@libp2p/identify 4.1.14-5cb617ae2 → 4.1.14-776cdedf6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/package.json +9 -9
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 sf=Object.create;var un=Object.defineProperty;var af=Object.getOwnPropertyDescriptor;var cf=Object.getOwnPropertyNames;var uf=Object.getPrototypeOf,ff=Object.prototype.hasOwnProperty;var Bo=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Be=(t,e)=>{for(var r in e)un(t,r,{get:e[r],enumerable:!0})},sa=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of cf(e))!ff.call(t,o)&&o!==r&&un(t,o,{get:()=>e[o],enumerable:!(n=af(e,o))||n.enumerable});return t};var lf=(t,e,r)=>(r=t!=null?sf(uf(t)):{},sa(e||!t||!t.__esModule?un(r,"default",{value:t,enumerable:!0}):r,t)),df=t=>sa(un({},"__esModule",{value:!0}),t);var Ui=Bo(gr=>{"use strict";Object.defineProperty(gr,"__esModule",{value:!0});gr.Netmask4Impl=void 0;gr.ip2long=yr;gr.long2ip=rt;function rt(t){let e=(t&-16777216)>>>24,r=(t&255<<16)>>>16,n=(t&65280)>>>8,o=t&255;return[e,r,n,o].join(".")}var Ch=48,Oh=97,Dh=65;function Ph(t){let e=0,r=10,n="9",o=0;t.length>1&&t[o]==="0"&&(t[o+1]==="x"||t[o+1]==="X"?(o+=2,r=16):"0"<=t[o+1]&&t[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<t.length;){if("0"<=t[o]&&t[o]<=n)e=e*r+(t.charCodeAt(o)-Ch)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-Oh)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-Dh)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[e,o]}function yr(t){let e=[];for(let r=0;r<=3&&t.length!==0;r++){if(r>0){if(t[0]!==".")throw new Error("Invalid IP");t=t.substring(1)}let[n,o]=Ph(t);t=t.substring(o),e.push(n)}if(t.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var Fi=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=yr(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=(yr(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=rt(this.netLong),this.mask=rt(this.maskLong),this.hostmask=rt(~this.maskLong),this.first=this.bitmask<=30?rt(this.netLong+1):this.base,this.last=this.bitmask<=30?rt(this.netLong+this.size-2):rt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?rt(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):(yr(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(rt(this.netLong+this.size*e),this.mask)}forEach(e){let r=yr(this.first),n=yr(this.last),o=0;for(;r<=n;)e(rt(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};gr.Netmask4Impl=Fi});var Pu=Bo(br=>{"use strict";Object.defineProperty(br,"__esModule",{value:!0});br.Netmask6Impl=void 0;br.ip6bigint=Ki;br.bigint2ip6=Vt;var Lh=Ui(),Mi=(1n<<128n)-1n;function Ki(t){let e=t.indexOf("%");e!==-1&&(t=t.substring(0,e));let r=t.lastIndexOf(":");if(r!==-1&&t.indexOf(".",r)!==-1){let n=t.substring(r+1),o=(0,Lh.ip2long)(n),s=t.substring(0,r+1)+"0:0";return Du(s)&~0xffffffffn|BigInt(o)}return Du(t)}function Du(t){let e=t.indexOf("::"),r;if(e!==-1){let o=t.substring(0,e),s=t.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(c).fill("0"),...a]}else r=t.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Vt(t){if(t<0n||t>Mi)throw new Error("Invalid IPv6 address value");let e=[];for(let i=0;i<8;i++)e.unshift(Number(t&0xffffn)),t>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)e[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(r=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(r=o,n=s),r!==-1&&r+n===8&&r>0)return e.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let i=e.slice(0,r).map(c=>c.toString(16)),a=e.slice(r+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return e.map(i=>i.toString(16)).join(":")}var Vi=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=Mi>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Ki(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Vt(this.netBigint),this.mask=Vt(this.maskBigint),this.hostmask=Vt(~this.maskBigint&Mi),this.first=this.base,this.last=Vt(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.last):(Ki(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Vt(this.netBigint+r*BigInt(e)),this.bitmask)}forEach(e){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)e(Vt(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};br.Netmask6Impl=Vi});var Lu=Bo(St=>{"use strict";Object.defineProperty(St,"__esModule",{value:!0});St.long2ip=St.ip2long=St.Netmask=void 0;var ho=Ui();Object.defineProperty(St,"ip2long",{enumerable:!0,get:function(){return ho.ip2long}});Object.defineProperty(St,"long2ip",{enumerable:!0,get:function(){return ho.long2ip}});var Rh=Pu(),qi=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new Rh.Netmask6Impl(e,r):this._impl=new ho.Netmask4Impl(e,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof ho.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new t(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new t(e))),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let r=this._impl.next(e);return new t(r.base,r.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};St.Netmask=qi});var pp={};Be(pp,{identify:()=>dp,identifyPush:()=>hp});var ae=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},zt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var fn=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var ln=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},dn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Me=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var It=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var To=Symbol.for("@libp2p/peer-id");var hn=Symbol.for("@libp2p/service-capabilities");var Lo={};Be(Lo,{base58btc:()=>he,base58flickr:()=>xf});var zp=new Uint8Array(0);function aa(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ne(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return _t(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return _t(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ca(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var ia=4096;function ua(t){let e=t.length;if(e<=ia)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=ia));return r}function hf(t){return t?.buffer instanceof ArrayBuffer}function _t(t){return hf(t)?t:t.slice()}function pf(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<t.length;s++){var i=t.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=t.length,l=t.charAt(0),p=Math.log(f)/Math.log(256),d=Math.log(256)/Math.log(f);function x(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var I=0,g=0,S=0,A=E.length;S!==A&&E[S]===0;)S++,I++;for(var N=(A-S)*d+1>>>0,U=new Uint8Array(N);S!==A;){for(var k=E[S],O=0,L=N-1;(k!==0||O<g)&&L!==-1;L--,O++)k+=256*U[L]>>>0,U[L]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");g=O,S++}for(var $=N-g;$!==N&&U[$]===0;)$++;for(var z=l.repeat(I);$<N;++$)z+=t.charAt(U[$]);return z}function m(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var I=0;if(E[I]!==" "){for(var g=0,S=0;E[I]===l;)g++,I++;for(var A=(E.length-I)*p+1>>>0,N=new Uint8Array(A);E[I];){var U=n[E.charCodeAt(I)];if(U===255)return;for(var k=0,O=A-1;(U!==0||k<S)&&O!==-1;O--,k++)U+=f*N[O]>>>0,N[O]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");S=k,I++}if(E[I]!==" "){for(var L=A-S;L!==A&&N[L]===0;)L++;for(var $=new Uint8Array(g+(A-L)),z=g;L!==A;)$[z++]=N[L++];return $}}}function w(E){var I=m(E);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:x,decodeUnsafe:m,decode:w}}var mf=pf,yf=mf,la=yf;var Co=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Oo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return da(this,e)}},Do=class{decoders;constructor(e){this.decoders=e}or(e){return da(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function da(t,e){return new Do({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Po=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Co(e,r,n),this.decoder=new Oo(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ht({name:t,prefix:e,encode:r,decode:n}){return new Po(t,e,r,n)}function lt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=la(r,t,n);return Ht({prefix:e,name:t,encode:o,decode:i=>Ne(s(i))})}function gf(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function bf(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function wf(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let o=t[n].toLowerCase(),s=t[n].toUpperCase();o!==t[n]&&(r[o]=n),s!==t[n]&&(r[s]=n)}return r}function fe({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=wf(n,o);return Ht({prefix:e,name:t,encode(i){return bf(i,n,r)},decode(i){return gf(i,s,r,t)}})}var he=lt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xf=lt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ro={};Be(Ro,{base32:()=>dt,base32hex:()=>Af,base32hexpad:()=>_f,base32hexpadupper:()=>Bf,base32hexupper:()=>If,base32pad:()=>vf,base32padupper:()=>Sf,base32upper:()=>Ef,base32z:()=>Tf});var dt=fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Ef=fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),vf=fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Sf=fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Af=fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),If=fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),_f=fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Bf=fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Tf=fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var No={};Be(No,{base36:()=>Ar,base36upper:()=>Cf});var Ar=lt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Cf=lt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Of=ma,ha=128,Df=127,Pf=~Df,Lf=Math.pow(2,31);function ma(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Lf;)e[r++]=t&255|ha,t/=128;for(;t&Pf;)e[r++]=t&255|ha,t>>>=7;return e[r]=t|0,ma.bytes=r-n+1,e}var Rf=ko,Nf=128,pa=127;function ko(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw ko.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&pa)<<o:(i&pa)*Math.pow(2,o),o+=7}while(i>=Nf);return ko.bytes=s-n,r}var kf=Math.pow(2,7),Ff=Math.pow(2,14),Uf=Math.pow(2,21),Mf=Math.pow(2,28),Kf=Math.pow(2,35),Vf=Math.pow(2,42),qf=Math.pow(2,49),zf=Math.pow(2,56),Hf=Math.pow(2,63),$f=function(t){return t<kf?1:t<Ff?2:t<Uf?3:t<Mf?4:t<Kf?5:t<Vf?6:t<qf?7:t<zf?8:t<Hf?9:10},jf={encode:Of,decode:Rf,encodingLength:$f},Yf=jf,Ir=Yf;function _r(t,e=0){let r=Ir.decode(t,e),n=Ir.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function $t(t,e,r=0){return Ir.encode(t,e,r),e}function jt(t){return Ir.encodingLength(t)}function We(t,e){let r=e.byteLength,n=jt(t),o=n+jt(r),s=new Uint8Array(o+r);return $t(t,s,0),$t(r,s,n),s.set(e,o),new Yt(t,r,e,s)}function Br(t){let e=Ne(t),[r,n]=_r(e),[o,s]=_r(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Yt(r,o,i,e)}function ya(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&aa(t.bytes,r.bytes)}}var Yt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=_t(n),this.bytes=_t(o)}};function ga(t,e){let{bytes:r,version:n}=t;return n===0?Zf(r,Fo(t),e??he.encoder):Gf(r,Fo(t),e??dt.encoder)}var ba=new WeakMap;function Fo(t){let e=ba.get(t);if(e==null){let r=new Map;return ba.set(t,r),r}return e}var be=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=_t(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Xf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=We(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&ya(e.multihash,n.multihash)}toString(e){return ga(this,e)}toJSON(){return{"/":ga(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??wa(n,o,s.bytes))}else if(r[Qf]===!0){let{version:n,multihash:o,code:s}=r,i=Br(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Tr)throw new Error(`Version 0 CID must use dag-pb (code: ${Tr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=wa(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Tr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Ne(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Yt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,p]=_r(e.subarray(r));return r+=p,l},o=n(),s=Tr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=Wf(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Fo(s).set(n,e),s}};function Wf(t,e){switch(t[0]){case"Q":{let r=e??he;return[he.prefix,r.decode(`${he.prefix}${t}`)]}case he.prefix:{let r=e??he;return[he.prefix,r.decode(t)]}case dt.prefix:{let r=e??dt;return[dt.prefix,r.decode(t)]}case Ar.prefix:{let r=e??Ar;return[Ar.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Zf(t,e,r){let{prefix:n}=r;if(n!==he.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Gf(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Tr=112,Xf=18;function wa(t,e,r){let n=jt(t),o=n+jt(e),s=new Uint8Array(o+r.byteLength);return $t(t,s,0),$t(e,s,n),s.set(r,o),s}var Qf=Symbol.for("@ipld/js-cid/CID");var Uo={};Be(Uo,{identity:()=>Ke});var xa=0,Jf="identity",Ea=Ne;function el(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return We(xa,Ea(t))}var Ke={code:xa,name:Jf,encode:Ea,digest:el};function me(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function tl(t){return t.buffer instanceof ArrayBuffer}function _e(t){return tl(t)?t:t.slice()}async function va(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,_e(e),_e(r.subarray()));return n?.signal?.throwIfAborted(),s}function we(t=0){return new Uint8Array(t)}function ve(t=0){return new Uint8Array(t)}function rl(t){return t?.buffer instanceof ArrayBuffer}function Mo(t){if(rl(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ze(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=ve(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Mo(r)}var Aa=Symbol.for("@achingbrain/uint8arraylist");function Sa(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function mn(t){return!!t?.[Aa]}var pe=class t{bufs;length;[Aa]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(mn(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(mn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Sa(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Sa(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(mn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Ze(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Ze(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!mn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let p=u;p>=0;p--){let d=this.get(l+p);if(n[p]!==d){f=Math.max(1,p-a[d]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=ve(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=we(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=we(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=we(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=ve(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=we(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=we(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=we(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=we(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=we(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!me(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Ko={};Be(Ko,{base10:()=>nl});var nl=lt({prefix:"9",name:"base10",alphabet:"0123456789"});var Vo={};Be(Vo,{base16:()=>ol,base16upper:()=>sl});var ol=fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),sl=fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var qo={};Be(qo,{base2:()=>il});var il=fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var zo={};Be(zo,{base256emoji:()=>ll});var Ia=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}"),al=Ia.reduce((t,e,r)=>(t[r]=e,t),[]),cl=Ia.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function ul(t){return t.reduce((e,r)=>(e+=al[r],e),"")}function fl(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=cl[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var ll=Ht({prefix:"\u{1F680}",name:"base256emoji",encode:ul,decode:fl});var $o={};Be($o,{base64:()=>dl,base64pad:()=>hl,base64url:()=>Ho,base64urlpad:()=>pl});var dl=fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),hl=fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ho=fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pl=fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var jo={};Be(jo,{base8:()=>ml});var ml=fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Yo={};Be(Yo,{identity:()=>yl});var yl=Ht({prefix:"\0",name:"identity",encode:t=>ua(Ne(t)),decode:t=>Ne(ca(t))});var Tm=new TextEncoder,Cm=new TextDecoder;var Go={};Be(Go,{sha256:()=>Cr,sha512:()=>xl});var wl=20;function Zo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Wo(t,e,r,n,o)}var Wo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??wl,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?_a(n,this.code,r?.truncate):n.then(o=>_a(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function _a(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return We(e,t)}function Ta(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Cr=Zo({name:"sha2-256",code:18,encode:Ta("SHA-256")}),xl=Zo({name:"sha2-512",code:19,encode:Ta("SHA-512")});var Or={...Yo,...qo,...jo,...Ko,...Vo,...Ro,...No,...Lo,...$o,...zo},Vm={...Go,...Uo};function Oa(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ca=Oa("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Xo=Oa("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=ve(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),El={utf8:Ca,"utf-8":Ca,hex:Or.base16,latin1:Xo,ascii:Xo,binary:Xo,...Or},yn=El;function V(t,e="utf8"){let r=yn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function H(t,e="utf8"){let r=yn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var vl=parseInt("11111",2),Qo=parseInt("10000000",2),Sl=parseInt("01111111",2),Da={0:Dr,1:Dr,2:Al,3:Bl,4:Tl,5:_l,6:Il,16:Dr,22:Dr,48:Dr};function nt(t,e={offset:0}){let r=t[e.offset]&vl;if(e.offset++,Da[r]!=null)return Da[r](t,e);throw new Error("No decoder for tag "+r)}function Pr(t,e){let r=0;if((t[e.offset]&Qo)===Qo){let n=t[e.offset]&Sl,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");o+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function Dr(t,e){Pr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=nt(t,e);if(n===null)break;r.push(n)}return r}function Al(t,e){let r=Pr(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function Il(t,e){let r=Pr(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function _l(t,e){return e.offset++,null}function Bl(t,e){let r=Pr(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Tl(t,e){let r=Pr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Cl(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new pe;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Jo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Cl(t.byteLength);return new pe(Uint8Array.from([e.byteLength|Qo]),e)}function Te(t){let e=new pe,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new pe(Uint8Array.from([2]),Jo(e),e)}function gn(t){let e=Uint8Array.from([0]),r=new pe(e,t);return new pe(Uint8Array.from([3]),Jo(r),r)}function ht(t,e=48){let r=new pe;for(let n of t)r.append(n);return new pe(Uint8Array.from([e]),Jo(r),r)}var Ol=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Dl=Uint8Array.from([6,5,43,129,4,0,34]),Pl=Uint8Array.from([6,5,43,129,4,0,35]),Ll={ext:!0,kty:"EC",crv:"P-256"},Rl={ext:!0,kty:"EC",crv:"P-384"},Nl={ext:!0,kty:"EC",crv:"P-521"},es=32,ts=48,rs=66;function ns(t){let e=nt(t);return Pa(e)}function Pa(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===es*2+1)return n=H(e.subarray(r,r+es),"base64url"),o=H(e.subarray(r+es),"base64url"),new Wt({...Ll,key_ops:["verify"],x:n,y:o});if(e.byteLength===ts*2+1)return n=H(e.subarray(r,r+ts),"base64url"),o=H(e.subarray(r+ts),"base64url"),new Wt({...Rl,key_ops:["verify"],x:n,y:o});if(e.byteLength===rs*2+1)return n=H(e.subarray(r,r+rs),"base64url"),o=H(e.subarray(r+rs),"base64url"),new Wt({...Nl,key_ops:["verify"],x:n,y:o});throw new ae(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function La(t){return ht([Te(Uint8Array.from([1])),ht([kl(t.crv)],160),ht([gn(new pe(Uint8Array.from([4]),V(t.x??"","base64url"),V(t.y??"","base64url")))],161)]).subarray()}function kl(t){if(t==="P-256")return Ol;if(t==="P-384")return Dl;if(t==="P-521")return Pl;throw new ae(`Invalid curve ${t}`)}var Wt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=La(this.jwk)),this._raw}toMultihash(){return Ke.digest(Ge(this))}toCID(){return be.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}async verify(e,r,n){return va(this.jwk,r,e,n)}};var bn=BigInt(4294967295),Ra=BigInt(32);function Fl(t,e=!1){return e?{h:Number(t&bn),l:Number(t>>Ra&bn)}:{h:Number(t>>Ra&bn)|0,l:Number(t&bn)|0}}function Na(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Fl(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Ul=t=>t/2**32|0,Ml=t=>t>>>0;function ka(t,e,r,n){let o=Ul(r),s=Ml(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var os=(t,e,r)=>t>>>r,ss=(t,e,r)=>t<<32-r|e>>>r,Tt=(t,e,r)=>t>>>r|e<<32-r,Ct=(t,e,r)=>t<<32-r|e>>>r,Lr=(t,e,r)=>t<<64-r|e>>>r-32,Rr=(t,e,r)=>t>>>r-32|e<<64-r;function Xe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Fa=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ua=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Ma=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ka=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Va=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),qa=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function wn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var is=t=>t?`"${t}" `:"";function ot(t,e=""){if(typeof t!="number")throw new TypeError(is(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(is(e)+"expected integer >= 0, got "+t);return t}function ke(t,e,r=""){if(wn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&ot(e,"length");let n=wn(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=is(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function xn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(ot(t.outputLen),ot(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Vl=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},za=(t,e)=>{Vl(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function Zt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function En(t,e){ke(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ot(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function vn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ve(t,e){return t<<32-e|t>>>e}var $a=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ql=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Sn(t){if(ke(t),$a)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=ql[t[r]];return e}function Ha(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function An(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if($a)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Ha(t.charCodeAt(s)),a=Ha(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function as(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];ke(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function zl(t,e,r="opts"){return za(t,"defaults"),e!==void 0&&za(e,r),Object.assign(Object.create(null),t,e)}function cs(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=zl({},e,"info");let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function ja(t=32){ot(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var us=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Ya(t,e,r){return t&e^~t&r}function Wa(t,e,r){return t&e^t&r^e&r}var Nr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=vn(this.buffer)}update(e){Zt(this),ke(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=vn(e);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Zt(this),En(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),ka(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:vn(e),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Za=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Ga=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Hl=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]),pt=new Uint32Array(64),fs=class extends Nr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)pt[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let p=pt[l-15],d=pt[l-2],x=Ve(p,7)^Ve(p,18)^p>>>3,m=Ve(d,17)^Ve(d,19)^d>>>10;pt[l]=m+pt[l-7]+x+pt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let p=Ve(a,6)^Ve(a,11)^Ve(a,25),d=f+p+Ya(a,c,u)+Hl[l]+pt[l]|0,m=(Ve(n,2)^Ve(n,13)^Ve(n,22))+Wa(n,o,s)|0;f=u,u=c,c=a,a=i+d|0,i=s,s=o,o=n,n=d+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Ot(pt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ot(this.buffer)}},ls=class extends fs{constructor(){super(32,Za)}};var Xa=Na(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),$l=Xa[0],jl=Xa[1],mt=new Uint32Array(80),yt=new Uint32Array(80),ds=class extends Nr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:p,Gh:d,Gl:x,Hh:m,Hl:w}=this;return[e,r,n,o,s,i,a,c,u,f,l,p,d,x,m,w]}set(e,r,n,o,s,i,a,c,u,f,l,p,d,x,m,w){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=p|0,this.Gh=d|0,this.Gl=x|0,this.Hh=m|0,this.Hl=w|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let g=0;g<16;g++,r+=4)mt[g]=e.getUint32(r),yt[g]=e.getUint32(r+=4);for(let g=16;g<80;g++){let S=mt[g-15]|0,A=yt[g-15]|0,N=Tt(S,A,1)^Tt(S,A,8)^os(S,A,7),U=Ct(S,A,1)^Ct(S,A,8)^ss(S,A,7),k=mt[g-2]|0,O=yt[g-2]|0,L=Tt(k,O,19)^Lr(k,O,61)^os(k,O,6),$=Ct(k,O,19)^Rr(k,O,61)^ss(k,O,6),z=Ma(U,$,yt[g-7],yt[g-16]),J=Ka(z,N,L,mt[g-7],mt[g-16]);mt[g]=J|0,yt[g]=z|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:p,Fh:d,Fl:x,Gh:m,Gl:w,Hh:E,Hl:I}=this;for(let g=0;g<80;g++){let S=Tt(l,p,14)^Tt(l,p,18)^Lr(l,p,41),A=Ct(l,p,14)^Ct(l,p,18)^Rr(l,p,41),N=l&d^~l&m,U=p&x^~p&w,k=Va(I,A,U,jl[g],yt[g]),O=qa(k,E,S,N,$l[g],mt[g]),L=k|0,$=Tt(n,o,28)^Lr(n,o,34)^Lr(n,o,39),z=Ct(n,o,28)^Rr(n,o,34)^Rr(n,o,39),J=n&s^n&a^s&a,B=o&i^o&c^i&c;E=m|0,I=w|0,m=d|0,w=x|0,d=l|0,x=p|0,{h:l,l:p}=Xe(u|0,f|0,O|0,L|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let M=Fa(L,z,B);n=Ua(M,O,$,J),o=M|0}({h:n,l:o}=Xe(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Xe(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Xe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Xe(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:p}=Xe(this.Eh|0,this.El|0,l|0,p|0),{h:d,l:x}=Xe(this.Fh|0,this.Fl|0,d|0,x|0),{h:m,l:w}=Xe(this.Gh|0,this.Gl|0,m|0,w|0),{h:E,l:I}=Xe(this.Hh|0,this.Hl|0,E|0,I|0),this.set(n,o,s,i,a,c,u,f,l,p,d,x,m,w,E,I)}roundClean(){Ot(mt,yt)}destroy(){this.destroyed=!0,Ot(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},hs=class extends ds{constructor(){super(64,Ga)}};var Gt=cs(()=>new ls,us(1));var ps=cs(()=>new hs,us(3));function _n(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var G=(t,e,r)=>ke(t,e,r),ms=ot;function Ja(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function gt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Dt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var kr=Sn,Fe=(...t)=>as(...t),Xt=t=>An(t),wt=wn,Pt=t=>ja(t),In=BigInt(0),Qa=BigInt(1),Yl=t=>t?`"${t}" `:"";function Ce(t,e=""){if(typeof t!="boolean")throw new TypeError(Yl(e)+"expected boolean, got type="+typeof t);return t}function Bn(t){if(typeof t=="bigint"){if(!bt(t))throw new RangeError("positive bigint expected, got "+t)}else ms(t);return t}function st(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Fr(t){let e=Bn(t).toString(16);return e.length&1?"0"+e:e}function ec(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?In:BigInt("0x"+t)}function Qe(t){return ec(Sn(t))}function Lt(t){return ec(Sn(Ur(ke(t)).reverse()))}function Tn(t,e){if(ot(e),e===0)throw new Error("zero output length is invalid");t=Bn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return An(n.padStart(r,"0"))}function ys(t,e){return Tn(t,e).reverse()}function Ur(t){return Uint8Array.from(G(t))}function bt(t){return typeof t=="bigint"&&In<=t}function gs(t,e,r){return bt(t)&&bt(e)&&bt(r)&&e<=t&&t<r}function Qt(t,e,r,n){if(!gs(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Jt(t){if(t<In)throw new Error("expected non-negative bigint, got "+t);return t===In?0:t.toString(2).length}var Mr=t=>(st(t,"n"),(Qa<<BigInt(t))-Qa);function tc(t,e,r){if(ot(t,"hashLen"),ot(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=w=>new Uint8Array(w),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},p=(...w)=>r(u,Fe(c,...w)),d=(w=o)=>{u=p(s,w),c=p(),w.length!==0&&(u=p(i,w),c=p())},x=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let w=0,E=[];for(;w<e;){c=p();let I=c.slice();E.push(I),w+=c.length}return Fe(...E)};return(w,E)=>{l(),d(w);let I;for(;(I=E(x()))===void 0;)d();return l(),I}}function Oe(t,e={},r={},n="object"){gt(t,n),gt(e,"fields"),gt(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=t[i];if(!Object.hasOwn(t,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(e,!1),s(r,!0)}var ye=BigInt(0),X=BigInt(1),xt=BigInt(2),oc=BigInt(3),bs=BigInt(4),sc=BigInt(5),Wl=BigInt(7),ic=BigInt(8),Zl=BigInt(9),Gl=BigInt(15),ac=BigInt(16),Xl=BigInt("0x10000000000000000");function ce(t,e){if(e<=ye)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ye?r:e+r}function cc(t,e,r){if(r<=X)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<ye)throw new Error("invalid exponent, negatives unsupported");if(e===ye)return X;if(e===X)return t;let n=t%r;if(n<ye&&(n+=r),e<Xl){let a=X;for(;e>ye;)e&X&&(a=a*n%r),n=n*n%r,e>>=X;return a}let o=[];for(;e>ye;)o.push(Number(e&Gl)),e>>=bs;let s=new Array(16);s[0]=X,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function se(t,e,r){if(r<=X)throw new Error("pow2: expected modulus > 1, got "+r);if(e<ye)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ye;)n*=n,n%=r;return n}function rc(t,e){if(t===ye)throw new Error("invert: expected non-zero number");if(e<=X)throw new Error("invert: expected modulus > 1, got "+e);let r=ce(t,e),n=e,o=ye,s=X;for(;r!==ye;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==X)throw new Error("invert: does not exist");return ce(o,e)}function uc(t,e){if(e<=X)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ce(t,e);if(r===ye)throw new Error("invertCt: expected non-zero number");let n=cc(r,e-xt,e);if(ce(r*n,e)!==X)throw new Error("invertCt: does not exist");return n}function ws(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function xs(t,e){if((t&X)===ye)throw new Error(e+": expected odd modulus, got "+t)}function fc(t,e){let r=t,n=(r.ORDER+X)/bs,o=r.pow(e,n);return ws(r,o,e),o}function Ql(t,e){let r=t,n=(r.ORDER-sc)/ic,o=r.mul(e,xt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,xt),s),c=r.mul(i,r.sub(a,r.ONE));return ws(r,c,e),c}function Jl(t){let e=tr(t),r=lc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+Wl)/ac;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),p=u.mul(f,o),d=u.mul(f,s),x=u.eql(u.sqr(l),c),m=u.eql(u.sqr(p),c);f=u.cmov(f,l,x),l=u.cmov(d,p,m);let w=u.eql(u.sqr(l),c),E=u.cmov(f,l,w);return ws(u,E,c),E})}function lc(t){if(t<oc)throw new Error("sqrt is not defined for small field");xs(t,"tonelliShanks");let e=t-X,r=0;for(;e%xt===ye;)e/=xt,r++;let n=xt,o=tr(t);for(;Kr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return fc;let s=o.pow(n,e),i=(e+X)/xt;return function(c,u){let f=c;if(f.is0(u))return u;if(Kr(f,u)!==1)throw new Error("Cannot find square root");let l=r,p=f.mul(f.ONE,s),d=f.pow(u,e),x=f.pow(u,i);for(;!f.eql(d,f.ONE);){if(f.is0(d))throw new Error("Cannot find square root: probably non-prime P");let m=1,w=f.sqr(d);for(;!f.eql(w,f.ONE);)if(m++,w=f.sqr(w),m===l)throw new Error("Cannot find square root");let E=X<<BigInt(l-m-1),I=f.pow(p,E);l=m,p=f.sqr(I),d=f.mul(d,p),x=f.mul(x,I)}return x}}function ed(t){return xs(t,"Fp.sqrt"),t%bs===oc?fc:t%ic===sc?Ql:t%ac===Zl?Jl(t):lc(t)}var dc=(t,e)=>(ce(t,e)&X)===X,td=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function er(t){if(gt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);st(t.BYTES,"BYTES"),st(t.BITS,"BITS");for(let e of td)Dt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function On(t,e,r=!1){er(t),_n(e,"nums"),Ce(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Kr(t,e){er(t);let r=t;xs(r.ORDER,"FpLegendre");let n=(r.ORDER-X)/xt,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function rd(t,e){if(e!==void 0&&ms(e),t<=ye)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Jt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var nc=new WeakMap,Cn=class{ORDER;BITS;BYTES;isLE;ZERO=ye;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=rd(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ce(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ye<=e&&e<this.ORDER}is0(e){return e===ye}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return ce(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ce(e*e,this.ORDER)}add(e,r){return ce(e+r,this.ORDER)}sub(e,r){return ce(e-r,this.ORDER)}mul(e,r){return ce(e*r,this.ORDER)}pow(e,r){return cc(e,r,this.ORDER)}div(e,r){return ce(e*rc(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return rc(e,this.ORDER)}sqrt(e){let r=nc.get(this);return r||nc.set(this,r=ed(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?ys(e,this.BYTES):Tn(e,this.BYTES)}fromBytes(e,r=!1){G(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?Lt(e):Qe(e);if(a&&(c=ce(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return On(this,e,!0)}cmov(e,r,n){return Ce(n,"condition"),n?r:e}};function tr(t,e={}){return Object.freeze(Cn.prototype),new Cn(t,e)}function hc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=Jt(t-X);return Math.ceil(e/8)}function Dn(t){let e=hc(t);return e+Math.ceil(e/2)}function Pn(t,e,r=!1){G(t);let n=t.length,o=hc(e),s=Math.max(Dn(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Lt(t):Qe(t),a=ce(i,e-X)+X;return r?ys(a,o):Tn(a,o)}var Ss=BigInt(0),Vr=BigInt(1),nd=BigInt(4),Es=16,pc=128,od=5,mc=2**31;function Et(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Dt(e.fromAffine,"Point.fromAffine"),Dt(e.fromBytes,"Point.fromBytes"),Dt(e.fromHex,"Point.fromHex"),gt(e.BASE,"Point.BASE"),gt(e.ZERO,"Point.ZERO"),er(e.Fp),er(e.Fn)}function Ln(t,e){Et(t),gc(e,t);let r=On(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function sd(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function id(t,e){let r=t*(4*e+128);if(r>mc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+mc/2**20+" MiB")}function As(t,e){if(t!==void 0){Dt(t,"randomBytes");try{let r=t(e);if(!wt(r)||r.length!==e)return}catch{return}return t}}function gc(t,e){_n(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function ad(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):bt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var bc=new WeakMap;function vs(t){return bc.get(t)||1}function cd(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function ud(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>Ss;){let i=0;t&Vr&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=Vr}return s}function fd(t,e,r){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let u=Number(t&s);t>>=i,u>o&&(u-=n,t+=Vr),a.push(u)}if(t!==Ss)throw new Error("invalid wnaf");return a}function ld(t,e,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=t;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=e[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var rr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){Et(e),this.randomBytes=As(r,Es),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=e;for(let c=0;c<o;c++){let u=a;for(let f=0;f<s;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(e,r){let{W:n,windows:o,comp:s}=e,i=2**(n-1),a=fd(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],p=f*i,d=Math.abs(l)-1,x=s[p];for(let w=1;w<i;w++)x=w===d?s[p+w]:x;let m=x.negate();l===0?u=u.add(s[p]):c=c.add(l<0?m:x)}return{p:c,f:u}}getWnafPrecomputes(e,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!gs(r,Vr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=vs(e);return s===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+pc,s=this.randomBytes(Es);if(!wt(s)||s.length!==Es)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Qe(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=od,s=1<<o,i=Mr(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(e);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let d=0;d<o;d++)u=u.double();let l=Number(r>>BigInt(f*o)&i),p=a[0];for(let d=1;d<s;d++)p=d===l?a[d]:p;u=u.add(p)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Vr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!bt(r))throw new Error("invalid scalar");let o=vs(e);if(o===1||r>=this.Point.Fn.ORDER)return Rn(this.Point,[e],[r],!0);let s=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(e,r){this.assertPoint(e),sd(r,this.bits);let n=Math.ceil((this.bits+pc)/r)+1;id(n*2**(r-1),this.Point.Fp.BYTES),bc.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return vs(e)!==1}};function Rn(t,e,r,n=!1){if(Et(t),gc(e,t),Ce(n,"allowOversized"),ad(r,t.Fn,n?t.Fn.ORDER**nd:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>cd(i,4)),s=r.map(i=>ud(i,4));return ld(t.ZERO,o,s)}function yc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return er(e),e}else return tr(t,{isLE:r})}function Nn(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Oe(r);for(let c of["p","n","h"]){let u=e[c];if(!(bt(u)&&u!==Ss))throw new Error(`CURVE.${c} must be positive bigint`)}let o=yc(e.p,r.Fp,n),s=yc(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function kn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var Fn=BigInt(0),Un=BigInt(1),Mn=BigInt(2),dd=BigInt(4),wc=BigInt(8);function hd(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function xc(t,e={}){Oe(e,{},{},"extraOpts");let r=e,n=Nn("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(Kr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Kr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Oe(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Pt:r.randomBytes,u=Mn<<BigInt(o.BYTES*8)-Un;function f(I){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(I)}let l=r.uvRatio===void 0?(I,g)=>{try{return{isValid:!0,value:o.sqrt(o.div(I,g))}}catch{return{isValid:!1,value:Fn}}}:r.uvRatio;if(!hd(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let p=o.eql(i.a,o.neg(o.ONE))?I=>o.neg(I):o.eql(i.a,o.ONE)?I=>I:I=>o.mul(i.a,I);function d(I,g,S=!1){let A=S?Un:Fn;return Qt("coordinate "+I,g,A,u),g}function x(I){if(!(I instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new m(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(g,S,A,N){this.X=d("x",g),this.Y=d("y",S),this.Z=d("z",A,!0),this.T=d("t",N),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof m)throw new Error("extended point not allowed");let{x:S,y:A}=g||{};return d("x",S),d("y",A),new m(S,A,o.ONE,o.mul(S,A))}static fromBytes(g,S=!1){let A=o.BYTES,{a:N,d:U}=i;g=Ur(G(g,A,"point")),Ce(S,"zip215");let k=Ur(g),O=g[A-1];k[A-1]=O&-129;let L=Lt(k),$=S?u:o.ORDER;Qt("point.y",L,Fn,$);let z=o.sqr(L),J=o.sub(z,o.ONE),B=o.sub(o.mulN(U,z),N),{isValid:M,value:K}=l(J,B);if(!M)throw new Error("bad point: invalid y coordinate");let P=f(K),re=(O&128)!==0;if(!S&&o.is0(K)&&re)throw new Error("bad point: x=0 and x_0=1");return re!==P&&(K=o.neg(K)),m.fromAffine({x:K,y:L})}static fromHex(g,S=!1){return m.fromBytes(Xt(g),S)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=6,S=!0){return E.setWindowSize(this,g),S||this.multiply(Mn),this}assertValidity(){let g=this,{a:S,d:A}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:N,Y:U,Z:k,T:O}=g,L=o.sqr(N),$=o.sqr(U),z=o.sqr(k),J=o.sqr(z),B=o.mul(L,S),M=o.mul(o.add(B,$),z),K=o.add(J,o.mul(A,o.mul(L,$)));if(!o.eql(M,K))throw new Error("bad point: equation left != right (1)");let P=o.mul(N,U),re=o.mul(k,O);if(!o.eql(P,re))throw new Error("bad point: equation left != right (2)")}equals(g){x(g);let{X:S,Y:A,Z:N}=this,{X:U,Y:k,Z:O}=g,L=o.mul(S,O),$=o.mul(U,N),z=o.mul(A,O),J=o.mul(k,N);return o.eql(L,$)&&o.eql(z,J)}is0(){return this.equals(m.ZERO)}negate(){return new m(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:g,Y:S,Z:A}=this,N=o.sqr(g),U=o.sqr(S),k=o.mul(o.sqr(A),Mn),O=p(N),L=o.addN(g,S),$=o.sub(o.subN(o.sqr(L),N),U),z=o.addN(O,U),J=o.subN(z,k),B=o.subN(O,U),M=o.mul($,J),K=o.mul(z,B),P=o.mul($,B),re=o.mul(J,z);return new m(M,K,re,P)}add(g){x(g);let{d:S}=i,{X:A,Y:N,Z:U,T:k}=this,{X:O,Y:L,Z:$,T:z}=g,J=o.mul(A,O),B=o.mul(N,L),M=o.mul(o.mulN(k,S),z),K=o.mul(U,$),P=o.sub(o.subN(o.mulN(o.addN(A,N),o.addN(O,L)),J),B),re=o.subN(K,M),ie=o.addN(K,M),v=o.sub(B,p(J)),h=o.mul(P,re),y=o.mul(ie,v),b=o.mul(P,v),_=o.mul(re,ie);return new m(h,y,_,b)}subtract(g){return x(g),this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:S,f:A}=E.mulSecret(this,g,a,w);return w([S,A])[0]}multiplyUnsafe(g){if(!s.isValid(g))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return g===Fn?m.ZERO:this.is0()||g===Un?this:E.mulUnsafe(this,g,w)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return E.mulUnsafe(this,i.n).is0()}toAffine(g){let S=this,A=g;if(A!=null&&typeof A!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof A);let{X:N,Y:U,Z:k}=S,O=S.is0();A==null&&(A=O?o.create(wc):o.inv(k));let L=o.mul(N,A),$=o.mul(U,A),z=o.mul(k,A);if(O)return{x:o.ZERO,y:o.ONE};if(!o.eql(z,o.ONE))throw new Error("invZ was invalid");return{x:L,y:$}}clearCofactor(){return a===Un?this:a===Mn?this.double():a===dd?this.double().double():a===wc?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:g,y:S}=this.toAffine(),A=o.toBytes(S);return A[A.length-1]|=f(g)?128:0,A}toHex(){return kr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let w=I=>Ln(m,I),E=new rr(m,c);return E.bits>=6&&m.BASE.precompute(6),Object.freeze(m.prototype),Object.freeze(m),m}function Ec(t,e,r={}){if(Et(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Oe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(st(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Pt:o.randomBytes,p=o.toMontgomery,d=o.toMontgomerySecret,x=o.adjustScalarBytes===void 0?B=>B:o.adjustScalarBytes,m=o.domain===void 0?(B,M,K)=>{if(Ce(K,"phflag"),M.length||K)throw new Error("Contexts/pre-hash are not supported");return B}:o.domain;function w(B){return c.create(Lt(B))}function E(B){let M=O.secretKey;G(B,O.secretKey,"secretKey");let K=G(n(B),2*M,"hashedSecretKey"),P=x(K.slice(0,M)),re=K.slice(M,2*M),ie=w(P);return{head:P,prefix:re,scalar:ie}}function I(B){let{head:M,prefix:K,scalar:P}=E(B),re=i.multiply(P),ie=re.toBytes();return{head:M,prefix:K,scalar:P,point:re,pointBytes:ie}}function g(B){return I(B).pointBytes}function S(B=Uint8Array.of(),...M){let K=Fe(...M);return w(n(m(K,G(B,void 0,"context"),!!s)))}function A(B,M,K={}){Oe(K,{},{},"options"),B=Ur(G(B,void 0,"message")),s&&(B=s(B));let{prefix:P,scalar:re,pointBytes:ie}=I(M),v=S(K.context,P,B),h=i.multiply(v).toBytes(),y=S(K.context,h,ie,B),b=c.create(v+y*re);if(!c.isValid(b))throw new Error("sign failed: invalid s");let _=Fe(h,c.toBytes(b));return G(_,O.signature,"result")}let N={zip215:o.zip215};function U(B,M,K,P=N){Oe(P);let{context:re}=P,ie=P.zip215===void 0?!!N.zip215:P.zip215,v=O.signature;B=G(B,v,"signature"),M=G(M,void 0,"message"),K=G(K,O.publicKey,"publicKey"),ie!==void 0&&Ce(ie,"zip215"),s&&(M=s(M));let h=v/2,y=B.subarray(0,h),b=Lt(B.subarray(h,v)),_,T,C;try{_=t.fromBytes(K,ie),T=t.fromBytes(y,ie),C=i.multiplyUnsafe(b)}catch{return!1}if(!ie&&_.isSmallOrder())return!1;let R=S(re,y,K,M);return T.add(_.multiplyUnsafe(R)).subtract(C).clearCofactor().is0()}let k=a.BYTES,O={secretKey:k,publicKey:k,signature:2*k,seed:k};function L(B){return B=B===void 0?l(O.seed):B,G(B,O.seed,"seed")}function $(B){return wt(B)&&B.length===O.secretKey}function z(B,M){try{return!!t.fromBytes(B,M===void 0?N.zip215:M)}catch{return!1}}let J={getExtendedPublicKey:I,randomSecretKey:L,isValidSecretKey:$,isValidPublicKey:z,toMontgomery(B){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(t.fromBytes(B))},toMontgomerySecret(B){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(B)}};return Object.freeze(O),Object.freeze(J),Object.freeze({keygen:kn(L,g),getPublicKey:g,sign:A,verify:U,utils:J,Point:t,lengths:O})}var Is=BigInt(1),vc=BigInt(2);var pd=BigInt(5),md=BigInt(8),_s=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),yd={p:_s,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:md,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function gd(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=_s,a=t*t%s*t%s,c=se(a,vc,s)*a%s,u=se(c,Is,s)*t%s,f=se(u,pd,s)*u%s,l=se(f,e,s)*f%s,p=se(l,r,s)*l%s,d=se(p,n,s)*p%s,x=se(d,o,s)*d%s,m=se(x,o,s)*d%s,w=se(m,e,s)*f%s;return{pow_p_5_8:se(w,vc,s)*t%s,b2:a}}function Ic(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Sc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function bd(t,e){let r=_s,n=ce(e*e*e,r),o=ce(n*n*e,r),s=gd(t*o).pow_p_5_8,i=ce(t*n*s,r),a=ce(e*i*i,r),c=i,u=ce(i*Sc,r),f=a===t,l=a===ce(-t,r),p=a===ce(-t*Sc,r);return f&&(i=c),(l||p)&&(i=u),dc(i,r)&&(i=ce(-i,r)),{isValid:f||l,value:i}}var Bs=xc(yd,{uvRatio:bd}),Ac=Bs.Fp;function wd(t){let{y:e}=t;return Ac.toBytes(Ac.div(Is+e,Is-e))}function xd(t){let e=Bs.Fp.BYTES;return ke(t,e),Ic(ps(t.subarray(0,e))).subarray(0,e)}function Ed(t){return Ec(Bs,ps,Object.assign({adjustScalarBytes:Ic,toMontgomery:wd,toMontgomerySecret:xd,zip215:!0},t))}var _c=Ed({});var qr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Kn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Ue={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Kn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Vn=32;var Ts,vd=(async()=>{try{return await Ue.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Sd(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Ue.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Ue.get().subtle.verify({name:"Ed25519"},n,_e(e),_e(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ad(t,e,r){return _c.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Bc(t,e,r){return Ts==null&&(Ts=await vd),Ts?Sd(t,e,r):Ad(t,e,r)}function qn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var zn=class{type="Ed25519";raw;constructor(e){this.raw=Cs(e,Vn)}toMultihash(){return Ke.digest(Ge(this))}toCID(){return be.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=Bc(this.raw,r,e);return qn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Os(t){return t=Cs(t,Vn),new zn(t)}function Cs(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new ae(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var _d=Math.pow(2,7),Bd=Math.pow(2,14),Td=Math.pow(2,21),Ds=Math.pow(2,28),Ps=Math.pow(2,35),Ls=Math.pow(2,42),Rs=Math.pow(2,49),Q=128,Se=127;function De(t){if(t<_d)return 1;if(t<Bd)return 2;if(t<Td)return 3;if(t<Ds)return 4;if(t<Ps)return 5;if(t<Ls)return 6;if(t<Rs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function nr(t,e,r=0){switch(De(t)){case 8:e[r++]=t&255|Q,t/=128;case 7:e[r++]=t&255|Q,t/=128;case 6:e[r++]=t&255|Q,t/=128;case 5:e[r++]=t&255|Q,t/=128;case 4:e[r++]=t&255|Q,t>>>=7;case 3:e[r++]=t&255|Q,t>>>=7;case 2:e[r++]=t&255|Q,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Cd(t,e,r=0){switch(De(t)){case 8:e.set(r++,t&255|Q),t/=128;case 7:e.set(r++,t&255|Q),t/=128;case 6:e.set(r++,t&255|Q),t/=128;case 5:e.set(r++,t&255|Q),t/=128;case 4:e.set(r++,t&255|Q),t>>>=7;case 3:e.set(r++,t&255|Q),t>>>=7;case 2:e.set(r++,t&255|Q),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function Ns(t,e){let r=t[e],n=0;if(n+=r&Se,r<Q||(r=t[e+1],n+=(r&Se)<<7,r<Q)||(r=t[e+2],n+=(r&Se)<<14,r<Q)||(r=t[e+3],n+=(r&Se)<<21,r<Q)||(r=t[e+4],n+=(r&Se)*Ds,r<Q)||(r=t[e+5],n+=(r&Se)*Ps,r<Q)||(r=t[e+6],n+=(r&Se)*Ls,r<Q)||(r=t[e+7],n+=(r&Se)*Rs,r<Q))return n;throw new RangeError("Could not decode varint")}function Od(t,e){let r=t.get(e),n=0;if(n+=r&Se,r<Q||(r=t.get(e+1),n+=(r&Se)<<7,r<Q)||(r=t.get(e+2),n+=(r&Se)<<14,r<Q)||(r=t.get(e+3),n+=(r&Se)<<21,r<Q)||(r=t.get(e+4),n+=(r&Se)*Ds,r<Q)||(r=t.get(e+5),n+=(r&Se)*Ps,r<Q)||(r=t.get(e+6),n+=(r&Se)*Ls,r<Q)||(r=t.get(e+7),n+=(r&Se)*Rs,r<Q))return n;throw new RangeError("Could not decode varint")}function or(t,e,r=0){return e==null&&(e=ve(De(t))),e instanceof Uint8Array?nr(t,e,r):Cd(t,e,r)}function zr(t,e=0){return t instanceof Uint8Array?Ns(t,e):Od(t,e)}var Fs=new Float32Array([-0]),vt=new Uint8Array(Fs.buffer);function Cc(t,e,r){Fs[0]=t,e[r]=vt[0],e[r+1]=vt[1],e[r+2]=vt[2],e[r+3]=vt[3]}function Oc(t,e){return vt[0]=t[e],vt[1]=t[e+1],vt[2]=t[e+2],vt[3]=t[e+3],Fs[0]}var Us=new Float64Array([-0]),Ae=new Uint8Array(Us.buffer);function Dc(t,e,r){Us[0]=t,e[r]=Ae[0],e[r+1]=Ae[1],e[r+2]=Ae[2],e[r+3]=Ae[3],e[r+4]=Ae[4],e[r+5]=Ae[5],e[r+6]=Ae[6],e[r+7]=Ae[7]}function Pc(t,e){return Ae[0]=t[e],Ae[1]=t[e+1],Ae[2]=t[e+2],Ae[3]=t[e+3],Ae[4]=t[e+4],Ae[5]=t[e+5],Ae[6]=t[e+6],Ae[7]=t[e+7],Us[0]}var Dd=BigInt(Number.MAX_SAFE_INTEGER),Pd=BigInt(Number.MIN_SAFE_INTEGER),Le=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Rt;if(e<Dd&&e>Pd)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Lc&&(o=0n,++n>Lc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Rt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Rt}},Rt=new Le(0,0);Rt.toBigInt=function(){return 0n};Rt.zzEncode=Rt.zzDecode=function(){return this};Rt.length=function(){return 1};var Lc=4294967296n;function Rc(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Nc(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Ms(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function qe(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Hn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Ks=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=_e(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,qe(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw qe(this,4);return Hn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw qe(this,4);return Hn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw qe(this,4);let e=Oc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw qe(this,4);let e=Pc(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw qe(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Nc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw qe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw qe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Le(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw qe(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw qe(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw qe(this,8);let e=Hn(this.buf,this.pos+=4),r=Hn(this.buf,this.pos+=4);return new Le(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ns(this.buf,this.pos);return this.pos+=De(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Hr(t){return new Ks(t instanceof Uint8Array?t:t.subarray())}function ze(t,e,r){let n=Hr(t);return e.decode(n,void 0,r)}function Vs(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return ve(i);o+i>e&&(n=ve(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Nt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function qs(){}var Hs=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Ld=Vs();function Rd(t){return globalThis.Buffer!=null?ve(t):Ld(t)}var jr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Nt(qs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Nt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new $s((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push($n,10,Le.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Le.fromBigInt(e);return this._push($n,r.length(),r)}uint64Number(e){return this._push(nr,De(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Le.fromBigInt(e).zzEncode();return this._push($n,r.length(),r)}sint64Number(e){let r=Le.fromNumber(e).zzEncode();return this._push($n,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(zs,1,e?1:0)}fixed32(e){return this._push($r,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Le.fromBigInt(e);return this._push($r,4,r.lo)._push($r,4,r.hi)}fixed64Number(e){let r=Le.fromNumber(e);return this._push($r,4,r.lo)._push($r,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Cc,4,e)}double(e){return this._push(Dc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(zs,1,0):this.uint32(r)._push(kd,r,e)}string(e){let r=Rc(e);return r!==0?this.uint32(r)._push(Ms,r,e):this._push(zs,1,0)}fork(){return this.states=new Hs(this),this.head=this.tail=new Nt(qs,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 Nt(qs,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Rd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function zs(t,e,r){e[r]=t&255}function Nd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var $s=class extends Nt{next;constructor(e,r){super(Nd,e,r),this.next=void 0}};function $n(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function $r(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function kd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(jr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Fd,e,t),this},jr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Ud,e,t),this});function Fd(t,e,r){e.set(t,r)}function Ud(t,e,r){t.length<40?Ms(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(V(t),r)}function js(){return new jr}function He(t,e){let r=js();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*$e(t,e,r){let n=Hr(t);yield*e.stream(n,void 0,"$",r)}var jn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Yn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Ys(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return Yn("enum",jn.VARINT,r,n,o)}function je(t,e,r){return Yn("message",jn.LENGTH_DELIMITED,t,e,r)}var Je=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ue;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(ue||(ue={}));var Ws;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Ws||(Ws={}));(function(t){t.codec=()=>Ys(Ws)})(ue||(ue={}));var et;(function(t){let e;t.codec=()=>(e==null&&(e=je((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ue.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=ue.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ue.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return He(s,t.codec())}t.encode=r;function n(s,i){return ze(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(et||(et={}));var Zs;(function(t){let e;t.codec=()=>(e==null&&(e=je((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ue.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=ue.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ue.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return He(s,t.codec())}t.encode=r;function n(s,i){return ze(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(Zs||(Zs={}));var Wr={};Be(Wr,{MAX_RSA_KEY_SIZE:()=>Gs,generateRSAKeyPair:()=>Vc,jwkToJWKKeyPair:()=>qc,jwkToPkcs1:()=>qd,jwkToPkix:()=>ei,jwkToRSAPrivateKey:()=>oi,pkcs1MessageToJwk:()=>Qs,pkcs1MessageToRSAPrivateKey:()=>ti,pkcs1ToJwk:()=>Vd,pkcs1ToRSAPrivateKey:()=>Kc,pkixMessageToJwk:()=>Js,pkixMessageToRSAPublicKey:()=>ni,pkixToJwk:()=>zd,pkixToRSAPublicKey:()=>ri});var sr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Wr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return be.createV1(114,this._multihash)}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,r,n){return Mc(this.jwk,r,e,n)}},Yr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Wr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}sign(e,r){return Uc(this.jwk,e,r)}};var Gs=8192,Xs=18,Md=1062,Kd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Vd(t){let e=nt(t);return Qs(e)}function Qs(t){return{n:H(t[1],"base64url"),e:H(t[2],"base64url"),d:H(t[3],"base64url"),p:H(t[4],"base64url"),q:H(t[5],"base64url"),dp:H(t[6],"base64url"),dq:H(t[7],"base64url"),qi:H(t[8],"base64url"),kty:"RSA"}}function qd(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new ae("JWK was missing components");return ht([Te(Uint8Array.from([0])),Te(V(t.n,"base64url")),Te(V(t.e,"base64url")),Te(V(t.d,"base64url")),Te(V(t.p,"base64url")),Te(V(t.q,"base64url")),Te(V(t.dp,"base64url")),Te(V(t.dq,"base64url")),Te(V(t.qi,"base64url"))]).subarray()}function zd(t){let e=nt(t,{offset:0});return Js(e)}function Js(t){let e=nt(t[1],{offset:0});return{kty:"RSA",n:H(e[0],"base64url"),e:H(e[1],"base64url")}}function ei(t){if(t.n==null||t.e==null)throw new ae("JWK was missing components");return ht([Kd,gn(ht([Te(V(t.n,"base64url")),Te(V(t.e,"base64url"))]))]).subarray()}function Kc(t){let e=nt(t);return ti(e)}function ti(t){let e=Qs(t);return oi(e)}function ri(t,e){if(t.byteLength>=Md)throw new zt("Key size is too large");let r=nt(t,{offset:0});return ni(r,t,e)}function ni(t,e,r){let n=Js(t);if(r==null){let o=Gt(et.encode({Type:ue.RSA,Data:e}));r=We(Xs,o)}return new sr(n,r)}function oi(t){if(Hc(t)>Gs)throw new ae("Key size is too large");let e=qc(t),r=Gt(et.encode({Type:ue.RSA,Data:ei(e.publicKey)})),n=We(Xs,r);return new Yr(e.privateKey,new sr(e.publicKey,n))}async function Vc(t){if(t>Gs)throw new ae("Key size is too large");let e=await zc(t),r=Gt(et.encode({Type:ue.RSA,Data:ei(e.publicKey)})),n=We(Xs,r);return new Yr(e.privateKey,new sr(e.publicKey,n))}function qc(t){if(t==null)throw new ae("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function zc(t,e){let r=await Ue.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Hd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Uc(t,e,r){let n=await Ue.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ue.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,_e(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Mc(t,e,r,n){let o=await Ue.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Ue.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,_e(e),_e(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Hd(t,e){if(t.privateKey==null||t.publicKey==null)throw new ae("Private and public key are required");let r=await Promise.all([Ue.get().subtle.exportKey("jwk",t.privateKey),Ue.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Hc(t){if(t.kty!=="RSA")throw new ae("invalid key type");if(t.n==null)throw new ae("invalid key modulus");return V(t.n,"base64url").length*8}var Wn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(xn(e),ke(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Ot(o)}update(e){return Zt(this),this.iHash.update(e),this}digestInto(e){Zt(this),En(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},$c=(()=>{let t=((e,r,n)=>new Wn(e,r).update(n).digest());return t.create=(e,r)=>new Wn(e,r),t})();var $d=BigInt(0),si=class extends Error{constructor(e=""){super(e)}},it={Err:si,_tlv:{encode:(t,e)=>{let{Err:r}=it;if(st(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Ja(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Fr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Fr(o.length/2|128):"";return Fr(t)+s+o+e},decode(t,e){let{Err:r}=it;e=G(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=it;if(Bn(t),t<$d)throw new e("integer: negative integers are not allowed");let r=Fr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=it;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Qe(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:o}=it;if(e!==void 0&&(st(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let s=G(t,void 0,"signature"),{v:i,l:a}=o.decode(48,s);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,i),{v:f,l}=o.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||f.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=it;Oe(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},Zn=(Object.freeze(it._tlv),Object.freeze(it._int),Object.freeze(it));var jc=(t,e)=>(t+(t>=0?e:-e)/Yc)/e;function jd(t,e,r){Qt("scalar",t,at,r);let[[n,o],[s,i]]=e,a=jc(i*t,r),c=jc(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,l=u<at,p=f<at;l&&(u=-u),p&&(f=-f);let d=Mr(Math.ceil(Jt(r)/2))+kt;if(u<at||u>=d||f<at||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:p,k2:f}}function ci(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function ii(t,e){Oe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ce(r.lowS,"lowS"),Ce(r.prehash,"prehash"),r.format!==void 0&&ci(r.format),r}var at=BigInt(0),kt=BigInt(1),Yc=BigInt(2),ai=BigInt(3),Yd=BigInt(4);function Wc(t,e={}){let r=Nn("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Oe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:p,toBytes:d}=e,x=e.randomBytes===void 0?Pt:e.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let m=c?{beta:c.beta,basises:c.basises.map(v=>[...v])}:void 0,w=Gc(n,o);function E(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function I(v,h,y){if(h.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:b,y:_}=h.toAffine(),T=n.toBytes(b);if(Ce(y,"isCompressed"),y){E();let C=!n.isOdd(_);return Fe(Zc(C),T)}else return Fe(Uint8Array.of(4),T,n.toBytes(_))}function g(v){G(v,void 0,"Point");let{publicKey:h,publicKeyUncompressed:y}=w,b=v.length,_=v[0],T=v.subarray(1);if(u&&b===1&&_===0)return{x:n.ZERO,y:n.ZERO};if(b===h&&(_===2||_===3)){let C=n.fromBytes(T);if(!n.isValid(C))throw new Error("bad point: is not on curve, wrong x");let R=k(C),F;try{F=n.sqrt(R)}catch(le){let ne=le instanceof Error?": "+le.message:"";throw new Error("bad point: is not on curve, sqrt error"+ne)}E();let Z=n.isOdd(F);return(_&1)===1!==Z&&(F=n.neg(F)),{x:C,y:F}}else if(b===y&&_===4){let C=n.BYTES,R=n.fromBytes(T.subarray(0,C)),F=n.fromBytes(T.subarray(C,C*2));if(!O(R,F))throw new Error("bad point: is not on curve");return{x:R,y:F}}else throw new Error(`bad point: got length ${b}, expected compressed=${h} or uncompressed=${y}`)}let S=d===void 0?I:d,A=p===void 0?g:p,N=n.mul(s.b,ai),U=n.is0(s.a)?v=>n.ZERO:v=>n.mul(s.a,v);function k(v){let h=n.sqr(v),y=n.mul(h,v);return n.add(n.add(y,n.mul(v,s.a)),s.b)}function O(v,h){let y=n.sqr(h),b=k(v);return n.eql(y,b)}if(!O(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let L=n.mul(n.pow(s.a,ai),Yd),$=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(L,$)))throw new Error("bad curve params: a or b");function z(v,h,y=!1){if(!n.isValid(h)||y&&n.is0(h))throw new Error(`bad point coordinate ${v}`);return typeof h=="object"&&h!==null?n.create(h):h}function J(v){if(!(v instanceof P))throw new Error("Weierstrass Point expected")}function B(v){if(!m||!m.basises)throw new Error("no endo");return jd(v,m.basises,o.ORDER)}function M(v,h,y,b){if(!o.isValid(b))throw new RangeError("invalid scalar: out of range");if(m){let{k1neg:_,k1:T,k2neg:C,k2:R}=B(b),F=new P(n.mul(y.X,m.beta),y.Y,y.Z);v.push(_?y.negate():y,C?F.negate():F),h.push(T,R)}else v.push(y),h.push(b)}let K=new WeakSet;class P{static BASE=new P(s.Gx,s.Gy,n.ONE);static ZERO=new P(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,y,b){this.X=z("x",h),this.Y=z("y",y,!0),this.Z=z("z",b),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x:y,y:b}=h||{};if(!h||!n.isValid(y)||!n.isValid(b))throw new Error("invalid affine point");if(h instanceof P)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(b)?P.ZERO:new P(y,b,n.ONE)}static fromBytes(h){let y=P.fromAffine(A(G(h,void 0,"point")));return y.assertValidity(),y}static fromHex(h){return P.fromBytes(Xt(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=6,y=!0){return ie.setWindowSize(this,h),y||this.multiply(ai),this}assertValidity(){let h=this;if(h.is0()){if(u&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}if(K.has(h))return;let{x:y,y:b}=h.toAffine();if(!n.isValid(y)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!O(y,b))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");K.add(h)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){J(h);let{X:y,Y:b,Z:_}=this,{X:T,Y:C,Z:R}=h,F=n.eql(n.mul(y,R),n.mul(T,_)),Z=n.eql(n.mul(b,R),n.mul(C,_));return F&&Z}negate(){return new P(this.X,n.neg(this.Y),this.Z)}double(){let{X:h,Y:y,Z:b}=this,_=n.ZERO,T=n.ZERO,C=n.ZERO,R=n.mul(h,h),F=n.mul(y,y),Z=n.mul(b,b),j=n.mul(h,y);return j=n.add(j,j),C=n.mul(h,b),C=n.add(C,C),_=U(C),T=n.mul(N,Z),T=n.add(_,T),_=n.sub(F,T),T=n.add(F,T),T=n.mul(_,T),_=n.mul(j,_),C=n.mul(N,C),Z=U(Z),j=n.sub(R,Z),j=U(j),j=n.add(j,C),C=n.add(R,R),R=n.add(C,R),R=n.add(R,Z),R=n.mul(R,j),T=n.add(T,R),Z=n.mul(y,b),Z=n.add(Z,Z),R=n.mul(Z,j),_=n.sub(_,R),C=n.mul(Z,F),C=n.add(C,C),C=n.add(C,C),new P(_,T,C)}add(h){J(h);let{X:y,Y:b,Z:_}=this,{X:T,Y:C,Z:R}=h,F=n.ZERO,Z=n.ZERO,j=n.ZERO,le=n.mul(y,T),ne=n.mul(b,C),ge=n.mul(_,R),Re=n.add(y,b),oe=n.add(T,C);Re=n.mul(Re,oe),oe=n.add(le,ne),Re=n.sub(Re,oe),oe=n.add(y,_);let de=n.add(T,R);return oe=n.mul(oe,de),de=n.add(le,ge),oe=n.sub(oe,de),de=n.add(b,_),F=n.add(C,R),de=n.mul(de,F),F=n.add(ne,ge),de=n.sub(de,F),j=U(oe),F=n.mul(N,ge),j=n.add(F,j),F=n.sub(ne,j),j=n.add(ne,j),Z=n.mul(F,j),ne=n.add(le,le),ne=n.add(ne,le),ge=U(ge),oe=n.mul(N,oe),ne=n.add(ne,ge),ge=n.sub(le,ge),ge=U(ge),oe=n.add(oe,ge),le=n.mul(ne,oe),Z=n.add(Z,le),le=n.mul(de,oe),F=n.mul(Re,F),F=n.sub(F,le),le=n.mul(Re,ne),j=n.mul(de,j),j=n.add(j,le),new P(F,Z,j)}subtract(h){return J(h),this.add(h.negate())}is0(){return this.equals(P.ZERO)}multiply(h){if(!o.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let{p:y,f:b}=ie.mulSecret(this,h,i,re);return re([y,b])[0]}multiplyUnsafe(h){let y=this,b=h;if(!o.isValid(b))throw new RangeError("invalid scalar: out of range");if(b===at||y.is0())return P.ZERO;if(b===kt)return y;if(ie.hasWindowSize(this))return ie.mulUnsafe(y,b,re);let _=[],T=[];return M(_,T,y,b),Rn(P,_,T)}mulAddUnsafe(h,y,b){J(y);let _=[],T=[];return M(_,T,this,h),M(_,T,y,b),Rn(P,_,T)}toAffine(h){let y=this,b=h;if(b!=null&&!n.isValid(b))throw new RangeError('"invertedZ" expected valid field element');let{X:_,Y:T,Z:C}=y;if(n.eql(C,n.ONE))return{x:_,y:T};let R=y.is0();b==null&&(b=R?n.ONE:n.inv(C));let F=n.mul(_,b),Z=n.mul(T,b),j=n.mul(C,b);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(j,n.ONE))throw new Error("invZ was invalid");return{x:F,y:Z}}isTorsionFree(){return i===kt?!0:l?l(P,this):ie.mulUnsafe(this,a).is0()}clearCofactor(){return i===kt?this:f?f(P,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===kt?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return Ce(h,"isCompressed"),this.assertValidity(),S(P,this,h)}toHex(h=!0){return kr(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let re=v=>Ln(P,v),ie=new rr(P,x);return ie.bits>=6&&P.BASE.precompute(6),Object.freeze(P.prototype),Object.freeze(P),P}function Zc(t){return Uint8Array.of(t?2:3)}function Gc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Wd(t,e={}){Et(t);let{Fn:r}=t,n=e.randomBytes===void 0?Pt:e.randomBytes,o=Object.assign(Gc(t.Fp,r),{seed:Math.max(Dn(r.ORDER),16)});function s(d){try{let x=r.fromBytes(d);return r.isValidNot0(x)}catch{return!1}}function i(d,x){let{publicKey:m,publicKeyUncompressed:w}=o;try{let E=d.length;return x===!0&&E!==m||x===!1&&E!==w?!1:!t.fromBytes(d).is0()}catch{return!1}}function a(d){return d=d===void 0?n(o.seed):d,Pn(G(d,o.seed,"seed"),r.ORDER)}function c(d,x=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(x)}function u(d){let{secretKey:x,publicKey:m,publicKeyUncompressed:w}=o,E=r._lengths;if(!wt(d))return;let I=G(d,void 0,"key").length,g=I===m||I===w,S=I===x||!!E?.includes(I);if(!(g&&S))return g}function f(d,x,m=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(x)===!1)throw new Error("second arg must be public key");let w=r.fromBytes(d),E=t.fromBytes(x);if(E.is0())throw new Error("invalid public key: point at infinity");return E.multiply(w).toBytes(m)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},p=kn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:p,Point:t,utils:l,lengths:o})}function Xc(t,e,r={}){Et(t);let n=e;xn(n),Oe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?Pt:o.randomBytes,i=o.hmac===void 0?(v,h)=>$c(n,v,h):o.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:f}=c,l=Dn(u),p=As(s,l),{keygen:d,getPublicKey:x,getSharedSecret:m,utils:w,lengths:E}=Wd(t,o),I={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=u*Yc+kt<a.ORDER;function S(v){let h=u>>kt;return v>h}function A(v,h){if(!c.isValidNot0(h))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return h}function N(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function U(v,h,y){return N(),(v===y?0:2)|Number(a.isOdd(h))}function k(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(v,h){ci(h);let y=E.signature,b=h==="compact"?y:h==="recovered"?y+1:void 0;return G(v,b)}class L{r;s;recovery;constructor(h,y,b){if(this.r=A("r",h),this.s=A("s",y),b!=null){if(k(),![0,1,2,3].includes(b))throw new Error("invalid recovery id");this.recovery=b}Object.freeze(this)}static fromBytes(h,y=I.format){O(h,y);let b;if(y==="der"){if(h.length>2*c.BYTES+16)throw new Zn.Err("invalid signature: DER signature too long");let{r:R,s:F}=Zn.toSig(G(h),c.BYTES+1);return new L(R,F)}y==="recovered"&&(b=h[0],y="compact",h=h.subarray(1));let _=E.signature/2,T=h.subarray(0,_),C=h.subarray(_,_*2);return new L(c.fromBytes(T),c.fromBytes(C),b)}static fromHex(h,y){return this.fromBytes(Xt(h),y)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new L(this.r,this.s,h)}recoverPublicKey(h){let{r:y,s:b}=this,_=this.assertRecovery(),T=_===2||_===3?y+u:y;if(!a.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=a.toBytes(T),R=t.fromBytes(Fe(Zc((_&1)===0),C)),F=c.inv(T),Z=z(G(h,void 0,"msgHash")),j=c.create(-Z*F),le=c.create(b*F),ne=t.BASE.mulAddUnsafe(j,R,le);if(ne.is0())throw new Error("invalid recovery: point at infinify");return ne.assertValidity(),ne}hasHighS(){return S(this.s)}toBytes(h=I.format){if(ci(h),h==="der")return Xt(Zn.hexFromSig(this));let{r:y,s:b}=this,_=c.toBytes(y),T=c.toBytes(b);return h==="recovered"?(k(),Fe(Uint8Array.of(this.assertRecovery()),_,T)):Fe(_,T)}toHex(h){return kr(this.toBytes(h))}}Object.freeze(L.prototype),Object.freeze(L);let $=o.bits2int===void 0?function(h){if(h.length>8192)throw new Error("input is too large");let y=Qe(h),b=h.length*8-f;return b>0?y>>BigInt(b):y}:o.bits2int,z=o.bits2int_modN===void 0?function(h){return c.create($(h))}:o.bits2int_modN,J=Mr(f);function B(v){return Qt("num < 2^"+f,v,at,J),c.toBytes(v)}function M(v,h){return G(v,void 0,"message"),h?G(n(v),void 0,"prehashed message"):v}function K(v,h,y){let{lowS:b,prehash:_,extraEntropy:T}=ii(y,I);v=M(v,_);let C=z(v),R=c.fromBytes(h);if(!c.isValidNot0(R))throw new Error("invalid private key");let F=[B(R),B(C)];if(T!=null&&T!==!1){let ne=T===!0?s(E.secretKey):T;F.push(G(ne,void 0,"extraEntropy"))}let Z=Fe(...F),j=C;function le(ne){let ge=$(ne);if(!c.isValidNot0(ge))return;let Re=t.BASE.multiply(ge).toAffine(),oe=c.create(Re.x);if(oe===at)return;let de;if(p!==void 0){let Sr=Qe(Pn(p(l),u)),rf=c.inv(c.mul(Sr,ge)),nf=c.mul(Sr,j),of=c.mul(Sr,R);de=c.create(rf*c.create(nf+of*oe))}else{let Sr=uc(ge,u);de=c.create(Sr*c.create(j+oe*R))}if(de===at)return;let _o=U(Re.x,Re.y,oe),oa=de;return b&&S(de)&&(oa=c.neg(de),_o^=1),new L(oe,oa,g?void 0:_o)}return{seed:Z,k2sig:le}}function P(v,h,y={}){let{seed:b,k2sig:_}=K(v,h,y);return tc(n.outputLen,c.BYTES,i)(b,_).toBytes(y.format)}function re(v,h,y,b={}){let{lowS:_,prehash:T,format:C}=ii(b,I);if(y=G(y,void 0,"publicKey"),h=M(h,T),!wt(v)){let R=v instanceof L?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+R)}O(v,C);try{let R=L.fromBytes(v,C),F=t.fromBytes(y);if(F.is0()||_&&R.hasHighS())return!1;let{r:Z,s:j}=R,le=z(h),ne=c.inv(j),ge=c.create(le*ne),Re=c.create(Z*ne),oe=t.BASE.mulAddUnsafe(ge,F,Re);if(oe.is0())return!1;let de=oe.toAffine();return!(c.create(de.x)!==Z||C==="recovered"&&R.recovery!==U(de.x,de.y,Z))}catch{return!1}}function ie(v,h,y={}){let{prehash:b}=ii(y,I);return h=M(h,b),L.fromBytes(v,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:d,getPublicKey:x,getSharedSecret:m,utils:w,lengths:E,Point:t,sign:P,verify:re,recoverPublicKey:ie,Signature:L,hash:n})}var fi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Zd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Qc=BigInt(2);function Gd(t){let e=fi.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=se(f,r,e)*f%e,p=se(l,r,e)*f%e,d=se(p,Qc,e)*u%e,x=se(d,o,e)*d%e,m=se(x,s,e)*x%e,w=se(m,a,e)*m%e,E=se(w,c,e)*w%e,I=se(E,a,e)*m%e,g=se(I,r,e)*f%e,S=se(g,i,e)*x%e,A=se(S,n,e)*u%e,N=se(A,Qc,e);if(!ui.eql(ui.sqr(N),t))throw new Error("Cannot find square root");return N}var ui=tr(fi.p,{sqrt:Gd}),Xd=Wc(fi,{Fp:ui,endo:Zd}),ir=Xc(Xd,Gt);function Jc(t,e,r,n){let o=Cr.digest(r instanceof Uint8Array?r:r.subarray());if(qn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ir.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new qr(String(s))});try{return n?.signal?.throwIfAborted(),ir.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new qr(String(s))}}var Gn=class{type="secp256k1";raw;_key;constructor(e){this._key=tu(e),this.raw=eu(this._key)}toMultihash(){return Ke.digest(Ge(this))}toCID(){return be.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,r,n){return Jc(this._key,r,e,n)}};function li(t){return new Gn(t)}function eu(t){return ir.Point.fromBytes(t).toBytes()}function tu(t){try{return ir.Point.fromBytes(t),t}catch(e){throw new zt(String(e))}}function ar(t,e){let{Type:r,Data:n}=et.decode(t),o=n??new Uint8Array;switch(r){case ue.RSA:return ri(o,e);case ue.Ed25519:return Os(o);case ue.secp256k1:return li(o);case ue.ECDSA:return ns(o);default:throw new It}}function ru(t){let{Type:e,Data:r}=et.decode(t.digest),n=r??new Uint8Array;switch(e){case ue.Ed25519:return Os(n);case ue.secp256k1:return li(n);case ue.ECDSA:return ns(n);default:throw new It}}function Ge(t){return et.encode({Type:ue[t.type],Data:t.raw})}var Zr;(function(t){let e;t.codec=()=>(e==null&&(e=je((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:we(0),payloadType:we(0),payload:we(0),signature:we(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return He(s,t.codec())}t.encode=r;function n(s,i){return ze(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(Zr||(Zr={}));var Xn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var tt=class t{static createFromProtobuf=e=>{let r=Zr.decode(e),n=ar(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=nu(o,s,i),c=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new Xn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Zr.encode({publicKey:Ge(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:me(this.marshal(),e.marshal())}async validate(e,r){let n=nu(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},nu=(t,e,r)=>{let n=V(t),o=or(n.byteLength),s=or(e.length),i=or(r.length);return new pe(o,n,s,e,i,r)};var ou=Symbol.for("nodejs.util.inspect.custom"),Qd=114,Gr=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[To]=!0;toString(){return this.string==null&&(this.string=he.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return be.createV1(Qd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return me(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return me(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[ou](){return`PeerId(${this.toString()})`}},Xr=class extends Gr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Qr=class extends Gr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Jr=class extends Gr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Jd=2336,en=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ke.digest(V(this.url))}[ou](){return`PeerId(${this.url})`}[To]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return be.createV1(Jd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=H(e)),e.toString()===this.toString())}};var eh=114,su=2336;function iu(t){if(t.type==="Ed25519")return new Qr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Jr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Xr({multihash:t.toCID().multihash,publicKey:t});throw new It}function di(t){if(rh(t))return new Xr({multihash:t});if(th(t))try{let e=ru(t);if(e.type==="Ed25519")return new Qr({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Jr({multihash:t,publicKey:e})}catch{let r=H(t.digest);return new en(new URL(r))}throw new dn("Supplied PeerID Multihash is invalid")}function Qn(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==eh&&t.code!==su)throw new ln("Supplied PeerID CID is invalid");if(t.code===su){let e=H(t.multihash.digest);return new en(new URL(e))}return di(t.multihash)}function th(t){return t.code===Ke.code}function rh(t){return t.code===Cr.code}var Ee=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ct=class extends Error{static name="ValidationError";name="ValidationError"},Jn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},eo=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var to=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let p=Number.parseInt(l,e);if(!Number.isNaN(p))return p});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var au=45,nh=15,cr=new to;function ro(t){if(!(t.length>nh))return cr.new(t).parseWith(()=>cr.readIPv4Addr())}function no(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>au))return cr.new(t).parseWith(()=>cr.readIPv6Addr())}function ur(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>au)return;let r=cr.new(t).parseWith(()=>cr.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function fr(t){return!!ro(t)}function oo(t){return!!no(t)}function pi(t){return e=>H(e,t)}function mi(t){return e=>V(e,t)}function lr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Ft(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function cu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=V(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ft(n);return Ze([r,o],r.length+o.length)}function uu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=dt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ft(n);return Ze([r,o],r.length+o.length)}function yi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=H(e,"base32"),o=lr(r);return`${n}:${o}`}var gi=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new Ee("Invalid byte value in IP address");e[n]=o}),e},fu=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=fr(r[n]),i;s&&(i=gi(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(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new Ee("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},lu=function(t){if(t.byteLength!==4)throw new Ee("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},du=function(t){if(t.byteLength!==16)throw new Ee("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Ee(`Invalid IPv6 address "${r}"`)}};function hu(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new Ee(`Invalid IPv6 address "${t}"`)}}var hi=Object.values(Or).map(t=>t.decoder),oh=(function(){let t=hi[0].or(hi[1]);return hi.slice(2).forEach(e=>t=t.or(e)),t})();function pu(t){return oh.decode(t)}function mu(t){return e=>t.encoder.encode(e)}function sh(t){if(parseInt(t).toString()!==t)throw new ct("Value must be an integer")}function ih(t){if(t<0)throw new ct("Value must be a positive integer, or zero")}function ah(t){return e=>{if(e>t)throw new ct(`Value must be smaller than or equal to ${t}`)}}function ch(...t){return e=>{for(let r of t)r(e)}}var tn=ch(sh,ih,ah(65535));var xe=-1,bi=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new eo(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ft=new bi,vh=[{code:4,name:"ip4",size:32,valueToBytes:gi,bytesToValue:lu,validate:t=>{if(!fr(t))throw new ct(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ft,bytesToValue:lr,validate:tn},{code:273,name:"udp",size:16,valueToBytes:Ft,bytesToValue:lr,validate:tn},{code:33,name:"dccp",size:16,valueToBytes:Ft,bytesToValue:lr,validate:tn},{code:41,name:"ip6",size:128,valueToBytes:fu,bytesToValue:du,stringToValue:hu,validate:t=>{if(!oo(t))throw new ct(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:xe},{code:43,name:"ipcidr",size:8,bytesToValue:pi("base10"),valueToBytes:mi("base10")},{code:53,name:"dns",size:xe},{code:54,name:"dns4",size:xe},{code:55,name:"dns6",size:xe},{code:56,name:"dnsaddr",size:xe},{code:132,name:"sctp",size:16,valueToBytes:Ft,bytesToValue:lr,validate:tn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:xe,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:xe,bytesToValue:pi("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?mi("base58btc")(t):be.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:yi,valueToBytes:cu},{code:445,name:"onion3",size:296,bytesToValue:yi,valueToBytes:uu},{code:446,name:"garlic64",size:xe},{code:447,name:"garlic32",size:xe},{code:448,name:"tls"},{code:449,name:"sni",size:xe},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:xe,bytesToValue:mu(Ho),valueToBytes:pu},{code:480,name:"http"},{code:481,name:"http-path",size:xe,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:xe}];vh.forEach(t=>{ft.addProtocol(t)});function yu(t){let e=[],r=0;for(;r<t.length;){let n=zr(t,r),o=ft.getProtocol(n),s=De(n),i=Sh(o,t,r+s),a=0;i>0&&o.size===xe&&(a=De(i));let c=s+a+i,u={code:n,name:o.name,bytes:_e(t.subarray(r,r+c))};if(i>0){let f=r+s+a,l=t.subarray(f,f+i);u.value=o.bytesToValue?.(l)??H(l)}e.push(u),r+=c}return e}function gu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ft.getProtocol(n.code),s=De(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===xe&&(c=De(a)));let u=new Uint8Array(s+c+a),f=0;nr(n.code,u,f),f+=s,i!=null&&(o.size===xe&&(nr(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Ze(r,e)}function bu(t){if(t.charAt(0)!=="/")throw new Ee('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=ft.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new Ee(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new Ee(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new Ee("Incomplete multiaddr");return e}function wu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ft.getProtocol(e.code);if(r==null)throw new Ee(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Sh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:zr(e,r)}var Ah=Symbol.for("nodejs.util.inspect.custom"),Li=Symbol.for("@multiformats/multiaddr");function Ih(t){if(t==null&&(t="/"),xu(t))return t.getComponents();if(t instanceof Uint8Array)return yu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),bu(t);if(Array.isArray(t))return t;throw new Ee("Must be a string, Uint8Array, Component[], or another Multiaddr")}var fo=class t{[Li]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Ih(e),r.validate!==!1&&_h(this)}get bytes(){return this.#r==null&&(this.#r=gu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=wu(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Jn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return me(this.bytes,e.bytes)}[Ah](){return`Multiaddr(${this.toString()})`}};function _h(t){t.getComponents().forEach(e=>{let r=ft.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function xu(t){return!!t?.[Li]}function nn(t){return new fo(t)}var Eu="libp2p-peer-record",vu=Uint8Array.from([3,1]);var on;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=je((l,p,d={})=>{d.lengthDelimited!==!1&&p.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(p.uint32(10),p.bytes(l.multiaddr)),d.lengthDelimited!==!1&&p.ldelim()},(l,p,d={})=>{let x={multiaddr:we(0)},m=p==null?l.len:l.pos+p;for(;l.pos<m;){let w=l.uint32();w>>>3===1?x.multiaddr=l.bytes():l.skipType(w&7)}return x},function*(l,p,d,x={}){let m=p==null?l.len:l.pos+p;for(;l.pos<m;){let w=l.uint32();w>>>3===1?yield{field:`${d}.multiaddr`,value:l.bytes()}:l.skipType(w&7)}})),a);function c(l){return He(l,i.codec())}i.encode=c;function u(l,p){return ze(l,i.codec(),p)}i.decode=u;function f(l,p){return $e(l,i.codec(),p)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=je((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:we(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Je('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let p=i.uint32();switch(p>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Je('Streaming decode error - repeated field "addresses" had too many elements');for(let d of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...d,index:f.addresses};f.addresses++;break}default:{i.skipType(p&7);break}}}})),r);function n(i){return He(i,t.codec())}t.encode=n;function o(i,a){return ze(i,t.codec(),a)}t.decode=o;function s(i,a){return $e(i,t.codec(),a)}t.stream=s})(on||(on={}));function Su(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var Ye=class t{static createFromProtobuf=e=>{let r=on.decode(e),n=di(Br(r.peerId)),o=(r.addresses??[]).map(i=>nn(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Eu;static CODEC=vu;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=on.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!Su(this.multiaddrs,e.multiaddrs))}};function Bh(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function lo(t){let e=Bh(t);if(e==null)throw new ae(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function Au(t,e,r){let n=0;for(let o of t)if(!(n<e)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Iu(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function Ri(t){switch(t.length){case Mt:return t.join(".");case Kt:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function _u(t){let e=0;for(let[r,n]of t.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<t.length;o++)if(t[o]!=0)return-1;break}return e}function Bu(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Mt=4,Kt=16,mx=parseInt("0xFFFF",16),Th=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function sn(t,e){e.length===Kt&&t.length===Mt&&Au(e,0,11)&&(e=e.slice(12)),e.length===Mt&&t.length===Kt&&Iu(t,Th,0,11)&&(t=t.slice(12));let r=t.length;if(r!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t[o]&e[o];return n}function Tu(t,e){if(typeof e=="string"&&(e=ur(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function Ni(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Mt,o=ro(e);if(o==null&&(n=Kt,o=no(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=ki(s,8*n);return{network:sn(o,i),mask:i}}function ki(t,e){if(e!==8*Mt&&e!==8*Kt)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var an=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Ni(e));else{let n=ur(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=ur(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ki(o,8*n.length);this.network=sn(n,this.mask)}}contains(e){return Tu({network:this.network,mask:this.mask},e)}toString(){let e=_u(this.mask),r=e!==-1?String(e):Bu(this.mask);return Ri(this.network)+"/"+r}};function Cu(t,e){return new an(t).contains(e)}function Ou(t){try{let e=lo(t);return e.type==="ip6"?Cu("2000::/3",e.host):!1}catch{return!1}}var Ru=lf(Lu(),1),Nh=["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"],kh=Nh.map(t=>new Ru.Netmask(t));function zi(t){for(let e of kh)if(e.contains(t))return!0;return!1}function Fh(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function Uh(t){let e=t.split(":");if(e.length<2)return!1;let r=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return zi(o)}function Mh(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function Kh(t){let e=t.split(":"),r=e[e.length-1];return zi(r)}function Vh(t){return/^::$/.test(t)||/^::1$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}function Nu(t){if(fr(t))return zi(t);if(Fh(t))return Uh(t);if(Mh(t))return Kh(t);if(oo(t))return Vh(t)}function ku(t){try{let e=lo(t);switch(e.type){case"ip4":case"ip6":return Nu(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var ee=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),D=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),Fu=t=>({match:e=>t.match(e)===!1?e:!1}),q=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),Ie=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),W=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function te(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var qh=D(421),Yx=te(qh),mo=D(54),yo=D(55),go=D(56),$i=D(53),Wx=te(mo,q(D(421))),Zx=te(yo,q(D(421))),Gx=te(go,q(D(421))),Xx=te(Ie($i,go,mo,yo),q(D(421))),Uu=W(D(4),q(D(43))),Mu=W(q(D(42)),D(41),q(D(43))),ji=Ie(Uu,Mu),wr=Ie(ji,$i,mo,yo,go),Ku=te(Ie(ji,W(Ie($i,go,mo,yo),q(D(421))))),Qx=te(Uu),Jx=te(Mu),e1=te(ji),Yi=W(wr,D(6)),cn=W(wr,D(273)),Vu=te(W(Yi,q(D(421)))),t1=te(cn),Wi=W(cn,ee(460),q(D(421))),bo=W(cn,ee(461),q(D(421))),zh=Ie(Wi,bo),r1=te(Wi),n1=te(bo),Hi=Ie(wr,Yi,cn,Wi,bo),qu=Ie(W(Hi,ee(477),q(D(421)))),o1=te(qu),zu=Ie(W(Hi,ee(478),q(D(421))),W(Hi,ee(448),q(D(449)),ee(477),q(D(421)))),s1=te(zu),Hu=W(cn,ee(280),q(D(466)),q(D(466)),q(D(421))),i1=te(Hu),$u=W(bo,ee(465),q(D(466)),q(D(466)),q(D(421))),a1=te($u),po=Ie(qu,zu,W(Yi,q(D(421))),W(zh,q(D(421))),W(wr,q(D(421))),Hu,$u,D(421)),c1=te(po),Hh=W(q(po),ee(290),Fu(ee(281)),q(D(421))),u1=te(Hh),$h=Ie(W(po,ee(290),ee(281),q(D(421))),W(po,ee(281),q(D(421))),W(ee(281),q(D(421)))),f1=te($h),jh=W(wr,Ie(W(D(6,"80")),W(D(6),ee(480)),ee(480)),q(D(481)),q(D(421))),l1=te(jh),Yh=W(wr,Ie(W(D(6,"443")),W(D(6,"443"),ee(480)),W(D(6),ee(443)),W(D(6),ee(448),ee(480)),W(ee(448),ee(480)),ee(448),ee(443)),q(D(481)),q(D(421))),d1=te(Yh),Wh=Ie(W(D(777),q(D(421)))),h1=te(Wh),Zh=Ie(W(D(400),q(D(421)))),p1=te(Zh);function xr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Zi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},ju=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Gi(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((l,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){p(ju(i));return}if(i&&(c=()=>{p(ju(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,p),r===Number.POSITIVE_INFINITY)return;let d=new Zi;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(x){p(x)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?p(o):(d.message=o??`Promise timed out after ${r} milliseconds`,p(d))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Gh=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Xh(t,e,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:f}=Gh(t),l=async(...d)=>{let x=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(x))return}catch(m){n(),i(m);return}c.push(x),r.count===c.length&&(n(),s(c))},p=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,l);for(let d of r.rejectionEvents)a.includes(d)||f(d,p)};for(let d of a)u(d,l);for(let d of r.rejectionEvents)a.includes(d)||u(d,p);r.signal&&r.signal.addEventListener("abort",()=>{p(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=Gi(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Yu(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Xh(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Wu(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var qt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Qh(t){return t.reason}function Xi(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??Qh;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var ep=4194304,wo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ji=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ea=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ta=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function tp(t){return typeof t?.closeRead=="function"}function rp(t){return typeof t?.close=="function"}function Qi(t){return tp(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:rp(t)?t.status!=="open":!1}function np(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function op(t,e){let r=e?.maxBufferSize??ep,n=new pe,o,s=!1,i;if(!np(t))throw new ae("Argument should be a Stream or a Multiaddr");let a=l=>{if(i==null){if(n.append(l.data),n.byteLength>r){let p=n.byteLength;n.consume(p);let d=new fn(`Read buffer overflow - ${p} > ${r}`);i=d,o?.reject(d),queueMicrotask(()=>{t.abort(d)});return}o?.resolve()}};t.addEventListener("message",a);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};t.addEventListener("close",c);let u=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(s===!0)throw new wo("Stream was unwrapped");if(i!=null)throw i;if(Qi(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new qt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let p=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=p){o.resolve();break}if(await Xi(o.promise,l?.signal),Qi(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let d=l?.bytes??n.byteLength;if(n.byteLength<d){if(Qi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,d),new qt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return f.read(l)}let x=n.sublist(0,d);return n.consume(d),x},async write(l,p){if(s===!0)throw new wo("Stream was unwrapped");t.send(l)||await Yu(t,"drain",{signal:p?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return f}function sp(t,e={}){let r=op(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=De(e.maxDataLength));let n=e?.lengthDecoder??zr,o=e?.lengthEncoder??or;return{async read(i){let a=-1,c=new pe;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Ji("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ta(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ea(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new qt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new qt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new pe(o(i.byteLength),i),a)},async writeV(i,a){let c=new pe(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function Er(t,e){let r=sp(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function ip(t){return t[Symbol.asyncIterator]!=null}function ap(t){if(ip(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Zu=ap;var xo=globalThis.CustomEvent??Event;async function*ra(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,s=[],i=xr(),a=xr(),c=!1,u,f=!1,l=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of t){if(s.length===r&&(i=xr(),await i.promise),f||l)break;let w={done:!1};s.push(w),m().then(E=>{w.done=!0,w.ok=!0,w.value=E,o.dispatchEvent(new xo("task-complete"))},E=>{w.done=!0,w.err=E,o.dispatchEvent(new xo("task-complete"))})}c=!0,o.dispatchEvent(new xo("task-complete"))}catch(m){u=m,o.dispatchEvent(new xo("task-complete"))}});function p(){return n?s[0]?.done:!!s.find(m=>m.done)}function*d(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw f=!0,i.resolve(),m.err;i.resolve()}}function*x(){for(;p();)for(let m=0;m<s.length;m++)if(s[m].done){let w=s[m];if(s.splice(m,1),m--,w.ok)yield w.value;else throw f=!0,i.resolve(),w.err;i.resolve()}}try{for(;;){if(p()||(a=xr(),await a.promise),u!=null||(n?yield*d():yield*x(),u!=null))throw u;if(c&&s.length===0)break}}finally{l=!0,i.resolve()}}var Gu="0.1.0";var Xu="id/push",Qu="1.0.0",Ju="1.0.0";var At;(function(t){let e;t.codec=()=>(e==null&&(e=je((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.protocolVersion!=null&&(i.uint32(42),i.string(s.protocolVersion)),s.agentVersion!=null&&(i.uint32(50),i.string(s.agentVersion)),s.publicKey!=null&&(i.uint32(10),i.bytes(s.publicKey)),s.listenAddrs!=null&&s.listenAddrs.length>0)for(let c of s.listenAddrs)i.uint32(18),i.bytes(c);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let c of s.protocols)i.uint32(26),i.string(c);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={listenAddrs:[],protocols:[]},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 5:{c.protocolVersion=s.string();break}case 6:{c.agentVersion=s.string();break}case 1:{c.publicKey=s.bytes();break}case 2:{if(a.limits?.listenAddrs!=null&&c.listenAddrs.length===a.limits.listenAddrs)throw new Je('Decode error - repeated field "listenAddrs" had too many elements');c.listenAddrs.push(s.bytes());break}case 4:{c.observedAddr=s.bytes();break}case 3:{if(a.limits?.protocols!=null&&c.protocols.length===a.limits.protocols)throw new Je('Decode error - repeated field "protocols" had too many elements');c.protocols.push(s.string());break}case 8:{c.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u={listenAddrs:0,protocols:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 5:{yield{field:`${a}.protocolVersion`,value:s.string()};break}case 6:{yield{field:`${a}.agentVersion`,value:s.string()};break}case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{if(c.limits?.listenAddrs!=null&&u.listenAddrs===c.limits.listenAddrs)throw new Je('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${a}.listenAddrs[]`,index:u.listenAddrs,value:s.bytes()},u.listenAddrs++;break}case 4:{yield{field:`${a}.observedAddr`,value:s.bytes()};break}case 3:{if(c.limits?.protocols!=null&&u.protocols===c.limits.protocols)throw new Je('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${a}.protocols[]`,index:u.protocols,value:s.string()},u.protocols++;break}case 8:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return He(s,t.codec())}t.encode=r;function n(s,i){return ze(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(At||(At={}));var Pe={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function tf(t){return t.bytes.length===0}function na(t){if(t!=null&&t.length>0)try{let e=nn(t);if(!tf(e))return e}catch{}}async function Eo(t,e,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Me("message was null or undefined");let s={},i=o.listenAddrs.map(na).filter(u=>u!=null);if(o.listenAddrs.length>0&&(s.addresses=i.map(u=>({isCertified:!1,multiaddr:u}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let u=ar(o.publicKey);if(!iu(u).equals(n.remotePeer))throw new Me("public key did not match remote PeerId");s.publicKey=u}let a;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let u=o.signedPeerRecord,f=await tt.openAndCertify(u,Ye.DOMAIN),l=Ye.createFromProtobuf(f.payload),p=Qn(f.publicKey.toCID());if(!l.peerId.equals(p))throw new Me("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(l.peerId))throw new Me("signing key does not match remote PeerId");let d;try{d=await t.get(l.peerId)}catch(m){if(m.name!=="NotFoundError")throw m}if(d!=null&&(s.metadata=d.metadata,d.peerRecordEnvelope!=null)){let m=tt.createFromProtobuf(d.peerRecordEnvelope),w=Ye.createFromProtobuf(m.payload);w.seqNumber>=l.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",w.seqNumber,l.seqNumber),l=w,u=d.peerRecordEnvelope)}s.peerRecordEnvelope=u;let x=l.multiaddrs.filter(m=>!tf(m));s.addresses=x.map(m=>({isCertified:!0,multiaddr:m})),a={seq:l.seqNumber,addresses:x}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,s),await t.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let u={};o.agentVersion!=null&&(u.AgentVersion=V(o.agentVersion)),o.protocolVersion!=null&&(u.ProtocolVersion=V(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,u),await t.merge(n.remotePeer,{metadata:u})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:i,observedAddr:o.observedAddr==null?void 0:nn(o.observedAddr),protocols:o.protocols,signedPeerRecord:a,connection:n};return e.safeDispatchEvent("peer:identify",{detail:c}),c}function vo(t){let e={...t[0]};for(let r of t.slice(1))r.protocolVersion!=null&&(e.protocolVersion=r.protocolVersion),r.agentVersion!=null&&(e.agentVersion=r.agentVersion),r.publicKey!=null&&(e.publicKey=r.publicKey),r.observedAddr!=null&&(e.observedAddr=r.observedAddr),r.signedPeerRecord!=null&&(e.signedPeerRecord=r.signedPeerRecord),e.listenAddrs=[...e.listenAddrs,...r.listenAddrs],e.protocols=[...new Set([...e.protocols,...r.protocols])];return e}async function So(t,e,r,n){let o=Er(t,{maxDataLength:e}).pb(At),s=[];for(let i=0;i<10;i++)try{s.push(await o.read(r))}catch(a){if(s.length===0)throw a;n.trace("stopped reading identify - %e",a);break}s.length>=10&&n("reached MAX_IDENTIFY_MESSAGES, returning truncated identify");try{await t.close(r)}catch(i){n.trace("error closing identify stream after read - %e",i),t.abort(i)}return s}var vr=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;runOnLimitedConnection;log;constructor(e,r){this.protocol=r.protocol,this.started=!1,this.components=e,this.log=r.log,this.timeout=r.timeout??Pe.timeout,this.maxInboundStreams=r.maxInboundStreams??Pe.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Pe.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Pe.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Pe.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Pe.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Pe.protocolPrefix}/${Gu}`,agentVersion:e.nodeInfo.userAgent},this.handleProtocol=this.handleProtocol.bind(this)}isStarted(){return this.started}async start(){this.started||(await this.components.peerStore.merge(this.components.peerId,{metadata:{AgentVersion:V(this.host.agentVersion),ProtocolVersion:V(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 Ao=class extends vr{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Pe.protocolPrefix}/${Xu}/${Ju}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Pe.concurrency,this._push=Wu(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Pe.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[hn]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),r=new Ye({peerId:this.components.peerId,multiaddrs:e}),n=await tt.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")??V(this.host.agentVersion)),a=H(s.metadata.get("ProtocolVersion")??V(this.host.protocolVersion)),c=this;async function*u(){for(let f of c.connectionManager.getConnections())(await c.components.peerStore.get(f.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let p,d=AbortSignal.timeout(c.timeout);try{p=await f.newStream(c.protocol,{signal:d,runOnLimitedConnection:c.runOnLimitedConnection}),await Er(p,{maxDataLength:c.maxMessageSize}).pb(At).write({listenAddrs:e.map(m=>m.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:d}),await p.close({signal:d})}catch(x){p?.log.newScope("identify-push")?.error("could not push identify update to peer",x),p?.abort(x)}})}await Zu(ra(u(),{concurrency:this.concurrency}))}catch(e){this.log.error("error pushing updates to peers - %e",e)}}async handleProtocol(e,r){let n=e.log.newScope("identify-push");if(this.components.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},s=await So(e,this.maxMessageSize,o,n);await Eo(this.components.peerStore,this.components.events,n,r,vo(s)),n.trace("handled push from %p",r.remotePeer)}};var Io=class extends vr{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Pe.protocolPrefix}/${"id"}/${Qu}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Pe.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[hn]=["@libp2p/identify"];async _identify(e,r={}){let n,o;if(r.signal==null){let s=AbortSignal.timeout(this.timeout);r={...r,signal:s}}this.log("run identify on new connection %a",e.remoteAddr);try{n=await e.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=await So(n,this.maxMessageSize,r,o);return vo(s)}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(e,r={}){let n=await this._identify(e,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Me("Public key was missing from identify message");let a=ar(o),c=Qn(a.toCID());if(!e.remotePeer.equals(c))throw new Me("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new Me("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),Eo(this.components.peerStore,this.components.events,this.log,e,n)}maybeAddObservedAddress(e){let r=na(e);if(r==null||(this.log.trace("our observed address was %a",r),ku(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Ou(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Vu.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(e,r){let n=e.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let f=new Ye({peerId:this.components.peerId,multiaddrs:i});a=(await tt.seal(f,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;Ku.matches(r.remoteAddr)||(c=void 0);let u=Er(e).pb(At);n("send response"),await u.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ge(this.components.privateKey.publicKey),listenAddrs:i.map(f=>f.bytes),signedPeerRecord:a,observedAddr:c,protocols:s.protocols},{signal:o}),n("close write"),await u.unwrap().unwrap().close({signal:o})}};function dp(t={}){return e=>new Io(e,t)}function hp(t={}){return e=>new Ao(e,t)}return df(pp);})();
|
|
2
|
+
"use strict";var Libp2PIdentify=(()=>{var sf=Object.create;var un=Object.defineProperty;var af=Object.getOwnPropertyDescriptor;var cf=Object.getOwnPropertyNames;var uf=Object.getPrototypeOf,ff=Object.prototype.hasOwnProperty;var Bo=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Be=(t,e)=>{for(var r in e)un(t,r,{get:e[r],enumerable:!0})},sa=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of cf(e))!ff.call(t,o)&&o!==r&&un(t,o,{get:()=>e[o],enumerable:!(n=af(e,o))||n.enumerable});return t};var lf=(t,e,r)=>(r=t!=null?sf(uf(t)):{},sa(e||!t||!t.__esModule?un(r,"default",{value:t,enumerable:!0}):r,t)),df=t=>sa(un({},"__esModule",{value:!0}),t);var Ui=Bo(gr=>{"use strict";Object.defineProperty(gr,"__esModule",{value:!0});gr.Netmask4Impl=void 0;gr.ip2long=yr;gr.long2ip=rt;function rt(t){let e=(t&-16777216)>>>24,r=(t&255<<16)>>>16,n=(t&65280)>>>8,o=t&255;return[e,r,n,o].join(".")}var Ch=48,Oh=97,Dh=65;function Ph(t){let e=0,r=10,n="9",o=0;t.length>1&&t[o]==="0"&&(t[o+1]==="x"||t[o+1]==="X"?(o+=2,r=16):"0"<=t[o+1]&&t[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<t.length;){if("0"<=t[o]&&t[o]<=n)e=e*r+(t.charCodeAt(o)-Ch)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-Oh)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-Dh)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[e,o]}function yr(t){let e=[];for(let r=0;r<=3&&t.length!==0;r++){if(r>0){if(t[0]!==".")throw new Error("Invalid IP");t=t.substring(1)}let[n,o]=Ph(t);t=t.substring(o),e.push(n)}if(t.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var Fi=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=yr(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=(yr(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=rt(this.netLong),this.mask=rt(this.maskLong),this.hostmask=rt(~this.maskLong),this.first=this.bitmask<=30?rt(this.netLong+1):this.base,this.last=this.bitmask<=30?rt(this.netLong+this.size-2):rt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?rt(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):(yr(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(rt(this.netLong+this.size*e),this.mask)}forEach(e){let r=yr(this.first),n=yr(this.last),o=0;for(;r<=n;)e(rt(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};gr.Netmask4Impl=Fi});var Pu=Bo(br=>{"use strict";Object.defineProperty(br,"__esModule",{value:!0});br.Netmask6Impl=void 0;br.ip6bigint=Ki;br.bigint2ip6=Vt;var Lh=Ui(),Mi=(1n<<128n)-1n;function Ki(t){let e=t.indexOf("%");e!==-1&&(t=t.substring(0,e));let r=t.lastIndexOf(":");if(r!==-1&&t.indexOf(".",r)!==-1){let n=t.substring(r+1),o=(0,Lh.ip2long)(n),s=t.substring(0,r+1)+"0:0";return Du(s)&~0xffffffffn|BigInt(o)}return Du(t)}function Du(t){let e=t.indexOf("::"),r;if(e!==-1){let o=t.substring(0,e),s=t.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(c).fill("0"),...a]}else r=t.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Vt(t){if(t<0n||t>Mi)throw new Error("Invalid IPv6 address value");let e=[];for(let i=0;i<8;i++)e.unshift(Number(t&0xffffn)),t>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)e[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(r=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(r=o,n=s),r!==-1&&r+n===8&&r>0)return e.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let i=e.slice(0,r).map(c=>c.toString(16)),a=e.slice(r+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return e.map(i=>i.toString(16)).join(":")}var Vi=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=Mi>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Ki(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Vt(this.netBigint),this.mask=Vt(this.maskBigint),this.hostmask=Vt(~this.maskBigint&Mi),this.first=this.base,this.last=Vt(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.last):(Ki(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Vt(this.netBigint+r*BigInt(e)),this.bitmask)}forEach(e){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)e(Vt(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};br.Netmask6Impl=Vi});var Lu=Bo(St=>{"use strict";Object.defineProperty(St,"__esModule",{value:!0});St.long2ip=St.ip2long=St.Netmask=void 0;var ho=Ui();Object.defineProperty(St,"ip2long",{enumerable:!0,get:function(){return ho.ip2long}});Object.defineProperty(St,"long2ip",{enumerable:!0,get:function(){return ho.long2ip}});var Rh=Pu(),qi=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new Rh.Netmask6Impl(e,r):this._impl=new ho.Netmask4Impl(e,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof ho.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new t(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new t(e))),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let r=this._impl.next(e);return new t(r.base,r.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};St.Netmask=qi});var pp={};Be(pp,{identify:()=>dp,identifyPush:()=>hp});var ae=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},zt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var fn=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var ln=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},dn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Me=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var It=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var To=Symbol.for("@libp2p/peer-id");var hn=Symbol.for("@libp2p/service-capabilities");var Lo={};Be(Lo,{base58btc:()=>he,base58flickr:()=>xf});var zp=new Uint8Array(0);function aa(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ne(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return _t(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return _t(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ca(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var ia=4096;function ua(t){let e=t.length;if(e<=ia)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=ia));return r}function hf(t){return t?.buffer instanceof ArrayBuffer}function _t(t){return hf(t)?t:t.slice()}function pf(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<t.length;s++){var i=t.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=t.length,l=t.charAt(0),p=Math.log(f)/Math.log(256),d=Math.log(256)/Math.log(f);function x(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var I=0,g=0,S=0,A=E.length;S!==A&&E[S]===0;)S++,I++;for(var N=(A-S)*d+1>>>0,U=new Uint8Array(N);S!==A;){for(var k=E[S],O=0,L=N-1;(k!==0||O<g)&&L!==-1;L--,O++)k+=256*U[L]>>>0,U[L]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");g=O,S++}for(var $=N-g;$!==N&&U[$]===0;)$++;for(var z=l.repeat(I);$<N;++$)z+=t.charAt(U[$]);return z}function m(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var I=0;if(E[I]!==" "){for(var g=0,S=0;E[I]===l;)g++,I++;for(var A=(E.length-I)*p+1>>>0,N=new Uint8Array(A);E[I];){var U=n[E.charCodeAt(I)];if(U===255)return;for(var k=0,O=A-1;(U!==0||k<S)&&O!==-1;O--,k++)U+=f*N[O]>>>0,N[O]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");S=k,I++}if(E[I]!==" "){for(var L=A-S;L!==A&&N[L]===0;)L++;for(var $=new Uint8Array(g+(A-L)),z=g;L!==A;)$[z++]=N[L++];return $}}}function w(E){var I=m(E);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:x,decodeUnsafe:m,decode:w}}var mf=pf,yf=mf,la=yf;var Co=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Oo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return da(this,e)}},Do=class{decoders;constructor(e){this.decoders=e}or(e){return da(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function da(t,e){return new Do({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Po=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Co(e,r,n),this.decoder=new Oo(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ht({name:t,prefix:e,encode:r,decode:n}){return new Po(t,e,r,n)}function lt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=la(r,t,n);return Ht({prefix:e,name:t,encode:o,decode:i=>Ne(s(i))})}function gf(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function bf(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function wf(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let o=t[n].toLowerCase(),s=t[n].toUpperCase();o!==t[n]&&(r[o]=n),s!==t[n]&&(r[s]=n)}return r}function fe({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=wf(n,o);return Ht({prefix:e,name:t,encode(i){return bf(i,n,r)},decode(i){return gf(i,s,r,t)}})}var he=lt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xf=lt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ro={};Be(Ro,{base32:()=>dt,base32hex:()=>Af,base32hexpad:()=>_f,base32hexpadupper:()=>Bf,base32hexupper:()=>If,base32pad:()=>vf,base32padupper:()=>Sf,base32upper:()=>Ef,base32z:()=>Tf});var dt=fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Ef=fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),vf=fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Sf=fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Af=fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),If=fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),_f=fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Bf=fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Tf=fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var No={};Be(No,{base36:()=>Ar,base36upper:()=>Cf});var Ar=lt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Cf=lt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Of=ma,ha=128,Df=127,Pf=~Df,Lf=Math.pow(2,31);function ma(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Lf;)e[r++]=t&255|ha,t/=128;for(;t&Pf;)e[r++]=t&255|ha,t>>>=7;return e[r]=t|0,ma.bytes=r-n+1,e}var Rf=ko,Nf=128,pa=127;function ko(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw ko.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&pa)<<o:(i&pa)*Math.pow(2,o),o+=7}while(i>=Nf);return ko.bytes=s-n,r}var kf=Math.pow(2,7),Ff=Math.pow(2,14),Uf=Math.pow(2,21),Mf=Math.pow(2,28),Kf=Math.pow(2,35),Vf=Math.pow(2,42),qf=Math.pow(2,49),zf=Math.pow(2,56),Hf=Math.pow(2,63),$f=function(t){return t<kf?1:t<Ff?2:t<Uf?3:t<Mf?4:t<Kf?5:t<Vf?6:t<qf?7:t<zf?8:t<Hf?9:10},jf={encode:Of,decode:Rf,encodingLength:$f},Yf=jf,Ir=Yf;function _r(t,e=0){let r=Ir.decode(t,e),n=Ir.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function $t(t,e,r=0){return Ir.encode(t,e,r),e}function jt(t){return Ir.encodingLength(t)}function We(t,e){let r=e.byteLength,n=jt(t),o=n+jt(r),s=new Uint8Array(o+r);return $t(t,s,0),$t(r,s,n),s.set(e,o),new Yt(t,r,e,s)}function Br(t){let e=Ne(t),[r,n]=_r(e),[o,s]=_r(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Yt(r,o,i,e)}function ya(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&aa(t.bytes,r.bytes)}}var Yt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=_t(n),this.bytes=_t(o)}};function ga(t,e){let{bytes:r,version:n}=t;return n===0?Zf(r,Fo(t),e??he.encoder):Gf(r,Fo(t),e??dt.encoder)}var ba=new WeakMap;function Fo(t){let e=ba.get(t);if(e==null){let r=new Map;return ba.set(t,r),r}return e}var be=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=_t(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Xf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=We(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&ya(e.multihash,n.multihash)}toString(e){return ga(this,e)}toJSON(){return{"/":ga(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??wa(n,o,s.bytes))}else if(r[Qf]===!0){let{version:n,multihash:o,code:s}=r,i=Br(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Tr)throw new Error(`Version 0 CID must use dag-pb (code: ${Tr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=wa(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Tr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Ne(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Yt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,p]=_r(e.subarray(r));return r+=p,l},o=n(),s=Tr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=Wf(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Fo(s).set(n,e),s}};function Wf(t,e){switch(t[0]){case"Q":{let r=e??he;return[he.prefix,r.decode(`${he.prefix}${t}`)]}case he.prefix:{let r=e??he;return[he.prefix,r.decode(t)]}case dt.prefix:{let r=e??dt;return[dt.prefix,r.decode(t)]}case Ar.prefix:{let r=e??Ar;return[Ar.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Zf(t,e,r){let{prefix:n}=r;if(n!==he.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Gf(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Tr=112,Xf=18;function wa(t,e,r){let n=jt(t),o=n+jt(e),s=new Uint8Array(o+r.byteLength);return $t(t,s,0),$t(e,s,n),s.set(r,o),s}var Qf=Symbol.for("@ipld/js-cid/CID");var Uo={};Be(Uo,{identity:()=>Ke});var xa=0,Jf="identity",Ea=Ne;function el(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return We(xa,Ea(t))}var Ke={code:xa,name:Jf,encode:Ea,digest:el};function me(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function tl(t){return t.buffer instanceof ArrayBuffer}function _e(t){return tl(t)?t:t.slice()}async function va(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,_e(e),_e(r.subarray()));return n?.signal?.throwIfAborted(),s}function we(t=0){return new Uint8Array(t)}function ve(t=0){return new Uint8Array(t)}function rl(t){return t?.buffer instanceof ArrayBuffer}function Mo(t){if(rl(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ze(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=ve(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Mo(r)}var Aa=Symbol.for("@achingbrain/uint8arraylist");function Sa(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function mn(t){return!!t?.[Aa]}var pe=class t{bufs;length;[Aa]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(mn(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(mn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Sa(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Sa(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(mn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Ze(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Ze(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!mn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let p=u;p>=0;p--){let d=this.get(l+p);if(n[p]!==d){f=Math.max(1,p-a[d]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=ve(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=we(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=we(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=we(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=ve(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=we(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=we(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=we(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=we(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=we(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!me(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Ko={};Be(Ko,{base10:()=>nl});var nl=lt({prefix:"9",name:"base10",alphabet:"0123456789"});var Vo={};Be(Vo,{base16:()=>ol,base16upper:()=>sl});var ol=fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),sl=fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var qo={};Be(qo,{base2:()=>il});var il=fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var zo={};Be(zo,{base256emoji:()=>ll});var Ia=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}"),al=Ia.reduce((t,e,r)=>(t[r]=e,t),[]),cl=Ia.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function ul(t){return t.reduce((e,r)=>(e+=al[r],e),"")}function fl(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=cl[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var ll=Ht({prefix:"\u{1F680}",name:"base256emoji",encode:ul,decode:fl});var $o={};Be($o,{base64:()=>dl,base64pad:()=>hl,base64url:()=>Ho,base64urlpad:()=>pl});var dl=fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),hl=fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ho=fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pl=fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var jo={};Be(jo,{base8:()=>ml});var ml=fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Yo={};Be(Yo,{identity:()=>yl});var yl=Ht({prefix:"\0",name:"identity",encode:t=>ua(Ne(t)),decode:t=>Ne(ca(t))});var Tm=new TextEncoder,Cm=new TextDecoder;var Go={};Be(Go,{sha256:()=>Cr,sha512:()=>xl});var wl=20;function Zo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Wo(t,e,r,n,o)}var Wo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??wl,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?_a(n,this.code,r?.truncate):n.then(o=>_a(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function _a(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return We(e,t)}function Ta(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Cr=Zo({name:"sha2-256",code:18,encode:Ta("SHA-256")}),xl=Zo({name:"sha2-512",code:19,encode:Ta("SHA-512")});var Or={...Yo,...qo,...jo,...Ko,...Vo,...Ro,...No,...Lo,...$o,...zo},Vm={...Go,...Uo};function Oa(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ca=Oa("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Xo=Oa("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=ve(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),El={utf8:Ca,"utf-8":Ca,hex:Or.base16,latin1:Xo,ascii:Xo,binary:Xo,...Or},yn=El;function V(t,e="utf8"){let r=yn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function H(t,e="utf8"){let r=yn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var vl=parseInt("11111",2),Qo=parseInt("10000000",2),Sl=parseInt("01111111",2),Da={0:Dr,1:Dr,2:Al,3:Bl,4:Tl,5:_l,6:Il,16:Dr,22:Dr,48:Dr};function nt(t,e={offset:0}){let r=t[e.offset]&vl;if(e.offset++,Da[r]!=null)return Da[r](t,e);throw new Error("No decoder for tag "+r)}function Pr(t,e){let r=0;if((t[e.offset]&Qo)===Qo){let n=t[e.offset]&Sl,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");o+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function Dr(t,e){Pr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=nt(t,e);if(n===null)break;r.push(n)}return r}function Al(t,e){let r=Pr(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function Il(t,e){let r=Pr(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function _l(t,e){return e.offset++,null}function Bl(t,e){let r=Pr(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Tl(t,e){let r=Pr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Cl(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new pe;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Jo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Cl(t.byteLength);return new pe(Uint8Array.from([e.byteLength|Qo]),e)}function Te(t){let e=new pe,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new pe(Uint8Array.from([2]),Jo(e),e)}function gn(t){let e=Uint8Array.from([0]),r=new pe(e,t);return new pe(Uint8Array.from([3]),Jo(r),r)}function ht(t,e=48){let r=new pe;for(let n of t)r.append(n);return new pe(Uint8Array.from([e]),Jo(r),r)}var Ol=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Dl=Uint8Array.from([6,5,43,129,4,0,34]),Pl=Uint8Array.from([6,5,43,129,4,0,35]),Ll={ext:!0,kty:"EC",crv:"P-256"},Rl={ext:!0,kty:"EC",crv:"P-384"},Nl={ext:!0,kty:"EC",crv:"P-521"},es=32,ts=48,rs=66;function ns(t){let e=nt(t);return Pa(e)}function Pa(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===es*2+1)return n=H(e.subarray(r,r+es),"base64url"),o=H(e.subarray(r+es),"base64url"),new Wt({...Ll,key_ops:["verify"],x:n,y:o});if(e.byteLength===ts*2+1)return n=H(e.subarray(r,r+ts),"base64url"),o=H(e.subarray(r+ts),"base64url"),new Wt({...Rl,key_ops:["verify"],x:n,y:o});if(e.byteLength===rs*2+1)return n=H(e.subarray(r,r+rs),"base64url"),o=H(e.subarray(r+rs),"base64url"),new Wt({...Nl,key_ops:["verify"],x:n,y:o});throw new ae(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function La(t){return ht([Te(Uint8Array.from([1])),ht([kl(t.crv)],160),ht([gn(new pe(Uint8Array.from([4]),V(t.x??"","base64url"),V(t.y??"","base64url")))],161)]).subarray()}function kl(t){if(t==="P-256")return Ol;if(t==="P-384")return Dl;if(t==="P-521")return Pl;throw new ae(`Invalid curve ${t}`)}var Wt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=La(this.jwk)),this._raw}toMultihash(){return Ke.digest(Ge(this))}toCID(){return be.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}async verify(e,r,n){return va(this.jwk,r,e,n)}};var bn=BigInt(4294967295),Ra=BigInt(32);function Fl(t,e=!1){return e?{h:Number(t&bn),l:Number(t>>Ra&bn)}:{h:Number(t>>Ra&bn)|0,l:Number(t&bn)|0}}function Na(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Fl(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Ul=t=>t/2**32|0,Ml=t=>t>>>0;function ka(t,e,r,n){let o=Ul(r),s=Ml(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var os=(t,e,r)=>t>>>r,ss=(t,e,r)=>t<<32-r|e>>>r,Tt=(t,e,r)=>t>>>r|e<<32-r,Ct=(t,e,r)=>t<<32-r|e>>>r,Lr=(t,e,r)=>t<<64-r|e>>>r-32,Rr=(t,e,r)=>t>>>r-32|e<<64-r;function Xe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Fa=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ua=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Ma=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ka=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Va=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),qa=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function wn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var is=t=>t?`"${t}" `:"";function ot(t,e=""){if(typeof t!="number")throw new TypeError(is(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(is(e)+"expected integer >= 0, got "+t);return t}function ke(t,e,r=""){if(wn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&ot(e,"length");let n=wn(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=is(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function xn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(ot(t.outputLen),ot(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Vl=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},za=(t,e)=>{Vl(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function Zt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function En(t,e){ke(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ot(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function vn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ve(t,e){return t<<32-e|t>>>e}var $a=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ql=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Sn(t){if(ke(t),$a)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=ql[t[r]];return e}function Ha(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function An(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if($a)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Ha(t.charCodeAt(s)),a=Ha(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function as(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];ke(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function zl(t,e,r="opts"){return za(t,"defaults"),e!==void 0&&za(e,r),Object.assign(Object.create(null),t,e)}function cs(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=zl({},e,"info");let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function ja(t=32){ot(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var us=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Ya(t,e,r){return t&e^~t&r}function Wa(t,e,r){return t&e^t&r^e&r}var Nr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=vn(this.buffer)}update(e){Zt(this),ke(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=vn(e);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Zt(this),En(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),ka(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:vn(e),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Za=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Ga=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Hl=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]),pt=new Uint32Array(64),fs=class extends Nr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)pt[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let p=pt[l-15],d=pt[l-2],x=Ve(p,7)^Ve(p,18)^p>>>3,m=Ve(d,17)^Ve(d,19)^d>>>10;pt[l]=m+pt[l-7]+x+pt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let p=Ve(a,6)^Ve(a,11)^Ve(a,25),d=f+p+Ya(a,c,u)+Hl[l]+pt[l]|0,m=(Ve(n,2)^Ve(n,13)^Ve(n,22))+Wa(n,o,s)|0;f=u,u=c,c=a,a=i+d|0,i=s,s=o,o=n,n=d+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Ot(pt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ot(this.buffer)}},ls=class extends fs{constructor(){super(32,Za)}};var Xa=Na(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),$l=Xa[0],jl=Xa[1],mt=new Uint32Array(80),yt=new Uint32Array(80),ds=class extends Nr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:p,Gh:d,Gl:x,Hh:m,Hl:w}=this;return[e,r,n,o,s,i,a,c,u,f,l,p,d,x,m,w]}set(e,r,n,o,s,i,a,c,u,f,l,p,d,x,m,w){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=p|0,this.Gh=d|0,this.Gl=x|0,this.Hh=m|0,this.Hl=w|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let g=0;g<16;g++,r+=4)mt[g]=e.getUint32(r),yt[g]=e.getUint32(r+=4);for(let g=16;g<80;g++){let S=mt[g-15]|0,A=yt[g-15]|0,N=Tt(S,A,1)^Tt(S,A,8)^os(S,A,7),U=Ct(S,A,1)^Ct(S,A,8)^ss(S,A,7),k=mt[g-2]|0,O=yt[g-2]|0,L=Tt(k,O,19)^Lr(k,O,61)^os(k,O,6),$=Ct(k,O,19)^Rr(k,O,61)^ss(k,O,6),z=Ma(U,$,yt[g-7],yt[g-16]),J=Ka(z,N,L,mt[g-7],mt[g-16]);mt[g]=J|0,yt[g]=z|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:p,Fh:d,Fl:x,Gh:m,Gl:w,Hh:E,Hl:I}=this;for(let g=0;g<80;g++){let S=Tt(l,p,14)^Tt(l,p,18)^Lr(l,p,41),A=Ct(l,p,14)^Ct(l,p,18)^Rr(l,p,41),N=l&d^~l&m,U=p&x^~p&w,k=Va(I,A,U,jl[g],yt[g]),O=qa(k,E,S,N,$l[g],mt[g]),L=k|0,$=Tt(n,o,28)^Lr(n,o,34)^Lr(n,o,39),z=Ct(n,o,28)^Rr(n,o,34)^Rr(n,o,39),J=n&s^n&a^s&a,B=o&i^o&c^i&c;E=m|0,I=w|0,m=d|0,w=x|0,d=l|0,x=p|0,{h:l,l:p}=Xe(u|0,f|0,O|0,L|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let M=Fa(L,z,B);n=Ua(M,O,$,J),o=M|0}({h:n,l:o}=Xe(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Xe(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Xe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Xe(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:p}=Xe(this.Eh|0,this.El|0,l|0,p|0),{h:d,l:x}=Xe(this.Fh|0,this.Fl|0,d|0,x|0),{h:m,l:w}=Xe(this.Gh|0,this.Gl|0,m|0,w|0),{h:E,l:I}=Xe(this.Hh|0,this.Hl|0,E|0,I|0),this.set(n,o,s,i,a,c,u,f,l,p,d,x,m,w,E,I)}roundClean(){Ot(mt,yt)}destroy(){this.destroyed=!0,Ot(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},hs=class extends ds{constructor(){super(64,Ga)}};var Gt=cs(()=>new ls,us(1));var ps=cs(()=>new hs,us(3));function _n(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var G=(t,e,r)=>ke(t,e,r),ms=ot;function Ja(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function gt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Dt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var kr=Sn,Fe=(...t)=>as(...t),Xt=t=>An(t),wt=wn,Pt=t=>ja(t),In=BigInt(0),Qa=BigInt(1),Yl=t=>t?`"${t}" `:"";function Ce(t,e=""){if(typeof t!="boolean")throw new TypeError(Yl(e)+"expected boolean, got type="+typeof t);return t}function Bn(t){if(typeof t=="bigint"){if(!bt(t))throw new RangeError("positive bigint expected, got "+t)}else ms(t);return t}function st(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Fr(t){let e=Bn(t).toString(16);return e.length&1?"0"+e:e}function ec(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?In:BigInt("0x"+t)}function Qe(t){return ec(Sn(t))}function Lt(t){return ec(Sn(Ur(ke(t)).reverse()))}function Tn(t,e){if(ot(e),e===0)throw new Error("zero output length is invalid");t=Bn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return An(n.padStart(r,"0"))}function ys(t,e){return Tn(t,e).reverse()}function Ur(t){return Uint8Array.from(G(t))}function bt(t){return typeof t=="bigint"&&In<=t}function gs(t,e,r){return bt(t)&&bt(e)&&bt(r)&&e<=t&&t<r}function Qt(t,e,r,n){if(!gs(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Jt(t){if(t<In)throw new Error("expected non-negative bigint, got "+t);return t===In?0:t.toString(2).length}var Mr=t=>(st(t,"n"),(Qa<<BigInt(t))-Qa);function tc(t,e,r){if(ot(t,"hashLen"),ot(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=w=>new Uint8Array(w),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},p=(...w)=>r(u,Fe(c,...w)),d=(w=o)=>{u=p(s,w),c=p(),w.length!==0&&(u=p(i,w),c=p())},x=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let w=0,E=[];for(;w<e;){c=p();let I=c.slice();E.push(I),w+=c.length}return Fe(...E)};return(w,E)=>{l(),d(w);let I;for(;(I=E(x()))===void 0;)d();return l(),I}}function Oe(t,e={},r={},n="object"){gt(t,n),gt(e,"fields"),gt(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=t[i];if(!Object.hasOwn(t,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(e,!1),s(r,!0)}var ye=BigInt(0),X=BigInt(1),xt=BigInt(2),oc=BigInt(3),bs=BigInt(4),sc=BigInt(5),Wl=BigInt(7),ic=BigInt(8),Zl=BigInt(9),Gl=BigInt(15),ac=BigInt(16),Xl=BigInt("0x10000000000000000");function ce(t,e){if(e<=ye)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ye?r:e+r}function cc(t,e,r){if(r<=X)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<ye)throw new Error("invalid exponent, negatives unsupported");if(e===ye)return X;if(e===X)return t;let n=t%r;if(n<ye&&(n+=r),e<Xl){let a=X;for(;e>ye;)e&X&&(a=a*n%r),n=n*n%r,e>>=X;return a}let o=[];for(;e>ye;)o.push(Number(e&Gl)),e>>=bs;let s=new Array(16);s[0]=X,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function se(t,e,r){if(r<=X)throw new Error("pow2: expected modulus > 1, got "+r);if(e<ye)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ye;)n*=n,n%=r;return n}function rc(t,e){if(t===ye)throw new Error("invert: expected non-zero number");if(e<=X)throw new Error("invert: expected modulus > 1, got "+e);let r=ce(t,e),n=e,o=ye,s=X;for(;r!==ye;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==X)throw new Error("invert: does not exist");return ce(o,e)}function uc(t,e){if(e<=X)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ce(t,e);if(r===ye)throw new Error("invertCt: expected non-zero number");let n=cc(r,e-xt,e);if(ce(r*n,e)!==X)throw new Error("invertCt: does not exist");return n}function ws(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function xs(t,e){if((t&X)===ye)throw new Error(e+": expected odd modulus, got "+t)}function fc(t,e){let r=t,n=(r.ORDER+X)/bs,o=r.pow(e,n);return ws(r,o,e),o}function Ql(t,e){let r=t,n=(r.ORDER-sc)/ic,o=r.mul(e,xt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,xt),s),c=r.mul(i,r.sub(a,r.ONE));return ws(r,c,e),c}function Jl(t){let e=tr(t),r=lc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+Wl)/ac;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),p=u.mul(f,o),d=u.mul(f,s),x=u.eql(u.sqr(l),c),m=u.eql(u.sqr(p),c);f=u.cmov(f,l,x),l=u.cmov(d,p,m);let w=u.eql(u.sqr(l),c),E=u.cmov(f,l,w);return ws(u,E,c),E})}function lc(t){if(t<oc)throw new Error("sqrt is not defined for small field");xs(t,"tonelliShanks");let e=t-X,r=0;for(;e%xt===ye;)e/=xt,r++;let n=xt,o=tr(t);for(;Kr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return fc;let s=o.pow(n,e),i=(e+X)/xt;return function(c,u){let f=c;if(f.is0(u))return u;if(Kr(f,u)!==1)throw new Error("Cannot find square root");let l=r,p=f.mul(f.ONE,s),d=f.pow(u,e),x=f.pow(u,i);for(;!f.eql(d,f.ONE);){if(f.is0(d))throw new Error("Cannot find square root: probably non-prime P");let m=1,w=f.sqr(d);for(;!f.eql(w,f.ONE);)if(m++,w=f.sqr(w),m===l)throw new Error("Cannot find square root");let E=X<<BigInt(l-m-1),I=f.pow(p,E);l=m,p=f.sqr(I),d=f.mul(d,p),x=f.mul(x,I)}return x}}function ed(t){return xs(t,"Fp.sqrt"),t%bs===oc?fc:t%ic===sc?Ql:t%ac===Zl?Jl(t):lc(t)}var dc=(t,e)=>(ce(t,e)&X)===X,td=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function er(t){if(gt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);st(t.BYTES,"BYTES"),st(t.BITS,"BITS");for(let e of td)Dt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function On(t,e,r=!1){er(t),_n(e,"nums"),Ce(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Kr(t,e){er(t);let r=t;xs(r.ORDER,"FpLegendre");let n=(r.ORDER-X)/xt,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function rd(t,e){if(e!==void 0&&ms(e),t<=ye)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Jt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var nc=new WeakMap,Cn=class{ORDER;BITS;BYTES;isLE;ZERO=ye;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=rd(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ce(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ye<=e&&e<this.ORDER}is0(e){return e===ye}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return ce(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ce(e*e,this.ORDER)}add(e,r){return ce(e+r,this.ORDER)}sub(e,r){return ce(e-r,this.ORDER)}mul(e,r){return ce(e*r,this.ORDER)}pow(e,r){return cc(e,r,this.ORDER)}div(e,r){return ce(e*rc(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return rc(e,this.ORDER)}sqrt(e){let r=nc.get(this);return r||nc.set(this,r=ed(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?ys(e,this.BYTES):Tn(e,this.BYTES)}fromBytes(e,r=!1){G(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?Lt(e):Qe(e);if(a&&(c=ce(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return On(this,e,!0)}cmov(e,r,n){return Ce(n,"condition"),n?r:e}};function tr(t,e={}){return Object.freeze(Cn.prototype),new Cn(t,e)}function hc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=Jt(t-X);return Math.ceil(e/8)}function Dn(t){let e=hc(t);return e+Math.ceil(e/2)}function Pn(t,e,r=!1){G(t);let n=t.length,o=hc(e),s=Math.max(Dn(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Lt(t):Qe(t),a=ce(i,e-X)+X;return r?ys(a,o):Tn(a,o)}var Ss=BigInt(0),Vr=BigInt(1),nd=BigInt(4),Es=16,pc=128,od=5,mc=2**31;function Et(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Dt(e.fromAffine,"Point.fromAffine"),Dt(e.fromBytes,"Point.fromBytes"),Dt(e.fromHex,"Point.fromHex"),gt(e.BASE,"Point.BASE"),gt(e.ZERO,"Point.ZERO"),er(e.Fp),er(e.Fn)}function Ln(t,e){Et(t),gc(e,t);let r=On(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function sd(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function id(t,e){let r=t*(4*e+128);if(r>mc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+mc/2**20+" MiB")}function As(t,e){if(t!==void 0){Dt(t,"randomBytes");try{let r=t(e);if(!wt(r)||r.length!==e)return}catch{return}return t}}function gc(t,e){_n(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function ad(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):bt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var bc=new WeakMap;function vs(t){return bc.get(t)||1}function cd(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function ud(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>Ss;){let i=0;t&Vr&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=Vr}return s}function fd(t,e,r){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let u=Number(t&s);t>>=i,u>o&&(u-=n,t+=Vr),a.push(u)}if(t!==Ss)throw new Error("invalid wnaf");return a}function ld(t,e,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=t;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=e[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var rr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){Et(e),this.randomBytes=As(r,Es),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=e;for(let c=0;c<o;c++){let u=a;for(let f=0;f<s;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(e,r){let{W:n,windows:o,comp:s}=e,i=2**(n-1),a=fd(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],p=f*i,d=Math.abs(l)-1,x=s[p];for(let w=1;w<i;w++)x=w===d?s[p+w]:x;let m=x.negate();l===0?u=u.add(s[p]):c=c.add(l<0?m:x)}return{p:c,f:u}}getWnafPrecomputes(e,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!gs(r,Vr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=vs(e);return s===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+pc,s=this.randomBytes(Es);if(!wt(s)||s.length!==Es)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Qe(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=od,s=1<<o,i=Mr(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(e);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let d=0;d<o;d++)u=u.double();let l=Number(r>>BigInt(f*o)&i),p=a[0];for(let d=1;d<s;d++)p=d===l?a[d]:p;u=u.add(p)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Vr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!bt(r))throw new Error("invalid scalar");let o=vs(e);if(o===1||r>=this.Point.Fn.ORDER)return Rn(this.Point,[e],[r],!0);let s=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(e,r){this.assertPoint(e),sd(r,this.bits);let n=Math.ceil((this.bits+pc)/r)+1;id(n*2**(r-1),this.Point.Fp.BYTES),bc.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return vs(e)!==1}};function Rn(t,e,r,n=!1){if(Et(t),gc(e,t),Ce(n,"allowOversized"),ad(r,t.Fn,n?t.Fn.ORDER**nd:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>cd(i,4)),s=r.map(i=>ud(i,4));return ld(t.ZERO,o,s)}function yc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return er(e),e}else return tr(t,{isLE:r})}function Nn(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Oe(r);for(let c of["p","n","h"]){let u=e[c];if(!(bt(u)&&u!==Ss))throw new Error(`CURVE.${c} must be positive bigint`)}let o=yc(e.p,r.Fp,n),s=yc(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function kn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var Fn=BigInt(0),Un=BigInt(1),Mn=BigInt(2),dd=BigInt(4),wc=BigInt(8);function hd(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function xc(t,e={}){Oe(e,{},{},"extraOpts");let r=e,n=Nn("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(Kr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Kr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Oe(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Pt:r.randomBytes,u=Mn<<BigInt(o.BYTES*8)-Un;function f(I){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(I)}let l=r.uvRatio===void 0?(I,g)=>{try{return{isValid:!0,value:o.sqrt(o.div(I,g))}}catch{return{isValid:!1,value:Fn}}}:r.uvRatio;if(!hd(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let p=o.eql(i.a,o.neg(o.ONE))?I=>o.neg(I):o.eql(i.a,o.ONE)?I=>I:I=>o.mul(i.a,I);function d(I,g,S=!1){let A=S?Un:Fn;return Qt("coordinate "+I,g,A,u),g}function x(I){if(!(I instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new m(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(g,S,A,N){this.X=d("x",g),this.Y=d("y",S),this.Z=d("z",A,!0),this.T=d("t",N),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof m)throw new Error("extended point not allowed");let{x:S,y:A}=g||{};return d("x",S),d("y",A),new m(S,A,o.ONE,o.mul(S,A))}static fromBytes(g,S=!1){let A=o.BYTES,{a:N,d:U}=i;g=Ur(G(g,A,"point")),Ce(S,"zip215");let k=Ur(g),O=g[A-1];k[A-1]=O&-129;let L=Lt(k),$=S?u:o.ORDER;Qt("point.y",L,Fn,$);let z=o.sqr(L),J=o.sub(z,o.ONE),B=o.sub(o.mulN(U,z),N),{isValid:M,value:K}=l(J,B);if(!M)throw new Error("bad point: invalid y coordinate");let P=f(K),re=(O&128)!==0;if(!S&&o.is0(K)&&re)throw new Error("bad point: x=0 and x_0=1");return re!==P&&(K=o.neg(K)),m.fromAffine({x:K,y:L})}static fromHex(g,S=!1){return m.fromBytes(Xt(g),S)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=6,S=!0){return E.setWindowSize(this,g),S||this.multiply(Mn),this}assertValidity(){let g=this,{a:S,d:A}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:N,Y:U,Z:k,T:O}=g,L=o.sqr(N),$=o.sqr(U),z=o.sqr(k),J=o.sqr(z),B=o.mul(L,S),M=o.mul(o.add(B,$),z),K=o.add(J,o.mul(A,o.mul(L,$)));if(!o.eql(M,K))throw new Error("bad point: equation left != right (1)");let P=o.mul(N,U),re=o.mul(k,O);if(!o.eql(P,re))throw new Error("bad point: equation left != right (2)")}equals(g){x(g);let{X:S,Y:A,Z:N}=this,{X:U,Y:k,Z:O}=g,L=o.mul(S,O),$=o.mul(U,N),z=o.mul(A,O),J=o.mul(k,N);return o.eql(L,$)&&o.eql(z,J)}is0(){return this.equals(m.ZERO)}negate(){return new m(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:g,Y:S,Z:A}=this,N=o.sqr(g),U=o.sqr(S),k=o.mul(o.sqr(A),Mn),O=p(N),L=o.addN(g,S),$=o.sub(o.subN(o.sqr(L),N),U),z=o.addN(O,U),J=o.subN(z,k),B=o.subN(O,U),M=o.mul($,J),K=o.mul(z,B),P=o.mul($,B),re=o.mul(J,z);return new m(M,K,re,P)}add(g){x(g);let{d:S}=i,{X:A,Y:N,Z:U,T:k}=this,{X:O,Y:L,Z:$,T:z}=g,J=o.mul(A,O),B=o.mul(N,L),M=o.mul(o.mulN(k,S),z),K=o.mul(U,$),P=o.sub(o.subN(o.mulN(o.addN(A,N),o.addN(O,L)),J),B),re=o.subN(K,M),ie=o.addN(K,M),v=o.sub(B,p(J)),h=o.mul(P,re),y=o.mul(ie,v),b=o.mul(P,v),_=o.mul(re,ie);return new m(h,y,_,b)}subtract(g){return x(g),this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:S,f:A}=E.mulSecret(this,g,a,w);return w([S,A])[0]}multiplyUnsafe(g){if(!s.isValid(g))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return g===Fn?m.ZERO:this.is0()||g===Un?this:E.mulUnsafe(this,g,w)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return E.mulUnsafe(this,i.n).is0()}toAffine(g){let S=this,A=g;if(A!=null&&typeof A!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof A);let{X:N,Y:U,Z:k}=S,O=S.is0();A==null&&(A=O?o.create(wc):o.inv(k));let L=o.mul(N,A),$=o.mul(U,A),z=o.mul(k,A);if(O)return{x:o.ZERO,y:o.ONE};if(!o.eql(z,o.ONE))throw new Error("invZ was invalid");return{x:L,y:$}}clearCofactor(){return a===Un?this:a===Mn?this.double():a===dd?this.double().double():a===wc?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:g,y:S}=this.toAffine(),A=o.toBytes(S);return A[A.length-1]|=f(g)?128:0,A}toHex(){return kr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let w=I=>Ln(m,I),E=new rr(m,c);return E.bits>=6&&m.BASE.precompute(6),Object.freeze(m.prototype),Object.freeze(m),m}function Ec(t,e,r={}){if(Et(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Oe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(st(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Pt:o.randomBytes,p=o.toMontgomery,d=o.toMontgomerySecret,x=o.adjustScalarBytes===void 0?B=>B:o.adjustScalarBytes,m=o.domain===void 0?(B,M,K)=>{if(Ce(K,"phflag"),M.length||K)throw new Error("Contexts/pre-hash are not supported");return B}:o.domain;function w(B){return c.create(Lt(B))}function E(B){let M=O.secretKey;G(B,O.secretKey,"secretKey");let K=G(n(B),2*M,"hashedSecretKey"),P=x(K.slice(0,M)),re=K.slice(M,2*M),ie=w(P);return{head:P,prefix:re,scalar:ie}}function I(B){let{head:M,prefix:K,scalar:P}=E(B),re=i.multiply(P),ie=re.toBytes();return{head:M,prefix:K,scalar:P,point:re,pointBytes:ie}}function g(B){return I(B).pointBytes}function S(B=Uint8Array.of(),...M){let K=Fe(...M);return w(n(m(K,G(B,void 0,"context"),!!s)))}function A(B,M,K={}){Oe(K,{},{},"options"),B=Ur(G(B,void 0,"message")),s&&(B=s(B));let{prefix:P,scalar:re,pointBytes:ie}=I(M),v=S(K.context,P,B),h=i.multiply(v).toBytes(),y=S(K.context,h,ie,B),b=c.create(v+y*re);if(!c.isValid(b))throw new Error("sign failed: invalid s");let _=Fe(h,c.toBytes(b));return G(_,O.signature,"result")}let N={zip215:o.zip215};function U(B,M,K,P=N){Oe(P);let{context:re}=P,ie=P.zip215===void 0?!!N.zip215:P.zip215,v=O.signature;B=G(B,v,"signature"),M=G(M,void 0,"message"),K=G(K,O.publicKey,"publicKey"),ie!==void 0&&Ce(ie,"zip215"),s&&(M=s(M));let h=v/2,y=B.subarray(0,h),b=Lt(B.subarray(h,v)),_,T,C;try{_=t.fromBytes(K,ie),T=t.fromBytes(y,ie),C=i.multiplyUnsafe(b)}catch{return!1}if(!ie&&_.isSmallOrder())return!1;let R=S(re,y,K,M);return T.add(_.multiplyUnsafe(R)).subtract(C).clearCofactor().is0()}let k=a.BYTES,O={secretKey:k,publicKey:k,signature:2*k,seed:k};function L(B){return B=B===void 0?l(O.seed):B,G(B,O.seed,"seed")}function $(B){return wt(B)&&B.length===O.secretKey}function z(B,M){try{return!!t.fromBytes(B,M===void 0?N.zip215:M)}catch{return!1}}let J={getExtendedPublicKey:I,randomSecretKey:L,isValidSecretKey:$,isValidPublicKey:z,toMontgomery(B){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(t.fromBytes(B))},toMontgomerySecret(B){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(B)}};return Object.freeze(O),Object.freeze(J),Object.freeze({keygen:kn(L,g),getPublicKey:g,sign:A,verify:U,utils:J,Point:t,lengths:O})}var Is=BigInt(1),vc=BigInt(2);var pd=BigInt(5),md=BigInt(8),_s=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),yd={p:_s,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:md,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function gd(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=_s,a=t*t%s*t%s,c=se(a,vc,s)*a%s,u=se(c,Is,s)*t%s,f=se(u,pd,s)*u%s,l=se(f,e,s)*f%s,p=se(l,r,s)*l%s,d=se(p,n,s)*p%s,x=se(d,o,s)*d%s,m=se(x,o,s)*d%s,w=se(m,e,s)*f%s;return{pow_p_5_8:se(w,vc,s)*t%s,b2:a}}function Ic(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Sc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function bd(t,e){let r=_s,n=ce(e*e*e,r),o=ce(n*n*e,r),s=gd(t*o).pow_p_5_8,i=ce(t*n*s,r),a=ce(e*i*i,r),c=i,u=ce(i*Sc,r),f=a===t,l=a===ce(-t,r),p=a===ce(-t*Sc,r);return f&&(i=c),(l||p)&&(i=u),dc(i,r)&&(i=ce(-i,r)),{isValid:f||l,value:i}}var Bs=xc(yd,{uvRatio:bd}),Ac=Bs.Fp;function wd(t){let{y:e}=t;return Ac.toBytes(Ac.div(Is+e,Is-e))}function xd(t){let e=Bs.Fp.BYTES;return ke(t,e),Ic(ps(t.subarray(0,e))).subarray(0,e)}function Ed(t){return Ec(Bs,ps,Object.assign({adjustScalarBytes:Ic,toMontgomery:wd,toMontgomerySecret:xd,zip215:!0},t))}var _c=Ed({});var qr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Kn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Ue={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Kn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Vn=32;var Ts,vd=(async()=>{try{return await Ue.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Sd(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Ue.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Ue.get().subtle.verify({name:"Ed25519"},n,_e(e),_e(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ad(t,e,r){return _c.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Bc(t,e,r){return Ts==null&&(Ts=await vd),Ts?Sd(t,e,r):Ad(t,e,r)}function qn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var zn=class{type="Ed25519";raw;constructor(e){this.raw=Cs(e,Vn)}toMultihash(){return Ke.digest(Ge(this))}toCID(){return be.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=Bc(this.raw,r,e);return qn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Os(t){return t=Cs(t,Vn),new zn(t)}function Cs(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new ae(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var _d=Math.pow(2,7),Bd=Math.pow(2,14),Td=Math.pow(2,21),Ds=Math.pow(2,28),Ps=Math.pow(2,35),Ls=Math.pow(2,42),Rs=Math.pow(2,49),Q=128,Se=127;function De(t){if(t<_d)return 1;if(t<Bd)return 2;if(t<Td)return 3;if(t<Ds)return 4;if(t<Ps)return 5;if(t<Ls)return 6;if(t<Rs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function nr(t,e,r=0){switch(De(t)){case 8:e[r++]=t&255|Q,t/=128;case 7:e[r++]=t&255|Q,t/=128;case 6:e[r++]=t&255|Q,t/=128;case 5:e[r++]=t&255|Q,t/=128;case 4:e[r++]=t&255|Q,t>>>=7;case 3:e[r++]=t&255|Q,t>>>=7;case 2:e[r++]=t&255|Q,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Cd(t,e,r=0){switch(De(t)){case 8:e.set(r++,t&255|Q),t/=128;case 7:e.set(r++,t&255|Q),t/=128;case 6:e.set(r++,t&255|Q),t/=128;case 5:e.set(r++,t&255|Q),t/=128;case 4:e.set(r++,t&255|Q),t>>>=7;case 3:e.set(r++,t&255|Q),t>>>=7;case 2:e.set(r++,t&255|Q),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function Ns(t,e){let r=t[e],n=0;if(n+=r&Se,r<Q||(r=t[e+1],n+=(r&Se)<<7,r<Q)||(r=t[e+2],n+=(r&Se)<<14,r<Q)||(r=t[e+3],n+=(r&Se)<<21,r<Q)||(r=t[e+4],n+=(r&Se)*Ds,r<Q)||(r=t[e+5],n+=(r&Se)*Ps,r<Q)||(r=t[e+6],n+=(r&Se)*Ls,r<Q)||(r=t[e+7],n+=(r&Se)*Rs,r<Q))return n;throw new RangeError("Could not decode varint")}function Od(t,e){let r=t.get(e),n=0;if(n+=r&Se,r<Q||(r=t.get(e+1),n+=(r&Se)<<7,r<Q)||(r=t.get(e+2),n+=(r&Se)<<14,r<Q)||(r=t.get(e+3),n+=(r&Se)<<21,r<Q)||(r=t.get(e+4),n+=(r&Se)*Ds,r<Q)||(r=t.get(e+5),n+=(r&Se)*Ps,r<Q)||(r=t.get(e+6),n+=(r&Se)*Ls,r<Q)||(r=t.get(e+7),n+=(r&Se)*Rs,r<Q))return n;throw new RangeError("Could not decode varint")}function or(t,e,r=0){return e==null&&(e=ve(De(t))),e instanceof Uint8Array?nr(t,e,r):Cd(t,e,r)}function zr(t,e=0){return t instanceof Uint8Array?Ns(t,e):Od(t,e)}var Fs=new Float32Array([-0]),vt=new Uint8Array(Fs.buffer);function Cc(t,e,r){Fs[0]=t,e[r]=vt[0],e[r+1]=vt[1],e[r+2]=vt[2],e[r+3]=vt[3]}function Oc(t,e){return vt[0]=t[e],vt[1]=t[e+1],vt[2]=t[e+2],vt[3]=t[e+3],Fs[0]}var Us=new Float64Array([-0]),Ae=new Uint8Array(Us.buffer);function Dc(t,e,r){Us[0]=t,e[r]=Ae[0],e[r+1]=Ae[1],e[r+2]=Ae[2],e[r+3]=Ae[3],e[r+4]=Ae[4],e[r+5]=Ae[5],e[r+6]=Ae[6],e[r+7]=Ae[7]}function Pc(t,e){return Ae[0]=t[e],Ae[1]=t[e+1],Ae[2]=t[e+2],Ae[3]=t[e+3],Ae[4]=t[e+4],Ae[5]=t[e+5],Ae[6]=t[e+6],Ae[7]=t[e+7],Us[0]}var Dd=BigInt(Number.MAX_SAFE_INTEGER),Pd=BigInt(Number.MIN_SAFE_INTEGER),Le=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Rt;if(e<Dd&&e>Pd)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Lc&&(o=0n,++n>Lc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Rt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Rt}},Rt=new Le(0,0);Rt.toBigInt=function(){return 0n};Rt.zzEncode=Rt.zzDecode=function(){return this};Rt.length=function(){return 1};var Lc=4294967296n;function Rc(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Nc(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Ms(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function qe(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Hn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Ks=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=_e(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,qe(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw qe(this,4);return Hn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw qe(this,4);return Hn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw qe(this,4);let e=Oc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw qe(this,4);let e=Pc(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw qe(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Nc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw qe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw qe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Le(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw qe(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw qe(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw qe(this,8);let e=Hn(this.buf,this.pos+=4),r=Hn(this.buf,this.pos+=4);return new Le(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ns(this.buf,this.pos);return this.pos+=De(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Hr(t){return new Ks(t instanceof Uint8Array?t:t.subarray())}function ze(t,e,r){let n=Hr(t);return e.decode(n,void 0,r)}function Vs(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return ve(i);o+i>e&&(n=ve(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Nt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function qs(){}var Hs=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Ld=Vs();function Rd(t){return globalThis.Buffer!=null?ve(t):Ld(t)}var jr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Nt(qs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Nt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new $s((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push($n,10,Le.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Le.fromBigInt(e);return this._push($n,r.length(),r)}uint64Number(e){return this._push(nr,De(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Le.fromBigInt(e).zzEncode();return this._push($n,r.length(),r)}sint64Number(e){let r=Le.fromNumber(e).zzEncode();return this._push($n,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(zs,1,e?1:0)}fixed32(e){return this._push($r,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Le.fromBigInt(e);return this._push($r,4,r.lo)._push($r,4,r.hi)}fixed64Number(e){let r=Le.fromNumber(e);return this._push($r,4,r.lo)._push($r,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Cc,4,e)}double(e){return this._push(Dc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(zs,1,0):this.uint32(r)._push(kd,r,e)}string(e){let r=Rc(e);return r!==0?this.uint32(r)._push(Ms,r,e):this._push(zs,1,0)}fork(){return this.states=new Hs(this),this.head=this.tail=new Nt(qs,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 Nt(qs,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Rd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function zs(t,e,r){e[r]=t&255}function Nd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var $s=class extends Nt{next;constructor(e,r){super(Nd,e,r),this.next=void 0}};function $n(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function $r(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function kd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(jr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Fd,e,t),this},jr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Ud,e,t),this});function Fd(t,e,r){e.set(t,r)}function Ud(t,e,r){t.length<40?Ms(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(V(t),r)}function js(){return new jr}function He(t,e){let r=js();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*$e(t,e,r){let n=Hr(t);yield*e.stream(n,void 0,".",r)}var jn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Yn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Ys(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i,a){};return Yn("enum",jn.VARINT,r,n,o)}function je(t,e,r){return Yn("message",jn.LENGTH_DELIMITED,t,e,r)}var Je=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ue;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(ue||(ue={}));var Ws;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Ws||(Ws={}));(function(t){t.codec=()=>Ys(Ws)})(ue||(ue={}));var et;(function(t){let e;t.codec=()=>(e==null&&(e=je((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ue.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=ue.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ue.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return He(s,t.codec())}t.encode=r;function n(s,i){return ze(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(et||(et={}));var Zs;(function(t){let e;t.codec=()=>(e==null&&(e=je((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ue.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=ue.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ue.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return He(s,t.codec())}t.encode=r;function n(s,i){return ze(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(Zs||(Zs={}));var Wr={};Be(Wr,{MAX_RSA_KEY_SIZE:()=>Gs,generateRSAKeyPair:()=>Vc,jwkToJWKKeyPair:()=>qc,jwkToPkcs1:()=>qd,jwkToPkix:()=>ei,jwkToRSAPrivateKey:()=>oi,pkcs1MessageToJwk:()=>Qs,pkcs1MessageToRSAPrivateKey:()=>ti,pkcs1ToJwk:()=>Vd,pkcs1ToRSAPrivateKey:()=>Kc,pkixMessageToJwk:()=>Js,pkixMessageToRSAPublicKey:()=>ni,pkixToJwk:()=>zd,pkixToRSAPublicKey:()=>ri});var sr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Wr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return be.createV1(114,this._multihash)}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,r,n){return Mc(this.jwk,r,e,n)}},Yr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Wr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}sign(e,r){return Uc(this.jwk,e,r)}};var Gs=8192,Xs=18,Md=1062,Kd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Vd(t){let e=nt(t);return Qs(e)}function Qs(t){return{n:H(t[1],"base64url"),e:H(t[2],"base64url"),d:H(t[3],"base64url"),p:H(t[4],"base64url"),q:H(t[5],"base64url"),dp:H(t[6],"base64url"),dq:H(t[7],"base64url"),qi:H(t[8],"base64url"),kty:"RSA"}}function qd(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new ae("JWK was missing components");return ht([Te(Uint8Array.from([0])),Te(V(t.n,"base64url")),Te(V(t.e,"base64url")),Te(V(t.d,"base64url")),Te(V(t.p,"base64url")),Te(V(t.q,"base64url")),Te(V(t.dp,"base64url")),Te(V(t.dq,"base64url")),Te(V(t.qi,"base64url"))]).subarray()}function zd(t){let e=nt(t,{offset:0});return Js(e)}function Js(t){let e=nt(t[1],{offset:0});return{kty:"RSA",n:H(e[0],"base64url"),e:H(e[1],"base64url")}}function ei(t){if(t.n==null||t.e==null)throw new ae("JWK was missing components");return ht([Kd,gn(ht([Te(V(t.n,"base64url")),Te(V(t.e,"base64url"))]))]).subarray()}function Kc(t){let e=nt(t);return ti(e)}function ti(t){let e=Qs(t);return oi(e)}function ri(t,e){if(t.byteLength>=Md)throw new zt("Key size is too large");let r=nt(t,{offset:0});return ni(r,t,e)}function ni(t,e,r){let n=Js(t);if(r==null){let o=Gt(et.encode({Type:ue.RSA,Data:e}));r=We(Xs,o)}return new sr(n,r)}function oi(t){if(Hc(t)>Gs)throw new ae("Key size is too large");let e=qc(t),r=Gt(et.encode({Type:ue.RSA,Data:ei(e.publicKey)})),n=We(Xs,r);return new Yr(e.privateKey,new sr(e.publicKey,n))}async function Vc(t){if(t>Gs)throw new ae("Key size is too large");let e=await zc(t),r=Gt(et.encode({Type:ue.RSA,Data:ei(e.publicKey)})),n=We(Xs,r);return new Yr(e.privateKey,new sr(e.publicKey,n))}function qc(t){if(t==null)throw new ae("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function zc(t,e){let r=await Ue.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Hd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Uc(t,e,r){let n=await Ue.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ue.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,_e(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Mc(t,e,r,n){let o=await Ue.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Ue.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,_e(e),_e(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Hd(t,e){if(t.privateKey==null||t.publicKey==null)throw new ae("Private and public key are required");let r=await Promise.all([Ue.get().subtle.exportKey("jwk",t.privateKey),Ue.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Hc(t){if(t.kty!=="RSA")throw new ae("invalid key type");if(t.n==null)throw new ae("invalid key modulus");return V(t.n,"base64url").length*8}var Wn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(xn(e),ke(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Ot(o)}update(e){return Zt(this),this.iHash.update(e),this}digestInto(e){Zt(this),En(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},$c=(()=>{let t=((e,r,n)=>new Wn(e,r).update(n).digest());return t.create=(e,r)=>new Wn(e,r),t})();var $d=BigInt(0),si=class extends Error{constructor(e=""){super(e)}},it={Err:si,_tlv:{encode:(t,e)=>{let{Err:r}=it;if(st(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Ja(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Fr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Fr(o.length/2|128):"";return Fr(t)+s+o+e},decode(t,e){let{Err:r}=it;e=G(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=it;if(Bn(t),t<$d)throw new e("integer: negative integers are not allowed");let r=Fr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=it;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Qe(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:o}=it;if(e!==void 0&&(st(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let s=G(t,void 0,"signature"),{v:i,l:a}=o.decode(48,s);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,i),{v:f,l}=o.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||f.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=it;Oe(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},Zn=(Object.freeze(it._tlv),Object.freeze(it._int),Object.freeze(it));var jc=(t,e)=>(t+(t>=0?e:-e)/Yc)/e;function jd(t,e,r){Qt("scalar",t,at,r);let[[n,o],[s,i]]=e,a=jc(i*t,r),c=jc(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,l=u<at,p=f<at;l&&(u=-u),p&&(f=-f);let d=Mr(Math.ceil(Jt(r)/2))+kt;if(u<at||u>=d||f<at||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:p,k2:f}}function ci(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function ii(t,e){Oe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ce(r.lowS,"lowS"),Ce(r.prehash,"prehash"),r.format!==void 0&&ci(r.format),r}var at=BigInt(0),kt=BigInt(1),Yc=BigInt(2),ai=BigInt(3),Yd=BigInt(4);function Wc(t,e={}){let r=Nn("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Oe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:p,toBytes:d}=e,x=e.randomBytes===void 0?Pt:e.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let m=c?{beta:c.beta,basises:c.basises.map(v=>[...v])}:void 0,w=Gc(n,o);function E(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function I(v,h,y){if(h.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:b,y:_}=h.toAffine(),T=n.toBytes(b);if(Ce(y,"isCompressed"),y){E();let C=!n.isOdd(_);return Fe(Zc(C),T)}else return Fe(Uint8Array.of(4),T,n.toBytes(_))}function g(v){G(v,void 0,"Point");let{publicKey:h,publicKeyUncompressed:y}=w,b=v.length,_=v[0],T=v.subarray(1);if(u&&b===1&&_===0)return{x:n.ZERO,y:n.ZERO};if(b===h&&(_===2||_===3)){let C=n.fromBytes(T);if(!n.isValid(C))throw new Error("bad point: is not on curve, wrong x");let R=k(C),F;try{F=n.sqrt(R)}catch(le){let ne=le instanceof Error?": "+le.message:"";throw new Error("bad point: is not on curve, sqrt error"+ne)}E();let Z=n.isOdd(F);return(_&1)===1!==Z&&(F=n.neg(F)),{x:C,y:F}}else if(b===y&&_===4){let C=n.BYTES,R=n.fromBytes(T.subarray(0,C)),F=n.fromBytes(T.subarray(C,C*2));if(!O(R,F))throw new Error("bad point: is not on curve");return{x:R,y:F}}else throw new Error(`bad point: got length ${b}, expected compressed=${h} or uncompressed=${y}`)}let S=d===void 0?I:d,A=p===void 0?g:p,N=n.mul(s.b,ai),U=n.is0(s.a)?v=>n.ZERO:v=>n.mul(s.a,v);function k(v){let h=n.sqr(v),y=n.mul(h,v);return n.add(n.add(y,n.mul(v,s.a)),s.b)}function O(v,h){let y=n.sqr(h),b=k(v);return n.eql(y,b)}if(!O(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let L=n.mul(n.pow(s.a,ai),Yd),$=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(L,$)))throw new Error("bad curve params: a or b");function z(v,h,y=!1){if(!n.isValid(h)||y&&n.is0(h))throw new Error(`bad point coordinate ${v}`);return typeof h=="object"&&h!==null?n.create(h):h}function J(v){if(!(v instanceof P))throw new Error("Weierstrass Point expected")}function B(v){if(!m||!m.basises)throw new Error("no endo");return jd(v,m.basises,o.ORDER)}function M(v,h,y,b){if(!o.isValid(b))throw new RangeError("invalid scalar: out of range");if(m){let{k1neg:_,k1:T,k2neg:C,k2:R}=B(b),F=new P(n.mul(y.X,m.beta),y.Y,y.Z);v.push(_?y.negate():y,C?F.negate():F),h.push(T,R)}else v.push(y),h.push(b)}let K=new WeakSet;class P{static BASE=new P(s.Gx,s.Gy,n.ONE);static ZERO=new P(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,y,b){this.X=z("x",h),this.Y=z("y",y,!0),this.Z=z("z",b),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x:y,y:b}=h||{};if(!h||!n.isValid(y)||!n.isValid(b))throw new Error("invalid affine point");if(h instanceof P)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(b)?P.ZERO:new P(y,b,n.ONE)}static fromBytes(h){let y=P.fromAffine(A(G(h,void 0,"point")));return y.assertValidity(),y}static fromHex(h){return P.fromBytes(Xt(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=6,y=!0){return ie.setWindowSize(this,h),y||this.multiply(ai),this}assertValidity(){let h=this;if(h.is0()){if(u&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}if(K.has(h))return;let{x:y,y:b}=h.toAffine();if(!n.isValid(y)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!O(y,b))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");K.add(h)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){J(h);let{X:y,Y:b,Z:_}=this,{X:T,Y:C,Z:R}=h,F=n.eql(n.mul(y,R),n.mul(T,_)),Z=n.eql(n.mul(b,R),n.mul(C,_));return F&&Z}negate(){return new P(this.X,n.neg(this.Y),this.Z)}double(){let{X:h,Y:y,Z:b}=this,_=n.ZERO,T=n.ZERO,C=n.ZERO,R=n.mul(h,h),F=n.mul(y,y),Z=n.mul(b,b),j=n.mul(h,y);return j=n.add(j,j),C=n.mul(h,b),C=n.add(C,C),_=U(C),T=n.mul(N,Z),T=n.add(_,T),_=n.sub(F,T),T=n.add(F,T),T=n.mul(_,T),_=n.mul(j,_),C=n.mul(N,C),Z=U(Z),j=n.sub(R,Z),j=U(j),j=n.add(j,C),C=n.add(R,R),R=n.add(C,R),R=n.add(R,Z),R=n.mul(R,j),T=n.add(T,R),Z=n.mul(y,b),Z=n.add(Z,Z),R=n.mul(Z,j),_=n.sub(_,R),C=n.mul(Z,F),C=n.add(C,C),C=n.add(C,C),new P(_,T,C)}add(h){J(h);let{X:y,Y:b,Z:_}=this,{X:T,Y:C,Z:R}=h,F=n.ZERO,Z=n.ZERO,j=n.ZERO,le=n.mul(y,T),ne=n.mul(b,C),ge=n.mul(_,R),Re=n.add(y,b),oe=n.add(T,C);Re=n.mul(Re,oe),oe=n.add(le,ne),Re=n.sub(Re,oe),oe=n.add(y,_);let de=n.add(T,R);return oe=n.mul(oe,de),de=n.add(le,ge),oe=n.sub(oe,de),de=n.add(b,_),F=n.add(C,R),de=n.mul(de,F),F=n.add(ne,ge),de=n.sub(de,F),j=U(oe),F=n.mul(N,ge),j=n.add(F,j),F=n.sub(ne,j),j=n.add(ne,j),Z=n.mul(F,j),ne=n.add(le,le),ne=n.add(ne,le),ge=U(ge),oe=n.mul(N,oe),ne=n.add(ne,ge),ge=n.sub(le,ge),ge=U(ge),oe=n.add(oe,ge),le=n.mul(ne,oe),Z=n.add(Z,le),le=n.mul(de,oe),F=n.mul(Re,F),F=n.sub(F,le),le=n.mul(Re,ne),j=n.mul(de,j),j=n.add(j,le),new P(F,Z,j)}subtract(h){return J(h),this.add(h.negate())}is0(){return this.equals(P.ZERO)}multiply(h){if(!o.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let{p:y,f:b}=ie.mulSecret(this,h,i,re);return re([y,b])[0]}multiplyUnsafe(h){let y=this,b=h;if(!o.isValid(b))throw new RangeError("invalid scalar: out of range");if(b===at||y.is0())return P.ZERO;if(b===kt)return y;if(ie.hasWindowSize(this))return ie.mulUnsafe(y,b,re);let _=[],T=[];return M(_,T,y,b),Rn(P,_,T)}mulAddUnsafe(h,y,b){J(y);let _=[],T=[];return M(_,T,this,h),M(_,T,y,b),Rn(P,_,T)}toAffine(h){let y=this,b=h;if(b!=null&&!n.isValid(b))throw new RangeError('"invertedZ" expected valid field element');let{X:_,Y:T,Z:C}=y;if(n.eql(C,n.ONE))return{x:_,y:T};let R=y.is0();b==null&&(b=R?n.ONE:n.inv(C));let F=n.mul(_,b),Z=n.mul(T,b),j=n.mul(C,b);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(j,n.ONE))throw new Error("invZ was invalid");return{x:F,y:Z}}isTorsionFree(){return i===kt?!0:l?l(P,this):ie.mulUnsafe(this,a).is0()}clearCofactor(){return i===kt?this:f?f(P,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===kt?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return Ce(h,"isCompressed"),this.assertValidity(),S(P,this,h)}toHex(h=!0){return kr(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let re=v=>Ln(P,v),ie=new rr(P,x);return ie.bits>=6&&P.BASE.precompute(6),Object.freeze(P.prototype),Object.freeze(P),P}function Zc(t){return Uint8Array.of(t?2:3)}function Gc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Wd(t,e={}){Et(t);let{Fn:r}=t,n=e.randomBytes===void 0?Pt:e.randomBytes,o=Object.assign(Gc(t.Fp,r),{seed:Math.max(Dn(r.ORDER),16)});function s(d){try{let x=r.fromBytes(d);return r.isValidNot0(x)}catch{return!1}}function i(d,x){let{publicKey:m,publicKeyUncompressed:w}=o;try{let E=d.length;return x===!0&&E!==m||x===!1&&E!==w?!1:!t.fromBytes(d).is0()}catch{return!1}}function a(d){return d=d===void 0?n(o.seed):d,Pn(G(d,o.seed,"seed"),r.ORDER)}function c(d,x=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(x)}function u(d){let{secretKey:x,publicKey:m,publicKeyUncompressed:w}=o,E=r._lengths;if(!wt(d))return;let I=G(d,void 0,"key").length,g=I===m||I===w,S=I===x||!!E?.includes(I);if(!(g&&S))return g}function f(d,x,m=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(x)===!1)throw new Error("second arg must be public key");let w=r.fromBytes(d),E=t.fromBytes(x);if(E.is0())throw new Error("invalid public key: point at infinity");return E.multiply(w).toBytes(m)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},p=kn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:p,Point:t,utils:l,lengths:o})}function Xc(t,e,r={}){Et(t);let n=e;xn(n),Oe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?Pt:o.randomBytes,i=o.hmac===void 0?(v,h)=>$c(n,v,h):o.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:f}=c,l=Dn(u),p=As(s,l),{keygen:d,getPublicKey:x,getSharedSecret:m,utils:w,lengths:E}=Wd(t,o),I={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=u*Yc+kt<a.ORDER;function S(v){let h=u>>kt;return v>h}function A(v,h){if(!c.isValidNot0(h))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return h}function N(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function U(v,h,y){return N(),(v===y?0:2)|Number(a.isOdd(h))}function k(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(v,h){ci(h);let y=E.signature,b=h==="compact"?y:h==="recovered"?y+1:void 0;return G(v,b)}class L{r;s;recovery;constructor(h,y,b){if(this.r=A("r",h),this.s=A("s",y),b!=null){if(k(),![0,1,2,3].includes(b))throw new Error("invalid recovery id");this.recovery=b}Object.freeze(this)}static fromBytes(h,y=I.format){O(h,y);let b;if(y==="der"){if(h.length>2*c.BYTES+16)throw new Zn.Err("invalid signature: DER signature too long");let{r:R,s:F}=Zn.toSig(G(h),c.BYTES+1);return new L(R,F)}y==="recovered"&&(b=h[0],y="compact",h=h.subarray(1));let _=E.signature/2,T=h.subarray(0,_),C=h.subarray(_,_*2);return new L(c.fromBytes(T),c.fromBytes(C),b)}static fromHex(h,y){return this.fromBytes(Xt(h),y)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new L(this.r,this.s,h)}recoverPublicKey(h){let{r:y,s:b}=this,_=this.assertRecovery(),T=_===2||_===3?y+u:y;if(!a.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=a.toBytes(T),R=t.fromBytes(Fe(Zc((_&1)===0),C)),F=c.inv(T),Z=z(G(h,void 0,"msgHash")),j=c.create(-Z*F),le=c.create(b*F),ne=t.BASE.mulAddUnsafe(j,R,le);if(ne.is0())throw new Error("invalid recovery: point at infinify");return ne.assertValidity(),ne}hasHighS(){return S(this.s)}toBytes(h=I.format){if(ci(h),h==="der")return Xt(Zn.hexFromSig(this));let{r:y,s:b}=this,_=c.toBytes(y),T=c.toBytes(b);return h==="recovered"?(k(),Fe(Uint8Array.of(this.assertRecovery()),_,T)):Fe(_,T)}toHex(h){return kr(this.toBytes(h))}}Object.freeze(L.prototype),Object.freeze(L);let $=o.bits2int===void 0?function(h){if(h.length>8192)throw new Error("input is too large");let y=Qe(h),b=h.length*8-f;return b>0?y>>BigInt(b):y}:o.bits2int,z=o.bits2int_modN===void 0?function(h){return c.create($(h))}:o.bits2int_modN,J=Mr(f);function B(v){return Qt("num < 2^"+f,v,at,J),c.toBytes(v)}function M(v,h){return G(v,void 0,"message"),h?G(n(v),void 0,"prehashed message"):v}function K(v,h,y){let{lowS:b,prehash:_,extraEntropy:T}=ii(y,I);v=M(v,_);let C=z(v),R=c.fromBytes(h);if(!c.isValidNot0(R))throw new Error("invalid private key");let F=[B(R),B(C)];if(T!=null&&T!==!1){let ne=T===!0?s(E.secretKey):T;F.push(G(ne,void 0,"extraEntropy"))}let Z=Fe(...F),j=C;function le(ne){let ge=$(ne);if(!c.isValidNot0(ge))return;let Re=t.BASE.multiply(ge).toAffine(),oe=c.create(Re.x);if(oe===at)return;let de;if(p!==void 0){let Sr=Qe(Pn(p(l),u)),rf=c.inv(c.mul(Sr,ge)),nf=c.mul(Sr,j),of=c.mul(Sr,R);de=c.create(rf*c.create(nf+of*oe))}else{let Sr=uc(ge,u);de=c.create(Sr*c.create(j+oe*R))}if(de===at)return;let _o=U(Re.x,Re.y,oe),oa=de;return b&&S(de)&&(oa=c.neg(de),_o^=1),new L(oe,oa,g?void 0:_o)}return{seed:Z,k2sig:le}}function P(v,h,y={}){let{seed:b,k2sig:_}=K(v,h,y);return tc(n.outputLen,c.BYTES,i)(b,_).toBytes(y.format)}function re(v,h,y,b={}){let{lowS:_,prehash:T,format:C}=ii(b,I);if(y=G(y,void 0,"publicKey"),h=M(h,T),!wt(v)){let R=v instanceof L?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+R)}O(v,C);try{let R=L.fromBytes(v,C),F=t.fromBytes(y);if(F.is0()||_&&R.hasHighS())return!1;let{r:Z,s:j}=R,le=z(h),ne=c.inv(j),ge=c.create(le*ne),Re=c.create(Z*ne),oe=t.BASE.mulAddUnsafe(ge,F,Re);if(oe.is0())return!1;let de=oe.toAffine();return!(c.create(de.x)!==Z||C==="recovered"&&R.recovery!==U(de.x,de.y,Z))}catch{return!1}}function ie(v,h,y={}){let{prehash:b}=ii(y,I);return h=M(h,b),L.fromBytes(v,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:d,getPublicKey:x,getSharedSecret:m,utils:w,lengths:E,Point:t,sign:P,verify:re,recoverPublicKey:ie,Signature:L,hash:n})}var fi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Zd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Qc=BigInt(2);function Gd(t){let e=fi.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=se(f,r,e)*f%e,p=se(l,r,e)*f%e,d=se(p,Qc,e)*u%e,x=se(d,o,e)*d%e,m=se(x,s,e)*x%e,w=se(m,a,e)*m%e,E=se(w,c,e)*w%e,I=se(E,a,e)*m%e,g=se(I,r,e)*f%e,S=se(g,i,e)*x%e,A=se(S,n,e)*u%e,N=se(A,Qc,e);if(!ui.eql(ui.sqr(N),t))throw new Error("Cannot find square root");return N}var ui=tr(fi.p,{sqrt:Gd}),Xd=Wc(fi,{Fp:ui,endo:Zd}),ir=Xc(Xd,Gt);function Jc(t,e,r,n){let o=Cr.digest(r instanceof Uint8Array?r:r.subarray());if(qn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ir.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new qr(String(s))});try{return n?.signal?.throwIfAborted(),ir.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new qr(String(s))}}var Gn=class{type="secp256k1";raw;_key;constructor(e){this._key=tu(e),this.raw=eu(this._key)}toMultihash(){return Ke.digest(Ge(this))}toCID(){return be.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:me(this.raw,e.raw)}verify(e,r,n){return Jc(this._key,r,e,n)}};function li(t){return new Gn(t)}function eu(t){return ir.Point.fromBytes(t).toBytes()}function tu(t){try{return ir.Point.fromBytes(t),t}catch(e){throw new zt(String(e))}}function ar(t,e){let{Type:r,Data:n}=et.decode(t),o=n??new Uint8Array;switch(r){case ue.RSA:return ri(o,e);case ue.Ed25519:return Os(o);case ue.secp256k1:return li(o);case ue.ECDSA:return ns(o);default:throw new It}}function ru(t){let{Type:e,Data:r}=et.decode(t.digest),n=r??new Uint8Array;switch(e){case ue.Ed25519:return Os(n);case ue.secp256k1:return li(n);case ue.ECDSA:return ns(n);default:throw new It}}function Ge(t){return et.encode({Type:ue[t.type],Data:t.raw})}var Zr;(function(t){let e;t.codec=()=>(e==null&&(e=je((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:we(0),payloadType:we(0),payload:we(0),signature:we(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return He(s,t.codec())}t.encode=r;function n(s,i){return ze(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(Zr||(Zr={}));var Xn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var tt=class t{static createFromProtobuf=e=>{let r=Zr.decode(e),n=ar(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=nu(o,s,i),c=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new Xn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Zr.encode({publicKey:Ge(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:me(this.marshal(),e.marshal())}async validate(e,r){let n=nu(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},nu=(t,e,r)=>{let n=V(t),o=or(n.byteLength),s=or(e.length),i=or(r.length);return new pe(o,n,s,e,i,r)};var ou=Symbol.for("nodejs.util.inspect.custom"),Qd=114,Gr=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[To]=!0;toString(){return this.string==null&&(this.string=he.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return be.createV1(Qd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return me(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return me(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[ou](){return`PeerId(${this.toString()})`}},Xr=class extends Gr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Qr=class extends Gr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Jr=class extends Gr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Jd=2336,en=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ke.digest(V(this.url))}[ou](){return`PeerId(${this.url})`}[To]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return be.createV1(Jd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=H(e)),e.toString()===this.toString())}};var eh=114,su=2336;function iu(t){if(t.type==="Ed25519")return new Qr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Jr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Xr({multihash:t.toCID().multihash,publicKey:t});throw new It}function di(t){if(rh(t))return new Xr({multihash:t});if(th(t))try{let e=ru(t);if(e.type==="Ed25519")return new Qr({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Jr({multihash:t,publicKey:e})}catch{let r=H(t.digest);return new en(new URL(r))}throw new dn("Supplied PeerID Multihash is invalid")}function Qn(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==eh&&t.code!==su)throw new ln("Supplied PeerID CID is invalid");if(t.code===su){let e=H(t.multihash.digest);return new en(new URL(e))}return di(t.multihash)}function th(t){return t.code===Ke.code}function rh(t){return t.code===Cr.code}var Ee=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ct=class extends Error{static name="ValidationError";name="ValidationError"},Jn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},eo=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var to=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let p=Number.parseInt(l,e);if(!Number.isNaN(p))return p});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var au=45,nh=15,cr=new to;function ro(t){if(!(t.length>nh))return cr.new(t).parseWith(()=>cr.readIPv4Addr())}function no(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>au))return cr.new(t).parseWith(()=>cr.readIPv6Addr())}function ur(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>au)return;let r=cr.new(t).parseWith(()=>cr.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function fr(t){return!!ro(t)}function oo(t){return!!no(t)}function pi(t){return e=>H(e,t)}function mi(t){return e=>V(e,t)}function lr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Ft(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function cu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=V(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ft(n);return Ze([r,o],r.length+o.length)}function uu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=dt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ft(n);return Ze([r,o],r.length+o.length)}function yi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=H(e,"base32"),o=lr(r);return`${n}:${o}`}var gi=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new Ee("Invalid byte value in IP address");e[n]=o}),e},fu=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=fr(r[n]),i;s&&(i=gi(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(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new Ee("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},lu=function(t){if(t.byteLength!==4)throw new Ee("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},du=function(t){if(t.byteLength!==16)throw new Ee("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Ee(`Invalid IPv6 address "${r}"`)}};function hu(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new Ee(`Invalid IPv6 address "${t}"`)}}var hi=Object.values(Or).map(t=>t.decoder),oh=(function(){let t=hi[0].or(hi[1]);return hi.slice(2).forEach(e=>t=t.or(e)),t})();function pu(t){return oh.decode(t)}function mu(t){return e=>t.encoder.encode(e)}function sh(t){if(parseInt(t).toString()!==t)throw new ct("Value must be an integer")}function ih(t){if(t<0)throw new ct("Value must be a positive integer, or zero")}function ah(t){return e=>{if(e>t)throw new ct(`Value must be smaller than or equal to ${t}`)}}function ch(...t){return e=>{for(let r of t)r(e)}}var tn=ch(sh,ih,ah(65535));var xe=-1,bi=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new eo(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ft=new bi,vh=[{code:4,name:"ip4",size:32,valueToBytes:gi,bytesToValue:lu,validate:t=>{if(!fr(t))throw new ct(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ft,bytesToValue:lr,validate:tn},{code:273,name:"udp",size:16,valueToBytes:Ft,bytesToValue:lr,validate:tn},{code:33,name:"dccp",size:16,valueToBytes:Ft,bytesToValue:lr,validate:tn},{code:41,name:"ip6",size:128,valueToBytes:fu,bytesToValue:du,stringToValue:hu,validate:t=>{if(!oo(t))throw new ct(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:xe},{code:43,name:"ipcidr",size:8,bytesToValue:pi("base10"),valueToBytes:mi("base10")},{code:53,name:"dns",size:xe},{code:54,name:"dns4",size:xe},{code:55,name:"dns6",size:xe},{code:56,name:"dnsaddr",size:xe},{code:132,name:"sctp",size:16,valueToBytes:Ft,bytesToValue:lr,validate:tn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:xe,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:xe,bytesToValue:pi("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?mi("base58btc")(t):be.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:yi,valueToBytes:cu},{code:445,name:"onion3",size:296,bytesToValue:yi,valueToBytes:uu},{code:446,name:"garlic64",size:xe},{code:447,name:"garlic32",size:xe},{code:448,name:"tls"},{code:449,name:"sni",size:xe},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:xe,bytesToValue:mu(Ho),valueToBytes:pu},{code:480,name:"http"},{code:481,name:"http-path",size:xe,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:xe}];vh.forEach(t=>{ft.addProtocol(t)});function yu(t){let e=[],r=0;for(;r<t.length;){let n=zr(t,r),o=ft.getProtocol(n),s=De(n),i=Sh(o,t,r+s),a=0;i>0&&o.size===xe&&(a=De(i));let c=s+a+i,u={code:n,name:o.name,bytes:_e(t.subarray(r,r+c))};if(i>0){let f=r+s+a,l=t.subarray(f,f+i);u.value=o.bytesToValue?.(l)??H(l)}e.push(u),r+=c}return e}function gu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ft.getProtocol(n.code),s=De(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===xe&&(c=De(a)));let u=new Uint8Array(s+c+a),f=0;nr(n.code,u,f),f+=s,i!=null&&(o.size===xe&&(nr(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Ze(r,e)}function bu(t){if(t.charAt(0)!=="/")throw new Ee('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=ft.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new Ee(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new Ee(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new Ee("Incomplete multiaddr");return e}function wu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ft.getProtocol(e.code);if(r==null)throw new Ee(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Sh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:zr(e,r)}var Ah=Symbol.for("nodejs.util.inspect.custom"),Li=Symbol.for("@multiformats/multiaddr");function Ih(t){if(t==null&&(t="/"),xu(t))return t.getComponents();if(t instanceof Uint8Array)return yu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),bu(t);if(Array.isArray(t))return t;throw new Ee("Must be a string, Uint8Array, Component[], or another Multiaddr")}var fo=class t{[Li]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Ih(e),r.validate!==!1&&_h(this)}get bytes(){return this.#r==null&&(this.#r=gu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=wu(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Jn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return me(this.bytes,e.bytes)}[Ah](){return`Multiaddr(${this.toString()})`}};function _h(t){t.getComponents().forEach(e=>{let r=ft.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function xu(t){return!!t?.[Li]}function nn(t){return new fo(t)}var Eu="libp2p-peer-record",vu=Uint8Array.from([3,1]);var on;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=je((l,p,d={})=>{d.lengthDelimited!==!1&&p.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(p.uint32(10),p.bytes(l.multiaddr)),d.lengthDelimited!==!1&&p.ldelim()},(l,p,d={})=>{let x={multiaddr:we(0)},m=p==null?l.len:l.pos+p;for(;l.pos<m;){let w=l.uint32();w>>>3===1?x.multiaddr=l.bytes():l.skipType(w&7)}return x},function*(l,p,d,x={}){let m=p==null?l.len:l.pos+p;for(;l.pos<m;){let w=l.uint32();w>>>3===1?yield{field:`${d}.multiaddr`,value:l.bytes()}:l.skipType(w&7)}})),a);function c(l){return He(l,i.codec())}i.encode=c;function u(l,p){return ze(l,i.codec(),p)}i.decode=u;function f(l,p){return $e(l,i.codec(),p)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=je((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:we(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Je('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let p=i.uint32();switch(p>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Je('Streaming decode error - repeated field "addresses" had too many elements');for(let d of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...d,index:f.addresses};f.addresses++;break}default:{i.skipType(p&7);break}}}})),r);function n(i){return He(i,t.codec())}t.encode=n;function o(i,a){return ze(i,t.codec(),a)}t.decode=o;function s(i,a){return $e(i,t.codec(),a)}t.stream=s})(on||(on={}));function Su(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var Ye=class t{static createFromProtobuf=e=>{let r=on.decode(e),n=di(Br(r.peerId)),o=(r.addresses??[]).map(i=>nn(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Eu;static CODEC=vu;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=on.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!Su(this.multiaddrs,e.multiaddrs))}};function Bh(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function lo(t){let e=Bh(t);if(e==null)throw new ae(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function Au(t,e,r){let n=0;for(let o of t)if(!(n<e)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Iu(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function Ri(t){switch(t.length){case Mt:return t.join(".");case Kt:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function _u(t){let e=0;for(let[r,n]of t.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<t.length;o++)if(t[o]!=0)return-1;break}return e}function Bu(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Mt=4,Kt=16,mx=parseInt("0xFFFF",16),Th=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function sn(t,e){e.length===Kt&&t.length===Mt&&Au(e,0,11)&&(e=e.slice(12)),e.length===Mt&&t.length===Kt&&Iu(t,Th,0,11)&&(t=t.slice(12));let r=t.length;if(r!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t[o]&e[o];return n}function Tu(t,e){if(typeof e=="string"&&(e=ur(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function Ni(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Mt,o=ro(e);if(o==null&&(n=Kt,o=no(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=ki(s,8*n);return{network:sn(o,i),mask:i}}function ki(t,e){if(e!==8*Mt&&e!==8*Kt)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var an=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Ni(e));else{let n=ur(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=ur(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ki(o,8*n.length);this.network=sn(n,this.mask)}}contains(e){return Tu({network:this.network,mask:this.mask},e)}toString(){let e=_u(this.mask),r=e!==-1?String(e):Bu(this.mask);return Ri(this.network)+"/"+r}};function Cu(t,e){return new an(t).contains(e)}function Ou(t){try{let e=lo(t);return e.type==="ip6"?Cu("2000::/3",e.host):!1}catch{return!1}}var Ru=lf(Lu(),1),Nh=["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"],kh=Nh.map(t=>new Ru.Netmask(t));function zi(t){for(let e of kh)if(e.contains(t))return!0;return!1}function Fh(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function Uh(t){let e=t.split(":");if(e.length<2)return!1;let r=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return zi(o)}function Mh(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function Kh(t){let e=t.split(":"),r=e[e.length-1];return zi(r)}function Vh(t){return/^::$/.test(t)||/^::1$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}function Nu(t){if(fr(t))return zi(t);if(Fh(t))return Uh(t);if(Mh(t))return Kh(t);if(oo(t))return Vh(t)}function ku(t){try{let e=lo(t);switch(e.type){case"ip4":case"ip6":return Nu(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var ee=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),D=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),Fu=t=>({match:e=>t.match(e)===!1?e:!1}),q=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),Ie=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),W=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function te(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var qh=D(421),Yx=te(qh),mo=D(54),yo=D(55),go=D(56),$i=D(53),Wx=te(mo,q(D(421))),Zx=te(yo,q(D(421))),Gx=te(go,q(D(421))),Xx=te(Ie($i,go,mo,yo),q(D(421))),Uu=W(D(4),q(D(43))),Mu=W(q(D(42)),D(41),q(D(43))),ji=Ie(Uu,Mu),wr=Ie(ji,$i,mo,yo,go),Ku=te(Ie(ji,W(Ie($i,go,mo,yo),q(D(421))))),Qx=te(Uu),Jx=te(Mu),e1=te(ji),Yi=W(wr,D(6)),cn=W(wr,D(273)),Vu=te(W(Yi,q(D(421)))),t1=te(cn),Wi=W(cn,ee(460),q(D(421))),bo=W(cn,ee(461),q(D(421))),zh=Ie(Wi,bo),r1=te(Wi),n1=te(bo),Hi=Ie(wr,Yi,cn,Wi,bo),qu=Ie(W(Hi,ee(477),q(D(421)))),o1=te(qu),zu=Ie(W(Hi,ee(478),q(D(421))),W(Hi,ee(448),q(D(449)),ee(477),q(D(421)))),s1=te(zu),Hu=W(cn,ee(280),q(D(466)),q(D(466)),q(D(421))),i1=te(Hu),$u=W(bo,ee(465),q(D(466)),q(D(466)),q(D(421))),a1=te($u),po=Ie(qu,zu,W(Yi,q(D(421))),W(zh,q(D(421))),W(wr,q(D(421))),Hu,$u,D(421)),c1=te(po),Hh=W(q(po),ee(290),Fu(ee(281)),q(D(421))),u1=te(Hh),$h=Ie(W(po,ee(290),ee(281),q(D(421))),W(po,ee(281),q(D(421))),W(ee(281),q(D(421)))),f1=te($h),jh=W(wr,Ie(W(D(6,"80")),W(D(6),ee(480)),ee(480)),q(D(481)),q(D(421))),l1=te(jh),Yh=W(wr,Ie(W(D(6,"443")),W(D(6,"443"),ee(480)),W(D(6),ee(443)),W(D(6),ee(448),ee(480)),W(ee(448),ee(480)),ee(448),ee(443)),q(D(481)),q(D(421))),d1=te(Yh),Wh=Ie(W(D(777),q(D(421)))),h1=te(Wh),Zh=Ie(W(D(400),q(D(421)))),p1=te(Zh);function xr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Zi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},ju=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Gi(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((l,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){p(ju(i)),t.then(l,p);return}if(i&&(c=()=>{p(ju(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,p),r===Number.POSITIVE_INFINITY)return;let d=new Zi;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(x){p(x)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?p(o):(d.message=o??`Promise timed out after ${r} milliseconds`,p(d))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Gh=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Xh(t,e,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:f}=Gh(t),l=async(...d)=>{let x=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(x))return}catch(m){n(),i(m);return}c.push(x),r.count===c.length&&(n(),s(c))},p=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,l);for(let d of r.rejectionEvents)a.includes(d)||f(d,p)};for(let d of a)u(d,l);for(let d of r.rejectionEvents)a.includes(d)||u(d,p);r.signal&&r.signal.addEventListener("abort",()=>{p(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=Gi(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Yu(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Xh(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Wu(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var qt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Qh(t){return t.reason}function Xi(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??Qh;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var ep=4194304,wo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ji=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ea=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ta=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function tp(t){return typeof t?.closeRead=="function"}function rp(t){return typeof t?.close=="function"}function Qi(t){return tp(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:rp(t)?t.status!=="open":!1}function np(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function op(t,e){let r=e?.maxBufferSize??ep,n=new pe,o,s=!1,i;if(!np(t))throw new ae("Argument should be a Stream or a Multiaddr");let a=l=>{if(!s&&i==null){if(n.append(l.data),n.byteLength>r){let p=n.byteLength;n.consume(p);let d=new fn(`Read buffer overflow - ${p} > ${r}`);i=d,o?.reject(d),queueMicrotask(()=>{t.abort(d)});return}o?.resolve()}};t.addEventListener("message",a);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};t.addEventListener("close",c);let u=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(s===!0)throw new wo("Stream was unwrapped");if(i!=null)throw i;if(Qi(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new qt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let p=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=p){o.resolve();break}if(await Xi(o.promise,l?.signal),Qi(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let d=l?.bytes??n.byteLength;if(n.byteLength<d){if(Qi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,d),new qt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return f.read(l)}let x=n.sublist(0,d);return n.consume(d),x},async write(l,p){if(s===!0)throw new wo("Stream was unwrapped");t.send(l)||await Yu(t,"drain",{signal:p?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n),n.consume(n.byteLength))),t}};return f}function sp(t,e={}){let r=op(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=De(e.maxDataLength));let n=e?.lengthDecoder??zr,o=e?.lengthEncoder??or;return{async read(i){let a=-1,c=new pe;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Ji("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ta(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ea(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new qt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new qt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new pe(o(i.byteLength),i),a)},async writeV(i,a){let c=new pe(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function Er(t,e){let r=sp(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function ip(t){return t[Symbol.asyncIterator]!=null}function ap(t){if(ip(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Zu=ap;var xo=globalThis.CustomEvent??Event;async function*ra(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,s=[],i=xr(),a=xr(),c=!1,u,f=!1,l=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of t){if(s.length===r&&(i=xr(),await i.promise),f||l)break;let w={done:!1};s.push(w),m().then(E=>{w.done=!0,w.ok=!0,w.value=E,o.dispatchEvent(new xo("task-complete"))},E=>{w.done=!0,w.err=E,o.dispatchEvent(new xo("task-complete"))})}c=!0,o.dispatchEvent(new xo("task-complete"))}catch(m){u=m,o.dispatchEvent(new xo("task-complete"))}});function p(){return n?s[0]?.done:!!s.find(m=>m.done)}function*d(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw f=!0,i.resolve(),m.err;i.resolve()}}function*x(){for(;p();)for(let m=0;m<s.length;m++)if(s[m].done){let w=s[m];if(s.splice(m,1),m--,w.ok)yield w.value;else throw f=!0,i.resolve(),w.err;i.resolve()}}try{for(;;){if(p()||(a=xr(),await a.promise),u!=null||(n?yield*d():yield*x(),u!=null))throw u;if(c&&s.length===0)break}}finally{l=!0,i.resolve()}}var Gu="0.1.0";var Xu="id/push",Qu="1.0.0",Ju="1.0.0";var At;(function(t){let e;t.codec=()=>(e==null&&(e=je((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.protocolVersion!=null&&(i.uint32(42),i.string(s.protocolVersion)),s.agentVersion!=null&&(i.uint32(50),i.string(s.agentVersion)),s.publicKey!=null&&(i.uint32(10),i.bytes(s.publicKey)),s.listenAddrs!=null&&s.listenAddrs.length>0)for(let c of s.listenAddrs)i.uint32(18),i.bytes(c);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let c of s.protocols)i.uint32(26),i.string(c);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={listenAddrs:[],protocols:[]},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 5:{c.protocolVersion=s.string();break}case 6:{c.agentVersion=s.string();break}case 1:{c.publicKey=s.bytes();break}case 2:{if(a.limits?.listenAddrs!=null&&c.listenAddrs.length===a.limits.listenAddrs)throw new Je('Decode error - repeated field "listenAddrs" had too many elements');c.listenAddrs.push(s.bytes());break}case 4:{c.observedAddr=s.bytes();break}case 3:{if(a.limits?.protocols!=null&&c.protocols.length===a.limits.protocols)throw new Je('Decode error - repeated field "protocols" had too many elements');c.protocols.push(s.string());break}case 8:{c.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u={listenAddrs:0,protocols:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 5:{yield{field:`${a}.protocolVersion`,value:s.string()};break}case 6:{yield{field:`${a}.agentVersion`,value:s.string()};break}case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{if(c.limits?.listenAddrs!=null&&u.listenAddrs===c.limits.listenAddrs)throw new Je('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${a}.listenAddrs[]`,index:u.listenAddrs,value:s.bytes()},u.listenAddrs++;break}case 4:{yield{field:`${a}.observedAddr`,value:s.bytes()};break}case 3:{if(c.limits?.protocols!=null&&u.protocols===c.limits.protocols)throw new Je('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${a}.protocols[]`,index:u.protocols,value:s.string()},u.protocols++;break}case 8:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return He(s,t.codec())}t.encode=r;function n(s,i){return ze(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(At||(At={}));var Pe={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function tf(t){return t.bytes.length===0}function na(t){if(t!=null&&t.length>0)try{let e=nn(t);if(!tf(e))return e}catch{}}async function Eo(t,e,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Me("message was null or undefined");let s={},i=o.listenAddrs.map(na).filter(u=>u!=null);if(o.listenAddrs.length>0&&(s.addresses=i.map(u=>({isCertified:!1,multiaddr:u}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let u=ar(o.publicKey);if(!iu(u).equals(n.remotePeer))throw new Me("public key did not match remote PeerId");s.publicKey=u}let a;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let u=o.signedPeerRecord,f=await tt.openAndCertify(u,Ye.DOMAIN),l=Ye.createFromProtobuf(f.payload),p=Qn(f.publicKey.toCID());if(!l.peerId.equals(p))throw new Me("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(l.peerId))throw new Me("signing key does not match remote PeerId");let d;try{d=await t.get(l.peerId)}catch(m){if(m.name!=="NotFoundError")throw m}if(d!=null&&(s.metadata=d.metadata,d.peerRecordEnvelope!=null)){let m=tt.createFromProtobuf(d.peerRecordEnvelope),w=Ye.createFromProtobuf(m.payload);w.seqNumber>=l.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",w.seqNumber,l.seqNumber),l=w,u=d.peerRecordEnvelope)}s.peerRecordEnvelope=u;let x=l.multiaddrs.filter(m=>!tf(m));s.addresses=x.map(m=>({isCertified:!0,multiaddr:m})),a={seq:l.seqNumber,addresses:x}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,s),await t.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let u={};o.agentVersion!=null&&(u.AgentVersion=V(o.agentVersion)),o.protocolVersion!=null&&(u.ProtocolVersion=V(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,u),await t.merge(n.remotePeer,{metadata:u})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:i,observedAddr:o.observedAddr==null?void 0:nn(o.observedAddr),protocols:o.protocols,signedPeerRecord:a,connection:n};return e.safeDispatchEvent("peer:identify",{detail:c}),c}function vo(t){let e={...t[0]};for(let r of t.slice(1))r.protocolVersion!=null&&(e.protocolVersion=r.protocolVersion),r.agentVersion!=null&&(e.agentVersion=r.agentVersion),r.publicKey!=null&&(e.publicKey=r.publicKey),r.observedAddr!=null&&(e.observedAddr=r.observedAddr),r.signedPeerRecord!=null&&(e.signedPeerRecord=r.signedPeerRecord),e.listenAddrs=[...e.listenAddrs,...r.listenAddrs],e.protocols=[...new Set([...e.protocols,...r.protocols])];return e}async function So(t,e,r,n){let o=Er(t,{maxDataLength:e}).pb(At),s=[];for(let i=0;i<10;i++)try{s.push(await o.read(r))}catch(a){if(s.length===0)throw a;n.trace("stopped reading identify - %e",a);break}s.length>=10&&n("reached MAX_IDENTIFY_MESSAGES, returning truncated identify");try{await t.close(r)}catch(i){n.trace("error closing identify stream after read - %e",i),t.abort(i)}return s}var vr=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;runOnLimitedConnection;log;constructor(e,r){this.protocol=r.protocol,this.started=!1,this.components=e,this.log=r.log,this.timeout=r.timeout??Pe.timeout,this.maxInboundStreams=r.maxInboundStreams??Pe.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Pe.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Pe.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Pe.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Pe.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Pe.protocolPrefix}/${Gu}`,agentVersion:e.nodeInfo.userAgent},this.handleProtocol=this.handleProtocol.bind(this)}isStarted(){return this.started}async start(){this.started||(await this.components.peerStore.merge(this.components.peerId,{metadata:{AgentVersion:V(this.host.agentVersion),ProtocolVersion:V(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 Ao=class extends vr{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Pe.protocolPrefix}/${Xu}/${Ju}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Pe.concurrency,this._push=Wu(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Pe.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[hn]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),r=new Ye({peerId:this.components.peerId,multiaddrs:e}),n=await tt.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")??V(this.host.agentVersion)),a=H(s.metadata.get("ProtocolVersion")??V(this.host.protocolVersion)),c=this;async function*u(){for(let f of c.connectionManager.getConnections())(await c.components.peerStore.get(f.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let p,d=AbortSignal.timeout(c.timeout);try{p=await f.newStream(c.protocol,{signal:d,runOnLimitedConnection:c.runOnLimitedConnection}),await Er(p,{maxDataLength:c.maxMessageSize}).pb(At).write({listenAddrs:e.map(m=>m.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:d}),await p.close({signal:d})}catch(x){p?.log.newScope("identify-push")?.error("could not push identify update to peer",x),p?.abort(x)}})}await Zu(ra(u(),{concurrency:this.concurrency}))}catch(e){this.log.error("error pushing updates to peers - %e",e)}}async handleProtocol(e,r){let n=e.log.newScope("identify-push");if(this.components.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},s=await So(e,this.maxMessageSize,o,n);await Eo(this.components.peerStore,this.components.events,n,r,vo(s)),n.trace("handled push from %p",r.remotePeer)}};var Io=class extends vr{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Pe.protocolPrefix}/${"id"}/${Qu}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Pe.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[hn]=["@libp2p/identify"];async _identify(e,r={}){let n,o;if(r.signal==null){let s=AbortSignal.timeout(this.timeout);r={...r,signal:s}}this.log("run identify on new connection %a",e.remoteAddr);try{n=await e.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=await So(n,this.maxMessageSize,r,o);return vo(s)}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(e,r={}){let n=await this._identify(e,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Me("Public key was missing from identify message");let a=ar(o),c=Qn(a.toCID());if(!e.remotePeer.equals(c))throw new Me("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new Me("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),Eo(this.components.peerStore,this.components.events,this.log,e,n)}maybeAddObservedAddress(e){let r=na(e);if(r==null||(this.log.trace("our observed address was %a",r),ku(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Ou(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Vu.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(e,r){let n=e.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let f=new Ye({peerId:this.components.peerId,multiaddrs:i});a=(await tt.seal(f,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;Ku.matches(r.remoteAddr)||(c=void 0);let u=Er(e).pb(At);n("send response"),await u.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ge(this.components.privateKey.publicKey),listenAddrs:i.map(f=>f.bytes),signedPeerRecord:a,observedAddr:c,protocols:s.protocols},{signal:o}),n("close write"),await u.unwrap().unwrap().close({signal:o})}};function dp(t={}){return e=>new Io(e,t)}function hp(t={}){return e=>new Ao(e,t)}return df(pp);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|