@libp2p/identify 4.1.12-d5534174d → 4.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +2 -2
- package/dist/typedoc-urls.json +18 -0
- package/package.json +8 -8
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PIdentify = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PIdentify=(()=>{var of=Object.create;var cn=Object.defineProperty;var sf=Object.getOwnPropertyDescriptor;var af=Object.getOwnPropertyNames;var cf=Object.getPrototypeOf,uf=Object.prototype.hasOwnProperty;var Io=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Se=(t,e)=>{for(var r in e)cn(t,r,{get:e[r],enumerable:!0})},oa=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of af(e))!uf.call(t,o)&&o!==r&&cn(t,o,{get:()=>e[o],enumerable:!(n=sf(e,o))||n.enumerable});return t};var ff=(t,e,r)=>(r=t!=null?of(cf(t)):{},oa(e||!t||!t.__esModule?cn(r,"default",{value:t,enumerable:!0}):r,t)),lf=t=>oa(cn({},"__esModule",{value:!0}),t);var Fi=Io(yr=>{"use strict";Object.defineProperty(yr,"__esModule",{value:!0});yr.Netmask4Impl=void 0;yr.ip2long=mr;yr.long2ip=Je;function Je(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 _h=48,Ch=97,Th=65;function Oh(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)-_h)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-Ch)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-Th)>>>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 mr(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]=Oh(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 ki=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=mr(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=(mr(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=Je(this.netLong),this.mask=Je(this.maskLong),this.hostmask=Je(~this.maskLong),this.first=this.bitmask<=30?Je(this.netLong+1):this.base,this.last=this.bitmask<=30?Je(this.netLong+this.size-2):Je(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Je(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):(mr(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(Je(this.netLong+this.size*e),this.mask)}forEach(e){let r=mr(this.first),n=mr(this.last),o=0;for(;r<=n;)e(Je(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};yr.Netmask4Impl=ki});var Du=Io(gr=>{"use strict";Object.defineProperty(gr,"__esModule",{value:!0});gr.Netmask6Impl=void 0;gr.ip6bigint=Mi;gr.bigint2ip6=Mt;var Dh=Fi(),Ui=(1n<<128n)-1n;function Mi(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,Dh.ip2long)(n),s=t.substring(0,r+1)+"0:0";return Ou(s)&~0xffffffffn|BigInt(o)}return Ou(t)}function Ou(t){let e=t.indexOf("::"),r;if(e!==-1){let o=t.substring(0,e),s=t.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(c).fill("0"),...a]}else r=t.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Mt(t){if(t<0n||t>Ui)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 Ki=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=Ui>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Mi(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Mt(this.netBigint),this.mask=Mt(this.maskBigint),this.hostmask=Mt(~this.maskBigint&Ui),this.first=this.base,this.last=Mt(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.last):(Mi(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Mt(this.netBigint+r*BigInt(e)),this.bitmask)}forEach(e){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)e(Mt(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};gr.Netmask6Impl=Ki});var Pu=Io(Et=>{"use strict";Object.defineProperty(Et,"__esModule",{value:!0});Et.long2ip=Et.ip2long=Et.Netmask=void 0;var fo=Fi();Object.defineProperty(Et,"ip2long",{enumerable:!0,get:function(){return fo.ip2long}});Object.defineProperty(Et,"long2ip",{enumerable:!0,get:function(){return fo.long2ip}});var Ph=Du(),Vi=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 Ph.Netmask6Impl(e,r):this._impl=new fo.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 fo.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()}};Et.Netmask=Vi});var dp={};Se(dp,{identify:()=>fp,identifyPush:()=>lp});var re=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},qt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var un=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},fn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Re=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var St=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Bo=Symbol.for("@libp2p/peer-id");var ln=Symbol.for("@libp2p/service-capabilities");var Do={};Se(Do,{base58btc:()=>ce,base58flickr:()=>xf});var Vp=new Uint8Array(0);function ia(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 Oe(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return At(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return At(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function aa(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var sa=4096;function ca(t){let e=t.length;if(e<=sa)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=sa));return r}function df(t){return t?.buffer instanceof ArrayBuffer}function At(t){return df(t)?t:t.slice()}function hf(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),h=Math.log(f)/Math.log(256),d=Math.log(256)/Math.log(f);function E(v){if(v instanceof Uint8Array||(ArrayBuffer.isView(v)?v=new Uint8Array(v.buffer,v.byteOffset,v.byteLength):Array.isArray(v)&&(v=Uint8Array.from(v))),!(v instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(v.length===0)return"";for(var I=0,g=0,B=0,_=v.length;B!==_&&v[B]===0;)B++,I++;for(var M=(_-B)*d+1>>>0,K=new Uint8Array(M);B!==_;){for(var k=v[B],R=0,N=M-1;(k!==0||R<g)&&N!==-1;N--,R++)k+=256*K[N]>>>0,K[N]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");g=R,B++}for(var z=M-g;z!==M&&K[z]===0;)z++;for(var D=l.repeat(I);z<M;++z)D+=t.charAt(K[z]);return D}function y(v){if(typeof v!="string")throw new TypeError("Expected String");if(v.length===0)return new Uint8Array;var I=0;if(v[I]!==" "){for(var g=0,B=0;v[I]===l;)g++,I++;for(var _=(v.length-I)*h+1>>>0,M=new Uint8Array(_);v[I];){var K=n[v.charCodeAt(I)];if(K===255)return;for(var k=0,R=_-1;(K!==0||k<B)&&R!==-1;R--,k++)K+=f*M[R]>>>0,M[R]=K%256>>>0,K=K/256>>>0;if(K!==0)throw new Error("Non-zero carry");B=k,I++}if(v[I]!==" "){for(var N=_-B;N!==_&&M[N]===0;)N++;for(var z=new Uint8Array(g+(_-N)),D=g;N!==_;)z[D++]=M[N++];return z}}}function x(v){var I=y(v);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:y,decode:x}}var pf=hf,mf=pf,fa=mf;var _o=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")}},Co=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 la(this,e)}},To=class{decoders;constructor(e){this.decoders=e}or(e){return la(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 la(t,e){return new To({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Oo=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 _o(e,r,n),this.decoder=new Co(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function zt({name:t,prefix:e,encode:r,decode:n}){return new Oo(t,e,r,n)}function ct({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=fa(r,t,n);return zt({prefix:e,name:t,encode:o,decode:i=>Oe(s(i))})}function yf(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 gf(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 bf(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 ae({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=bf(n,o);return zt({prefix:e,name:t,encode(i){return gf(i,n,r)},decode(i){return yf(i,s,r,t)}})}var ce=ct({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xf=ct({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Po={};Se(Po,{base32:()=>ut,base32hex:()=>Sf,base32hexpad:()=>If,base32hexpadupper:()=>Bf,base32hexupper:()=>Af,base32pad:()=>Ef,base32padupper:()=>vf,base32upper:()=>wf,base32z:()=>_f});var ut=ae({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),wf=ae({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Ef=ae({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),vf=ae({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Sf=ae({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Af=ae({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),If=ae({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Bf=ae({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),_f=ae({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Lo={};Se(Lo,{base36:()=>Ar,base36upper:()=>Cf});var Ar=ct({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Cf=ct({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Tf=pa,da=128,Of=127,Df=~Of,Pf=Math.pow(2,31);function pa(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Pf;)e[r++]=t&255|da,t/=128;for(;t&Df;)e[r++]=t&255|da,t>>>=7;return e[r]=t|0,pa.bytes=r-n+1,e}var Lf=Ro,Rf=128,ha=127;function Ro(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Ro.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&ha)<<o:(i&ha)*Math.pow(2,o),o+=7}while(i>=Rf);return Ro.bytes=s-n,r}var Nf=Math.pow(2,7),kf=Math.pow(2,14),Ff=Math.pow(2,21),Uf=Math.pow(2,28),Mf=Math.pow(2,35),Kf=Math.pow(2,42),Vf=Math.pow(2,49),qf=Math.pow(2,56),zf=Math.pow(2,63),Hf=function(t){return t<Nf?1:t<kf?2:t<Ff?3:t<Uf?4:t<Mf?5:t<Kf?6:t<Vf?7:t<qf?8:t<zf?9:10},$f={encode:Tf,decode:Lf,encodingLength:Hf},jf=$f,Ir=jf;function Br(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 Ht(t,e,r=0){return Ir.encode(t,e,r),e}function $t(t){return Ir.encodingLength(t)}function $e(t,e){let r=e.byteLength,n=$t(t),o=n+$t(r),s=new Uint8Array(o+r);return Ht(t,s,0),Ht(r,s,n),s.set(e,o),new jt(t,r,e,s)}function _r(t){let e=Oe(t),[r,n]=Br(e),[o,s]=Br(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new jt(r,o,i,e)}function ma(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ia(t.bytes,r.bytes)}}var jt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=At(n),this.bytes=At(o)}};function ya(t,e){let{bytes:r,version:n}=t;return n===0?Wf(r,No(t),e??ce.encoder):Zf(r,No(t),e??ut.encoder)}var ga=new WeakMap;function No(t){let e=ga.get(t);if(e==null){let r=new Map;return ga.set(t,r),r}return e}var de=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=At(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!==Cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Gf)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=$e(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&&ma(e.multihash,n.multihash)}toString(e){return ya(this,e)}toJSON(){return{"/":ya(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??ba(n,o,s.bytes))}else if(r[Xf]===!0){let{version:n,multihash:o,code:s}=r,i=_r(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!==Cr)throw new Error(`Version 0 CID must use dag-pb (code: ${Cr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ba(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Cr,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=Oe(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new jt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Br(e.subarray(r));return r+=h,l},o=n(),s=Cr;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]=Yf(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 No(s).set(n,e),s}};function Yf(t,e){switch(t[0]){case"Q":{let r=e??ce;return[ce.prefix,r.decode(`${ce.prefix}${t}`)]}case ce.prefix:{let r=e??ce;return[ce.prefix,r.decode(t)]}case ut.prefix:{let r=e??ut;return[ut.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 Wf(t,e,r){let{prefix:n}=r;if(n!==ce.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 Zf(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 Cr=112,Gf=18;function ba(t,e,r){let n=$t(t),o=n+$t(e),s=new Uint8Array(o+r.byteLength);return Ht(t,s,0),Ht(e,s,n),s.set(r,o),s}var Xf=Symbol.for("@ipld/js-cid/CID");var ko={};Se(ko,{identity:()=>Ne});var xa=0,Qf="identity",wa=Oe;function Jf(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 $e(xa,wa(t))}var Ne={code:xa,name:Qf,encode:wa,digest:Jf};function fe(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 el(t){return t.buffer instanceof ArrayBuffer}function ve(t){return el(t)?t:t.slice()}async function Ea(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,ve(e),ve(r.subarray()));return n?.signal?.throwIfAborted(),s}function he(t=0){return new Uint8Array(t)}function ge(t=0){return new Uint8Array(t)}function tl(t){return t?.buffer instanceof ArrayBuffer}function Fo(t){if(tl(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function je(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=ge(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Fo(r)}var Sa=Symbol.for("@achingbrain/uint8arraylist");function va(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 hn(t){return!!t?.[Sa]}var ue=class t{bufs;length;[Sa]=!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(hn(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(hn(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=va(this.bufs,e);return r.buf[r.index]}set(e,r){let n=va(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(hn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return je(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:je(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!hn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let d=this.get(l+h);if(n[h]!==d){f=Math.max(1,h-a[d]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=ge(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=he(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=he(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=he(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=ge(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=he(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=he(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=he(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=he(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=he(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(!fe(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 Uo={};Se(Uo,{base10:()=>rl});var rl=ct({prefix:"9",name:"base10",alphabet:"0123456789"});var Mo={};Se(Mo,{base16:()=>nl,base16upper:()=>ol});var nl=ae({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),ol=ae({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Ko={};Se(Ko,{base2:()=>sl});var sl=ae({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Vo={};Se(Vo,{base256emoji:()=>fl});var Aa=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}"),il=Aa.reduce((t,e,r)=>(t[r]=e,t),[]),al=Aa.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function cl(t){return t.reduce((e,r)=>(e+=il[r],e),"")}function ul(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=al[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var fl=zt({prefix:"\u{1F680}",name:"base256emoji",encode:cl,decode:ul});var zo={};Se(zo,{base64:()=>ll,base64pad:()=>dl,base64url:()=>qo,base64urlpad:()=>hl});var ll=ae({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),dl=ae({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qo=ae({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),hl=ae({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ho={};Se(Ho,{base8:()=>pl});var pl=ae({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $o={};Se($o,{identity:()=>ml});var ml=zt({prefix:"\0",name:"identity",encode:t=>ca(Oe(t)),decode:t=>Oe(aa(t))});var Bm=new TextEncoder,_m=new TextDecoder;var Wo={};Se(Wo,{sha256:()=>Tr,sha512:()=>xl});var bl=20;function Yo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new jo(t,e,r,n,o)}var jo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??bl,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?Ia(n,this.code,r?.truncate):n.then(o=>Ia(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ia(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 $e(e,t)}function _a(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Tr=Yo({name:"sha2-256",code:18,encode:_a("SHA-256")}),xl=Yo({name:"sha2-512",code:19,encode:_a("SHA-512")});var Or={...$o,...Ko,...Ho,...Uo,...Mo,...Po,...Lo,...Do,...zo,...Vo},Mm={...Wo,...ko};function Ta(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ca=Ta("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Zo=Ta("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=ge(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),wl={utf8:Ca,"utf-8":Ca,hex:Or.base16,latin1:Zo,ascii:Zo,binary:Zo,...Or},pn=wl;function V(t,e="utf8"){let r=pn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function H(t,e="utf8"){let r=pn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var El=parseInt("11111",2),Go=parseInt("10000000",2),vl=parseInt("01111111",2),Oa={0:Dr,1:Dr,2:Sl,3:Bl,4:_l,5:Il,6:Al,16:Dr,22:Dr,48:Dr};function et(t,e={offset:0}){let r=t[e.offset]&El;if(e.offset++,Oa[r]!=null)return Oa[r](t,e);throw new Error("No decoder for tag "+r)}function Pr(t,e){let r=0;if((t[e.offset]&Go)===Go){let n=t[e.offset]&vl,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=et(t,e);if(n===null)break;r.push(n)}return r}function Sl(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 Al(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 Il(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 _l(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 ue;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Xo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Cl(t.byteLength);return new ue(Uint8Array.from([e.byteLength|Go]),e)}function Ae(t){let e=new ue,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ue(Uint8Array.from([2]),Xo(e),e)}function mn(t){let e=Uint8Array.from([0]),r=new ue(e,t);return new ue(Uint8Array.from([3]),Xo(r),r)}function ft(t,e=48){let r=new ue;for(let n of t)r.append(n);return new ue(Uint8Array.from([e]),Xo(r),r)}var Tl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ol=Uint8Array.from([6,5,43,129,4,0,34]),Dl=Uint8Array.from([6,5,43,129,4,0,35]),Pl={ext:!0,kty:"EC",crv:"P-256"},Ll={ext:!0,kty:"EC",crv:"P-384"},Rl={ext:!0,kty:"EC",crv:"P-521"},Qo=32,Jo=48,es=66;function ts(t){let e=et(t);return Da(e)}function Da(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Qo*2+1)return n=H(e.subarray(r,r+Qo),"base64url"),o=H(e.subarray(r+Qo),"base64url"),new Yt({...Pl,key_ops:["verify"],x:n,y:o});if(e.byteLength===Jo*2+1)return n=H(e.subarray(r,r+Jo),"base64url"),o=H(e.subarray(r+Jo),"base64url"),new Yt({...Ll,key_ops:["verify"],x:n,y:o});if(e.byteLength===es*2+1)return n=H(e.subarray(r,r+es),"base64url"),o=H(e.subarray(r+es),"base64url"),new Yt({...Rl,key_ops:["verify"],x:n,y:o});throw new re(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Pa(t){return ft([Ae(Uint8Array.from([1])),ft([Nl(t.crv)],160),ft([mn(new ue(Uint8Array.from([4]),V(t.x??"","base64url"),V(t.y??"","base64url")))],161)]).subarray()}function Nl(t){if(t==="P-256")return Tl;if(t==="P-384")return Ol;if(t==="P-521")return Dl;throw new re(`Invalid curve ${t}`)}var Yt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Pa(this.jwk)),this._raw}toMultihash(){return Ne.digest(Ye(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return ce.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}async verify(e,r,n){return Ea(this.jwk,r,e,n)}};var yn=BigInt(4294967295),La=BigInt(32);function kl(t,e=!1){return e?{h:Number(t&yn),l:Number(t>>La&yn)}:{h:Number(t>>La&yn)|0,l:Number(t&yn)|0}}function Ra(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}=kl(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Fl=t=>t/2**32|0,Ul=t=>t>>>0;function Na(t,e,r,n){let o=Fl(r),s=Ul(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var rs=(t,e,r)=>t>>>r,ns=(t,e,r)=>t<<32-r|e>>>r,Bt=(t,e,r)=>t>>>r|e<<32-r,_t=(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 We(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var ka=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Fa=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Ua=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ma=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Ka=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Va=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function gn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var os=t=>t?`"${t}" `:"";function tt(t,e=""){if(typeof t!="number")throw new TypeError(os(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(os(e)+"expected integer >= 0, got "+t);return t}function De(t,e,r=""){if(gn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&tt(e,"length");let n=gn(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=os(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function bn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(tt(t.outputLen),tt(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var qa=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};function Wt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function xn(t,e){De(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ct(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function wn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function ke(t,e){return t<<32-e|t>>>e}var Ha=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Kl=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function En(t){if(De(t),Ha)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Kl[t[r]];return e}function za(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function vn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Ha)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=za(t.charCodeAt(s)),a=za(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 ss(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];De(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 Vl(t,e,r="opts"){return qa(t,"defaults"),e!==void 0&&qa(e,r),Object.assign(t,e)}function is(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Vl({},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 $a(t=32){tt(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 as=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function ja(t,e,r){return t&e^~t&r}function Ya(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=wn(this.buffer)}update(e){Wt(this),De(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=wn(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){Wt(this),xn(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)),Na(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:wn(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()}},Wa=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Za=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var ql=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]),lt=new Uint32Array(64),cs=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)lt[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=lt[l-15],d=lt[l-2],E=ke(h,7)^ke(h,18)^h>>>3,y=ke(d,17)^ke(d,19)^d>>>10;lt[l]=y+lt[l-7]+E+lt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=ke(a,6)^ke(a,11)^ke(a,25),d=f+h+ja(a,c,u)+ql[l]+lt[l]|0,y=(ke(n,2)^ke(n,13)^ke(n,22))+Ya(n,o,s)|0;f=u,u=c,c=a,a=i+d|0,i=s,s=o,o=n,n=d+y|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(){Ct(lt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ct(this.buffer)}},us=class extends cs{constructor(){super(32,Wa)}};var Ga=Ra(["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))),zl=Ga[0],Hl=Ga[1],dt=new Uint32Array(80),ht=new Uint32Array(80),fs=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:h,Gh:d,Gl:E,Hh:y,Hl:x}=this;return[e,r,n,o,s,i,a,c,u,f,l,h,d,E,y,x]}set(e,r,n,o,s,i,a,c,u,f,l,h,d,E,y,x){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=E|0,this.Hh=y|0,this.Hl=x|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)dt[g]=e.getUint32(r),ht[g]=e.getUint32(r+=4);for(let g=16;g<80;g++){let B=dt[g-15]|0,_=ht[g-15]|0,M=Bt(B,_,1)^Bt(B,_,8)^rs(B,_,7),K=_t(B,_,1)^_t(B,_,8)^ns(B,_,7),k=dt[g-2]|0,R=ht[g-2]|0,N=Bt(k,R,19)^Lr(k,R,61)^rs(k,R,6),z=_t(k,R,19)^Rr(k,R,61)^ns(k,R,6),D=Ua(K,z,ht[g-7],ht[g-16]),ee=Ma(D,M,N,dt[g-7],dt[g-16]);dt[g]=ee|0,ht[g]=D|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:d,Fl:E,Gh:y,Gl:x,Hh:v,Hl:I}=this;for(let g=0;g<80;g++){let B=Bt(l,h,14)^Bt(l,h,18)^Lr(l,h,41),_=_t(l,h,14)^_t(l,h,18)^Rr(l,h,41),M=l&d^~l&y,K=h&E^~h&x,k=Ka(I,_,K,Hl[g],ht[g]),R=Va(k,v,B,M,zl[g],dt[g]),N=k|0,z=Bt(n,o,28)^Lr(n,o,34)^Lr(n,o,39),D=_t(n,o,28)^Rr(n,o,34)^Rr(n,o,39),ee=n&s^n&a^s&a,O=o&i^o&c^i&c;v=y|0,I=x|0,y=d|0,x=E|0,d=l|0,E=h|0,{h:l,l:h}=We(u|0,f|0,R|0,N|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let T=ka(N,D,O);n=Fa(T,R,z,ee),o=T|0}({h:n,l:o}=We(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=We(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=We(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=We(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=We(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:E}=We(this.Fh|0,this.Fl|0,d|0,E|0),{h:y,l:x}=We(this.Gh|0,this.Gl|0,y|0,x|0),{h:v,l:I}=We(this.Hh|0,this.Hl|0,v|0,I|0),this.set(n,o,s,i,a,c,u,f,l,h,d,E,y,x,v,I)}roundClean(){Ct(dt,ht)}destroy(){this.destroyed=!0,Ct(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ls=class extends fs{constructor(){super(64,Za)}};var Zt=is(()=>new us,as(1));var ds=is(()=>new ls,as(3));function An(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 Z=(t,e,r)=>De(t,e,r),hs=tt;function Qa(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function pt(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 Tt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var kr=En,Pe=(...t)=>ss(...t),Gt=t=>vn(t),yt=gn,Ot=t=>$a(t),Sn=BigInt(0),Xa=BigInt(1),$l=t=>t?`"${t}" `:"";function Ie(t,e=""){if(typeof t!="boolean")throw new TypeError($l(e)+"expected boolean, got type="+typeof t);return t}function In(t){if(typeof t=="bigint"){if(!mt(t))throw new RangeError("positive bigint expected, got "+t)}else hs(t);return t}function gt(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=In(t).toString(16);return e.length&1?"0"+e:e}function Ja(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Sn:BigInt("0x"+t)}function Ze(t){return Ja(En(t))}function Dt(t){return Ja(En(_n(De(t)).reverse()))}function Bn(t,e){if(tt(e),e===0)throw new Error("zero output length is invalid");t=In(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return vn(n.padStart(r,"0"))}function ps(t,e){return Bn(t,e).reverse()}function _n(t){return Uint8Array.from(Z(t))}function mt(t){return typeof t=="bigint"&&Sn<=t}function ms(t,e,r){return mt(t)&&mt(e)&&mt(r)&&e<=t&&t<r}function Xt(t,e,r,n){if(!ms(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Qt(t){if(t<Sn)throw new Error("expected non-negative bigint, got "+t);return t===Sn?0:t.toString(2).length}var Ur=t=>(gt(t,"n"),(Xa<<BigInt(t))-Xa);function ec(t,e,r){if(tt(t,"hashLen"),tt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=x=>new Uint8Array(x),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...x)=>r(u,Pe(c,...x)),d=(x=o)=>{u=h(s,x),c=h(),x.length!==0&&(u=h(i,x),c=h())},E=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let x=0,v=[];for(;x<e;){c=h();let I=c.slice();v.push(I),x+=c.length}return Pe(...v)};return(x,v)=>{l(),d(x);let I;for(;(I=v(E()))===void 0;)d();return l(),I}}function Be(t,e={},r={},n="object"){pt(t,n),pt(e,"fields"),pt(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 le=BigInt(0),G=BigInt(1),bt=BigInt(2),nc=BigInt(3),ys=BigInt(4),oc=BigInt(5),jl=BigInt(7),sc=BigInt(8),Yl=BigInt(9),Wl=BigInt(15),ic=BigInt(16),Zl=BigInt("0x10000000000000000");function ne(t,e){if(e<=le)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=le?r:e+r}function ac(t,e,r){if(r<=G)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<le)throw new Error("invalid exponent, negatives unsupported");if(e===le)return G;if(e===G)return t;let n=t%r;if(n<le&&(n+=r),e<Zl){let a=G;for(;e>le;)e&G&&(a=a*n%r),n=n*n%r,e>>=G;return a}let o=[];for(;e>le;)o.push(Number(e&Wl)),e>>=ys;let s=new Array(16);s[0]=G,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 te(t,e,r){if(r<=G)throw new Error("pow2: expected modulus > 1, got "+r);if(e<le)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >le;)n*=n,n%=r;return n}function tc(t,e){if(t===le)throw new Error("invert: expected non-zero number");if(e<=G)throw new Error("invert: expected modulus > 1, got "+e);let r=ne(t,e),n=e,o=le,s=G;for(;r!==le;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==G)throw new Error("invert: does not exist");return ne(o,e)}function cc(t,e){if(e<=G)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ne(t,e);if(r===le)throw new Error("invertCt: expected non-zero number");let n=ac(r,e-bt,e);if(ne(r*n,e)!==G)throw new Error("invertCt: does not exist");return n}function gs(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function bs(t,e){if((t&G)===le)throw new Error(e+": expected odd modulus, got "+t)}function uc(t,e){let r=t,n=(r.ORDER+G)/ys,o=r.pow(e,n);return gs(r,o,e),o}function Gl(t,e){let r=t,n=(r.ORDER-oc)/sc,o=r.mul(e,bt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,bt),s),c=r.mul(i,r.sub(a,r.ONE));return gs(r,c,e),c}function Xl(t){let e=er(t),r=fc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+jl)/ic;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),h=u.mul(f,o),d=u.mul(f,s),E=u.eql(u.sqr(l),c),y=u.eql(u.sqr(h),c);f=u.cmov(f,l,E),l=u.cmov(d,h,y);let x=u.eql(u.sqr(l),c),v=u.cmov(f,l,x);return gs(u,v,c),v})}function fc(t){if(t<nc)throw new Error("sqrt is not defined for small field");bs(t,"tonelliShanks");let e=t-G,r=0;for(;e%bt===le;)e/=bt,r++;let n=bt,o=er(t);for(;Mr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return uc;let s=o.pow(n,e),i=(e+G)/bt;return function(c,u){let f=c;if(f.is0(u))return u;if(Mr(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,s),d=f.pow(u,e),E=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 y=1,x=f.sqr(d);for(;!f.eql(x,f.ONE);)if(y++,x=f.sqr(x),y===l)throw new Error("Cannot find square root");let v=G<<BigInt(l-y-1),I=f.pow(h,v);l=y,h=f.sqr(I),d=f.mul(d,h),E=f.mul(E,I)}return E}}function Ql(t){return bs(t,"Fp.sqrt"),t%ys===nc?uc:t%sc===oc?Gl:t%ic===Yl?Xl(t):fc(t)}var lc=(t,e)=>(ne(t,e)&G)===G,Jl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jt(t){if(pt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);gt(t.BYTES,"BYTES"),gt(t.BITS,"BITS");for(let e of Jl)Tt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=G)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Tn(t,e,r=!1){Jt(t),An(e,"nums"),Ie(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 Mr(t,e){Jt(t);let r=t;bs(r.ORDER,"FpLegendre");let n=(r.ORDER-G)/bt,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 ed(t,e){if(e!==void 0&&hs(e),t<=le)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=Qt(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 rc=new WeakMap,Cn=class{ORDER;BITS;BYTES;isLE;ZERO=le;ONE=G;_lengths;_mod;constructor(e,r={}){if(e<=G)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}=ed(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 ne(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return le<=e&&e<this.ORDER}is0(e){return e===le}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&G)===G}neg(e){return ne(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ne(e*e,this.ORDER)}add(e,r){return ne(e+r,this.ORDER)}sub(e,r){return ne(e-r,this.ORDER)}mul(e,r){return ne(e*r,this.ORDER)}pow(e,r){return ac(e,r,this.ORDER)}div(e,r){return ne(e*tc(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 tc(e,this.ORDER)}sqrt(e){let r=rc.get(this);return r||rc.set(this,r=Ql(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?ps(e,this.BYTES):Bn(e,this.BYTES)}fromBytes(e,r=!1){Z(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?Dt(e):Ze(e);if(a&&(c=ne(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Tn(this,e,!0)}cmov(e,r,n){return Ie(n,"condition"),n?r:e}};function er(t,e={}){return Object.freeze(Cn.prototype),new Cn(t,e)}function dc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=G)throw new Error("field order must be greater than 1");let e=Qt(t-G);return Math.ceil(e/8)}function On(t){let e=dc(t);return e+Math.ceil(e/2)}function Dn(t,e,r=!1){Z(t);let n=t.length,o=dc(e),s=Math.max(On(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Dt(t):Ze(t),a=ne(i,e-G)+G;return r?ps(a,o):Bn(a,o)}var Es=BigInt(0),Kr=BigInt(1),td=BigInt(4),xs=16,hc=128,rd=5,pc=2**31;function xt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Tt(e.fromAffine,"Point.fromAffine"),Tt(e.fromBytes,"Point.fromBytes"),Tt(e.fromHex,"Point.fromHex"),pt(e.BASE,"Point.BASE"),pt(e.ZERO,"Point.ZERO"),Jt(e.Fp),Jt(e.Fn)}function Pn(t,e){xt(t),yc(e,t);let r=Tn(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function nd(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 od(t,e){let r=t*(4*e+128);if(r>pc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+pc/2**20+" MiB")}function vs(t,e){if(t!==void 0){Tt(t,"randomBytes");try{let r=t(e);if(!yt(r)||r.length!==e)return}catch{return}return t}}function yc(t,e){An(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function sd(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):mt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var gc=new WeakMap;function ws(t){return gc.get(t)||1}function id(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 ad(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>Es;){let i=0;t&Kr&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=Kr}return s}function cd(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+=Kr),a.push(u)}if(t!==Es)throw new Error("invalid wnaf");return a}function ud(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 tr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){xt(e),this.randomBytes=vs(r,xs),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=cd(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],h=f*i,d=Math.abs(l)-1,E=s[h];for(let x=1;x<i;x++)E=x===d?s[h+x]:E;let y=E.negate();l===0?u=u.add(s[h]):c=c.add(l<0?y:E)}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),!ms(r,Kr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=ws(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+hc,s=this.randomBytes(xs);if(!yt(s)||s.length!==xs)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Ze(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=rd,s=1<<o,i=Ur(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),h=a[0];for(let d=1;d<s;d++)h=d===l?a[d]:h;u=u.add(h)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Kr?!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),!mt(r))throw new Error("invalid scalar");let o=ws(e);if(o===1||r>=this.Point.Fn.ORDER)return Ln(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),nd(r,this.bits);let n=Math.ceil((this.bits+hc)/r)+1;od(n*2**(r-1),this.Point.Fp.BYTES),gc.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return ws(e)!==1}};function Ln(t,e,r,n=!1){if(xt(t),yc(e,t),Ie(n,"allowOversized"),sd(r,t.Fn,n?t.Fn.ORDER**td:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>id(i,4)),s=r.map(i=>ad(i,4));return ud(t.ZERO,o,s)}function mc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Jt(e),e}else return er(t,{isLE:r})}function Rn(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`);Be(r);for(let c of["p","n","h"]){let u=e[c];if(!(mt(u)&&u!==Es))throw new Error(`CURVE.${c} must be positive bigint`)}let o=mc(e.p,r.Fp,n),s=mc(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 Nn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var kn=BigInt(0),Fn=BigInt(1),Un=BigInt(2),fd=BigInt(4),bc=BigInt(8);function ld(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={}){Be(e,{},{},"extraOpts");let r=e,n=Rn("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(Mr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Mr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Be(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Ot:r.randomBytes,u=Un<<BigInt(o.BYTES*8)-Fn;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:kn}}}:r.uvRatio;if(!ld(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let h=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,B=!1){let _=B?Fn:kn;return Xt("coordinate "+I,g,_,u),g}function E(I){if(!(I instanceof y))throw new Error("EdwardsPoint expected")}class y{static BASE=new y(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new y(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(g,B,_,M){this.X=d("x",g),this.Y=d("y",B),this.Z=d("z",_,!0),this.T=d("t",M),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof y)throw new Error("extended point not allowed");let{x:B,y:_}=g||{};return d("x",B),d("y",_),new y(B,_,o.ONE,o.mul(B,_))}static fromBytes(g,B=!1){let _=o.BYTES,{a:M,d:K}=i;g=_n(Z(g,_,"point")),Ie(B,"zip215");let k=_n(g),R=g[_-1];k[_-1]=R&-129;let N=Dt(k),z=B?u:o.ORDER;Xt("point.y",N,kn,z);let D=o.sqr(N),ee=o.sub(D,o.ONE),O=o.sub(o.mulN(K,D),M),{isValid:T,value:p}=l(ee,O);if(!T)throw new Error("bad point: invalid y coordinate");let b=f(p),S=(R&128)!==0;if(!B&&o.is0(p)&&S)throw new Error("bad point: x=0 and x_0=1");return S!==b&&(p=o.neg(p)),y.fromAffine({x:p,y:N})}static fromHex(g,B=!1){return y.fromBytes(Gt(g),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=6,B=!0){return v.setWindowSize(this,g),B||this.multiply(Un),this}assertValidity(){let g=this,{a:B,d:_}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:M,Y:K,Z:k,T:R}=g,N=o.sqr(M),z=o.sqr(K),D=o.sqr(k),ee=o.sqr(D),O=o.mul(N,B),T=o.mul(o.add(O,z),D),p=o.add(ee,o.mul(_,o.mul(N,z)));if(!o.eql(T,p))throw new Error("bad point: equation left != right (1)");let b=o.mul(M,K),S=o.mul(k,R);if(!o.eql(b,S))throw new Error("bad point: equation left != right (2)")}equals(g){E(g);let{X:B,Y:_,Z:M}=this,{X:K,Y:k,Z:R}=g,N=o.mul(B,R),z=o.mul(K,M),D=o.mul(_,R),ee=o.mul(k,M);return o.eql(N,z)&&o.eql(D,ee)}is0(){return this.equals(y.ZERO)}negate(){return new y(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:g,Y:B,Z:_}=this,M=o.sqr(g),K=o.sqr(B),k=o.mul(o.sqr(_),Un),R=h(M),N=o.addN(g,B),z=o.sub(o.subN(o.sqr(N),M),K),D=o.addN(R,K),ee=o.subN(D,k),O=o.subN(R,K),T=o.mul(z,ee),p=o.mul(D,O),b=o.mul(z,O),S=o.mul(ee,D);return new y(T,p,S,b)}add(g){E(g);let{d:B}=i,{X:_,Y:M,Z:K,T:k}=this,{X:R,Y:N,Z:z,T:D}=g,ee=o.mul(_,R),O=o.mul(M,N),T=o.mul(o.mulN(k,B),D),p=o.mul(K,z),b=o.sub(o.subN(o.mulN(o.addN(_,M),o.addN(R,N)),ee),O),S=o.subN(p,T),P=o.addN(p,T),w=o.sub(O,h(ee)),m=o.mul(b,S),A=o.mul(P,w),C=o.mul(b,w),F=o.mul(S,P);return new y(m,A,F,C)}subtract(g){return E(g),this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:_}=v.mulSecret(this,g,a,x);return x([B,_])[0]}multiplyUnsafe(g){if(!s.isValid(g))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return g===kn?y.ZERO:this.is0()||g===Fn?this:v.mulUnsafe(this,g,x)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return v.mulUnsafe(this,i.n).is0()}toAffine(g){let B=this,_=g;if(_!=null&&typeof _!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof _);let{X:M,Y:K,Z:k}=B,R=B.is0();_==null&&(_=R?o.create(bc):o.inv(k));let N=o.mul(M,_),z=o.mul(K,_),D=o.mul(k,_);if(R)return{x:o.ZERO,y:o.ONE};if(!o.eql(D,o.ONE))throw new Error("invZ was invalid");return{x:N,y:z}}clearCofactor(){return a===Fn?this:a===Un?this.double():a===fd?this.double().double():a===bc?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:g,y:B}=this.toAffine(),_=o.toBytes(B);return _[_.length-1]|=f(g)?128:0,_}toHex(){return kr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let x=I=>Pn(y,I),v=new tr(y,c);return v.bits>=6&&y.BASE.precompute(6),Object.freeze(y.prototype),Object.freeze(y),y}function wc(t,e,r={}){if(xt(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Be(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&&(gt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Ot:o.randomBytes,h=o.toMontgomery,d=o.toMontgomerySecret,E=o.adjustScalarBytes===void 0?O=>O:o.adjustScalarBytes,y=o.domain===void 0?(O,T,p)=>{if(Ie(p,"phflag"),T.length||p)throw new Error("Contexts/pre-hash are not supported");return O}:o.domain;function x(O){return c.create(Dt(O))}function v(O){let T=R.secretKey;Z(O,R.secretKey,"secretKey");let p=Z(n(O),2*T,"hashedSecretKey"),b=E(p.slice(0,T)),S=p.slice(T,2*T),P=x(b);return{head:b,prefix:S,scalar:P}}function I(O){let{head:T,prefix:p,scalar:b}=v(O),S=i.multiply(b),P=S.toBytes();return{head:T,prefix:p,scalar:b,point:S,pointBytes:P}}function g(O){return I(O).pointBytes}function B(O=Uint8Array.of(),...T){let p=Pe(...T);return x(n(y(p,Z(O,void 0,"context"),!!s)))}function _(O,T,p={}){Be(p,{},{},"options"),O=Z(O,void 0,"message"),s&&(O=s(O));let{prefix:b,scalar:S,pointBytes:P}=I(T),w=B(p.context,b,O),m=i.multiply(w).toBytes(),A=B(p.context,m,P,O),C=c.create(w+A*S);if(!c.isValid(C))throw new Error("sign failed: invalid s");let F=Pe(m,c.toBytes(C));return Z(F,R.signature,"result")}let M={zip215:o.zip215};function K(O,T,p,b=M){Be(b);let{context:S}=b,P=b.zip215===void 0?!!M.zip215:b.zip215,w=R.signature;O=Z(O,w,"signature"),T=Z(T,void 0,"message"),p=Z(p,R.publicKey,"publicKey"),P!==void 0&&Ie(P,"zip215"),s&&(T=s(T));let m=w/2,A=O.subarray(0,m),C=Dt(O.subarray(m,w)),F,U,W;try{F=t.fromBytes(p,P),U=t.fromBytes(A,P),W=i.multiplyUnsafe(C)}catch{return!1}if(!P&&F.isSmallOrder())return!1;let Y=B(S,A,p,T);return U.add(F.multiplyUnsafe(Y)).subtract(W).clearCofactor().is0()}let k=a.BYTES,R={secretKey:k,publicKey:k,signature:2*k,seed:k};function N(O){return O=O===void 0?l(R.seed):O,Z(O,R.seed,"seed")}function z(O){return yt(O)&&O.length===R.secretKey}function D(O,T){try{return!!t.fromBytes(O,T===void 0?M.zip215:T)}catch{return!1}}let ee={getExtendedPublicKey:I,randomSecretKey:N,isValidSecretKey:z,isValidPublicKey:D,toMontgomery(O){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(t.fromBytes(O))},toMontgomerySecret(O){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(O)}};return Object.freeze(R),Object.freeze(ee),Object.freeze({keygen:Nn(N,g),getPublicKey:g,sign:_,verify:K,utils:ee,Point:t,lengths:R})}var Ss=BigInt(1),Ec=BigInt(2);var dd=BigInt(5),hd=BigInt(8),As=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),pd={p:As,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:hd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function md(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=As,a=t*t%s*t%s,c=te(a,Ec,s)*a%s,u=te(c,Ss,s)*t%s,f=te(u,dd,s)*u%s,l=te(f,e,s)*f%s,h=te(l,r,s)*l%s,d=te(h,n,s)*h%s,E=te(d,o,s)*d%s,y=te(E,o,s)*d%s,x=te(y,e,s)*f%s;return{pow_p_5_8:te(x,Ec,s)*t%s,b2:a}}function Ac(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var vc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function yd(t,e){let r=As,n=ne(e*e*e,r),o=ne(n*n*e,r),s=md(t*o).pow_p_5_8,i=ne(t*n*s,r),a=ne(e*i*i,r),c=i,u=ne(i*vc,r),f=a===t,l=a===ne(-t,r),h=a===ne(-t*vc,r);return f&&(i=c),(l||h)&&(i=u),lc(i,r)&&(i=ne(-i,r)),{isValid:f||l,value:i}}var Is=xc(pd,{uvRatio:yd}),Sc=Is.Fp;function gd(t){let{y:e}=t;return Sc.toBytes(Sc.div(Ss+e,Ss-e))}function bd(t){let e=Is.Fp.BYTES;return De(t,e),Ac(ds(t.subarray(0,e))).subarray(0,e)}function xd(t){return wc(Is,ds,Object.assign({adjustScalarBytes:Ac,toMontgomery:gd,toMontgomerySecret:bd,zip215:!0},t))}var Ic=xd({});var Vr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Mn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Le={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Mn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Kn=32;var Bs,wd=(async()=>{try{return await Le.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Ed(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Le.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Le.get().subtle.verify({name:"Ed25519"},n,ve(e),ve(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function vd(t,e,r){return Ic.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Bc(t,e,r){return Bs==null&&(Bs=await wd),Bs?Ed(t,e,r):vd(t,e,r)}function Vn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var qn=class{type="Ed25519";raw;constructor(e){this.raw=_s(e,Kn)}toMultihash(){return Ne.digest(Ye(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return ce.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=Bc(this.raw,r,e);return Vn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Cs(t){return t=_s(t,Kn),new qn(t)}function _s(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new re(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var Ad=Math.pow(2,7),Id=Math.pow(2,14),Bd=Math.pow(2,21),Ts=Math.pow(2,28),Os=Math.pow(2,35),Ds=Math.pow(2,42),Ps=Math.pow(2,49),X=128,be=127;function _e(t){if(t<Ad)return 1;if(t<Id)return 2;if(t<Bd)return 3;if(t<Ts)return 4;if(t<Os)return 5;if(t<Ds)return 6;if(t<Ps)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function rr(t,e,r=0){switch(_e(t)){case 8:e[r++]=t&255|X,t/=128;case 7:e[r++]=t&255|X,t/=128;case 6:e[r++]=t&255|X,t/=128;case 5:e[r++]=t&255|X,t/=128;case 4:e[r++]=t&255|X,t>>>=7;case 3:e[r++]=t&255|X,t>>>=7;case 2:e[r++]=t&255|X,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function _d(t,e,r=0){switch(_e(t)){case 8:e.set(r++,t&255|X),t/=128;case 7:e.set(r++,t&255|X),t/=128;case 6:e.set(r++,t&255|X),t/=128;case 5:e.set(r++,t&255|X),t/=128;case 4:e.set(r++,t&255|X),t>>>=7;case 3:e.set(r++,t&255|X),t>>>=7;case 2:e.set(r++,t&255|X),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function Ls(t,e){let r=t[e],n=0;if(n+=r&be,r<X||(r=t[e+1],n+=(r&be)<<7,r<X)||(r=t[e+2],n+=(r&be)<<14,r<X)||(r=t[e+3],n+=(r&be)<<21,r<X)||(r=t[e+4],n+=(r&be)*Ts,r<X)||(r=t[e+5],n+=(r&be)*Os,r<X)||(r=t[e+6],n+=(r&be)*Ds,r<X)||(r=t[e+7],n+=(r&be)*Ps,r<X))return n;throw new RangeError("Could not decode varint")}function Cd(t,e){let r=t.get(e),n=0;if(n+=r&be,r<X||(r=t.get(e+1),n+=(r&be)<<7,r<X)||(r=t.get(e+2),n+=(r&be)<<14,r<X)||(r=t.get(e+3),n+=(r&be)<<21,r<X)||(r=t.get(e+4),n+=(r&be)*Ts,r<X)||(r=t.get(e+5),n+=(r&be)*Os,r<X)||(r=t.get(e+6),n+=(r&be)*Ds,r<X)||(r=t.get(e+7),n+=(r&be)*Ps,r<X))return n;throw new RangeError("Could not decode varint")}function nr(t,e,r=0){return e==null&&(e=ge(_e(t))),e instanceof Uint8Array?rr(t,e,r):_d(t,e,r)}function qr(t,e=0){return t instanceof Uint8Array?Ls(t,e):Cd(t,e)}var Ns=new Float32Array([-0]),wt=new Uint8Array(Ns.buffer);function Cc(t,e,r){Ns[0]=t,e[r]=wt[0],e[r+1]=wt[1],e[r+2]=wt[2],e[r+3]=wt[3]}function Tc(t,e){return wt[0]=t[e],wt[1]=t[e+1],wt[2]=t[e+2],wt[3]=t[e+3],Ns[0]}var ks=new Float64Array([-0]),xe=new Uint8Array(ks.buffer);function Oc(t,e,r){ks[0]=t,e[r]=xe[0],e[r+1]=xe[1],e[r+2]=xe[2],e[r+3]=xe[3],e[r+4]=xe[4],e[r+5]=xe[5],e[r+6]=xe[6],e[r+7]=xe[7]}function Dc(t,e){return xe[0]=t[e],xe[1]=t[e+1],xe[2]=t[e+2],xe[3]=t[e+3],xe[4]=t[e+4],xe[5]=t[e+5],xe[6]=t[e+6],xe[7]=t[e+7],ks[0]}var Td=BigInt(Number.MAX_SAFE_INTEGER),Od=BigInt(Number.MIN_SAFE_INTEGER),Te=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Pt;if(e<Td&&e>Od)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>Pc&&(o=0n,++n>Pc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Pt;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):Pt}},Pt=new Te(0,0);Pt.toBigInt=function(){return 0n};Pt.zzEncode=Pt.zzDecode=function(){return this};Pt.length=function(){return 1};var Pc=4294967296n;function Lc(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 Rc(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 Fs(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 Fe(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function zn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Us=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=ve(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,Fe(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 Fe(this,4);return zn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Fe(this,4);return zn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Fe(this,4);let e=Tc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Fe(this,4);let e=Dc(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 Fe(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Rc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Fe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Fe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Te(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Fe(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 Fe(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 Fe(this,8);let e=zn(this.buf,this.pos+=4),r=zn(this.buf,this.pos+=4);return new Te(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ls(this.buf,this.pos);return this.pos+=_e(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function zr(t){return new Us(t instanceof Uint8Array?t:t.subarray())}function Ue(t,e,r){let n=zr(t);return e.decode(n,void 0,r)}function Ms(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return ge(i);o+i>e&&(n=ge(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Lt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Ks(){}var qs=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Dd=Ms();function Pd(t){return globalThis.Buffer!=null?ge(t):Dd(t)}var $r=class{len;head;tail;states;constructor(){this.len=0,this.head=new Lt(Ks,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Lt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new zs((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(Hn,10,Te.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Te.fromBigInt(e);return this._push(Hn,r.length(),r)}uint64Number(e){return this._push(rr,_e(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Te.fromBigInt(e).zzEncode();return this._push(Hn,r.length(),r)}sint64Number(e){let r=Te.fromNumber(e).zzEncode();return this._push(Hn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Vs,1,e?1:0)}fixed32(e){return this._push(Hr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Te.fromBigInt(e);return this._push(Hr,4,r.lo)._push(Hr,4,r.hi)}fixed64Number(e){let r=Te.fromNumber(e);return this._push(Hr,4,r.lo)._push(Hr,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(Oc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Vs,1,0):this.uint32(r)._push(Rd,r,e)}string(e){let r=Lc(e);return r!==0?this.uint32(r)._push(Fs,r,e):this._push(Vs,1,0)}fork(){return this.states=new qs(this),this.head=this.tail=new Lt(Ks,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 Lt(Ks,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=Pd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Vs(t,e,r){e[r]=t&255}function Ld(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var zs=class extends Lt{next;constructor(e,r){super(Ld,e,r),this.next=void 0}};function Hn(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 Hr(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 Rd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&($r.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Nd,e,t),this},$r.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(kd,e,t),this});function Nd(t,e,r){e.set(t,r)}function kd(t,e,r){t.length<40?Fs(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(V(t),r)}function Hs(){return new $r}function Me(t,e){let r=Hs();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ke(t,e,r){let n=zr(t);yield*e.stream(n,void 0,"$",r)}var $n={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function jn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function $s(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return jn("enum",$n.VARINT,r,n,o)}function Ve(t,e,r){return jn("message",$n.LENGTH_DELIMITED,t,e,r)}var Ge=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var oe;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(oe||(oe={}));var js;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(js||(js={}));(function(t){t.codec=()=>$s(js)})(oe||(oe={}));var Xe;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),oe.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=oe.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:oe.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 Me(s,t.codec())}t.encode=r;function n(s,i){return Ue(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Xe||(Xe={}));var Ys;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),oe.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=oe.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:oe.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 Me(s,t.codec())}t.encode=r;function n(s,i){return Ue(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Ys||(Ys={}));var Yr={};Se(Yr,{MAX_RSA_KEY_SIZE:()=>Ws,generateRSAKeyPair:()=>Kc,jwkToJWKKeyPair:()=>Vc,jwkToPkcs1:()=>Kd,jwkToPkix:()=>Qs,jwkToRSAPrivateKey:()=>ri,pkcs1MessageToJwk:()=>Gs,pkcs1MessageToRSAPrivateKey:()=>Js,pkcs1ToJwk:()=>Md,pkcs1ToRSAPrivateKey:()=>Mc,pkixMessageToJwk:()=>Xs,pkixMessageToRSAPublicKey:()=>ti,pkixToJwk:()=>Vd,pkixToRSAPublicKey:()=>ei});var or=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Yr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return de.createV1(114,this._multihash)}toString(){return ce.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}verify(e,r,n){return Uc(this.jwk,r,e,n)}},jr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Yr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}sign(e,r){return Fc(this.jwk,e,r)}};var Ws=8192,Zs=18,Fd=1062,Ud=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Md(t){let e=et(t);return Gs(e)}function Gs(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 Kd(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 re("JWK was missing components");return ft([Ae(Uint8Array.from([0])),Ae(V(t.n,"base64url")),Ae(V(t.e,"base64url")),Ae(V(t.d,"base64url")),Ae(V(t.p,"base64url")),Ae(V(t.q,"base64url")),Ae(V(t.dp,"base64url")),Ae(V(t.dq,"base64url")),Ae(V(t.qi,"base64url"))]).subarray()}function Vd(t){let e=et(t,{offset:0});return Xs(e)}function Xs(t){let e=et(t[1],{offset:0});return{kty:"RSA",n:H(e[0],"base64url"),e:H(e[1],"base64url")}}function Qs(t){if(t.n==null||t.e==null)throw new re("JWK was missing components");return ft([Ud,mn(ft([Ae(V(t.n,"base64url")),Ae(V(t.e,"base64url"))]))]).subarray()}function Mc(t){let e=et(t);return Js(e)}function Js(t){let e=Gs(t);return ri(e)}function ei(t,e){if(t.byteLength>=Fd)throw new qt("Key size is too large");let r=et(t,{offset:0});return ti(r,t,e)}function ti(t,e,r){let n=Xs(t);if(r==null){let o=Zt(Xe.encode({Type:oe.RSA,Data:e}));r=$e(Zs,o)}return new or(n,r)}function ri(t){if(zc(t)>Ws)throw new re("Key size is too large");let e=Vc(t),r=Zt(Xe.encode({Type:oe.RSA,Data:Qs(e.publicKey)})),n=$e(Zs,r);return new jr(e.privateKey,new or(e.publicKey,n))}async function Kc(t){if(t>Ws)throw new re("Key size is too large");let e=await qc(t),r=Zt(Xe.encode({Type:oe.RSA,Data:Qs(e.publicKey)})),n=$e(Zs,r);return new jr(e.privateKey,new or(e.publicKey,n))}function Vc(t){if(t==null)throw new re("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function qc(t,e){let r=await Le.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 qd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Fc(t,e,r){let n=await Le.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Le.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,ve(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Uc(t,e,r,n){let o=await Le.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Le.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,ve(e),ve(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function qd(t,e){if(t.privateKey==null||t.publicKey==null)throw new re("Private and public key are required");let r=await Promise.all([Le.get().subtle.exportKey("jwk",t.privateKey),Le.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function zc(t){if(t.kty!=="RSA")throw new re("invalid key type");if(t.n==null)throw new re("invalid key modulus");return V(t.n,"base64url").length*8}var Yn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(bn(e),De(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),Ct(o)}update(e){return Wt(this),this.iHash.update(e),this}digestInto(e){Wt(this),xn(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()}},Hc=(()=>{let t=((e,r,n)=>new Yn(e,r).update(n).digest());return t.create=(e,r)=>new Yn(e,r),t})();var zd=BigInt(0),ni=class extends Error{constructor(e=""){super(e)}},rt={Err:ni,_tlv:{encode:(t,e)=>{let{Err:r}=rt;if(gt(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Qa(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}=rt;e=Z(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}=rt;if(In(t),t<zd)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}=rt;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 Ze(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=rt,o=Z(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=rt;Be(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)}},oi=(Object.freeze(rt._tlv),Object.freeze(rt._int),Object.freeze(rt));var $c=(t,e)=>(t+(t>=0?e:-e)/jc)/e;function Hd(t,e,r){Xt("scalar",t,nt,r);let[[n,o],[s,i]]=e,a=$c(i*t,r),c=$c(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,l=u<nt,h=f<nt;l&&(u=-u),h&&(f=-f);let d=Ur(Math.ceil(Qt(r)/2))+Rt;if(u<nt||u>=d||f<nt||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function ai(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function si(t,e){Be(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ie(r.lowS,"lowS"),Ie(r.prehash,"prehash"),r.format!==void 0&&ai(r.format),r}var nt=BigInt(0),Rt=BigInt(1),jc=BigInt(2),ii=BigInt(3),$d=BigInt(4);function Yc(t,e={}){let r=Rn("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Be(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u}=e,f=e.randomBytes===void 0?Ot: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 l=Zc(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(T,p,b){if(u&&p.is0())return Uint8Array.of(0);let{x:S,y:P}=p.toAffine(),w=n.toBytes(S);if(Ie(b,"isCompressed"),b){h();let m=!n.isOdd(P);return Pe(Wc(m),w)}else return Pe(Uint8Array.of(4),w,n.toBytes(P))}function E(T){Z(T,void 0,"Point");let{publicKey:p,publicKeyUncompressed:b}=l,S=T.length,P=T[0],w=T.subarray(1);if(u&&S===1&&P===0)return{x:n.ZERO,y:n.ZERO};if(S===p&&(P===2||P===3)){let m=n.fromBytes(w);if(!n.isValid(m))throw new Error("bad point: is not on curve, wrong x");let A=g(m),C;try{C=n.sqrt(A)}catch(W){let Y=W instanceof Error?": "+W.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}h();let F=n.isOdd(C);return(P&1)===1!==F&&(C=n.neg(C)),{x:m,y:C}}else if(S===b&&P===4){let m=n.BYTES,A=n.fromBytes(w.subarray(0,m)),C=n.fromBytes(w.subarray(m,m*2));if(!B(A,C))throw new Error("bad point: is not on curve");return{x:A,y:C}}else throw new Error(`bad point: got length ${S}, expected compressed=${p} or uncompressed=${b}`)}let y=e.toBytes===void 0?d:e.toBytes,x=e.fromBytes===void 0?E:e.fromBytes,v=n.mul(s.b,ii),I=n.is0(s.a)?T=>n.ZERO:T=>n.mul(s.a,T);function g(T){let p=n.sqr(T),b=n.mul(p,T);return n.add(n.add(b,n.mul(T,s.a)),s.b)}function B(T,p){let b=n.sqr(p),S=g(T);return n.eql(b,S)}if(!B(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let _=n.mul(n.pow(s.a,ii),$d),M=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(_,M)))throw new Error("bad curve params: a or b");function K(T,p,b=!1){if(!n.isValid(p)||b&&n.is0(p))throw new Error(`bad point coordinate ${T}`);return p}function k(T){if(!(T instanceof D))throw new Error("Weierstrass Point expected")}function R(T){if(!c||!c.basises)throw new Error("no endo");return Hd(T,c.basises,o.ORDER)}function N(T,p,b,S){if(!o.isValid(S))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:P,k1:w,k2neg:m,k2:A}=R(S),C=new D(n.mul(b.X,c.beta),b.Y,b.Z);T.push(P?b.negate():b,m?C.negate():C),p.push(w,A)}else T.push(b),p.push(S)}let z=new WeakSet;class D{static BASE=new D(s.Gx,s.Gy,n.ONE);static ZERO=new D(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,b,S){this.X=K("x",p),this.Y=K("y",b,!0),this.Z=K("z",S),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:b,y:S}=p||{};if(!p||!n.isValid(b)||!n.isValid(S))throw new Error("invalid affine point");if(p instanceof D)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(S)?D.ZERO:new D(b,S,n.ONE)}static fromBytes(p){let b=D.fromAffine(x(Z(p,void 0,"point")));return b.assertValidity(),b}static fromHex(p){return D.fromBytes(Gt(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,b=!0){return O.setWindowSize(this,p),b||this.multiply(ii),this}assertValidity(){let p=this;if(p.is0()){if(e.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(z.has(p))return;let{x:b,y:S}=p.toAffine();if(!n.isValid(b)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!B(b,S))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");z.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){k(p);let{X:b,Y:S,Z:P}=this,{X:w,Y:m,Z:A}=p,C=n.eql(n.mul(b,A),n.mul(w,P)),F=n.eql(n.mul(S,A),n.mul(m,P));return C&&F}negate(){return new D(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:b,Z:S}=this,P=n.ZERO,w=n.ZERO,m=n.ZERO,A=n.mul(p,p),C=n.mul(b,b),F=n.mul(S,S),U=n.mul(p,b);return U=n.add(U,U),m=n.mul(p,S),m=n.add(m,m),P=I(m),w=n.mul(v,F),w=n.add(P,w),P=n.sub(C,w),w=n.add(C,w),w=n.mul(P,w),P=n.mul(U,P),m=n.mul(v,m),F=I(F),U=n.sub(A,F),U=I(U),U=n.add(U,m),m=n.add(A,A),A=n.add(m,A),A=n.add(A,F),A=n.mul(A,U),w=n.add(w,A),F=n.mul(b,S),F=n.add(F,F),A=n.mul(F,U),P=n.sub(P,A),m=n.mul(F,C),m=n.add(m,m),m=n.add(m,m),new D(P,w,m)}add(p){k(p);let{X:b,Y:S,Z:P}=this,{X:w,Y:m,Z:A}=p,C=n.ZERO,F=n.ZERO,U=n.ZERO,W=n.mul(b,w),Y=n.mul(S,m),se=n.mul(P,A),Ee=n.add(b,S),ie=n.add(w,m);Ee=n.mul(Ee,ie),ie=n.add(W,Y),Ee=n.sub(Ee,ie),ie=n.add(b,P);let ye=n.add(w,A);return ie=n.mul(ie,ye),ye=n.add(W,se),ie=n.sub(ie,ye),ye=n.add(S,P),C=n.add(m,A),ye=n.mul(ye,C),C=n.add(Y,se),ye=n.sub(ye,C),U=I(ie),C=n.mul(v,se),U=n.add(C,U),C=n.sub(Y,U),U=n.add(Y,U),F=n.mul(C,U),Y=n.add(W,W),Y=n.add(Y,W),se=I(se),ie=n.mul(v,ie),Y=n.add(Y,se),se=n.sub(W,se),se=I(se),ie=n.add(ie,se),W=n.mul(Y,ie),F=n.add(F,W),W=n.mul(ye,ie),C=n.mul(Ee,C),C=n.sub(C,W),W=n.mul(Ee,Y),U=n.mul(ye,U),U=n.add(U,W),new D(C,F,U)}subtract(p){return k(p),this.add(p.negate())}is0(){return this.equals(D.ZERO)}multiply(p){if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:b,f:S}=O.mulSecret(this,p,i,ee);return ee([b,S])[0]}multiplyUnsafe(p){let b=this,S=p;if(!o.isValid(S))throw new RangeError("invalid scalar: out of range");if(S===nt||b.is0())return D.ZERO;if(S===Rt)return b;if(O.hasWindowSize(this))return O.mulUnsafe(b,S,ee);let P=[],w=[];return N(P,w,b,S),Ln(D,P,w)}mulAddUnsafe(p,b,S){k(b);let P=[],w=[];return N(P,w,this,p),N(P,w,b,S),Ln(D,P,w)}toAffine(p){let b=this,S=p;if(S!=null&&!n.isValid(S))throw new RangeError('"invertedZ" expected valid field element');let{X:P,Y:w,Z:m}=b;if(n.eql(m,n.ONE))return{x:P,y:w};let A=b.is0();S==null&&(S=A?n.ONE:n.inv(m));let C=n.mul(P,S),F=n.mul(w,S),U=n.mul(m,S);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(U,n.ONE))throw new Error("invZ was invalid");return{x:C,y:F}}isTorsionFree(){let{isTorsionFree:p}=e;return i===Rt?!0:p?p(D,this):O.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=e;return i===Rt?this:p?p(D,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Rt?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Ie(p,"isCompressed"),this.assertValidity(),y(D,this,p)}toHex(p=!0){return kr(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let ee=T=>Pn(D,T),O=new tr(D,f);return O.bits>=6&&D.BASE.precompute(6),Object.freeze(D.prototype),Object.freeze(D),D}function Wc(t){return Uint8Array.of(t?2:3)}function Zc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function jd(t,e={}){xt(t);let{Fn:r}=t,n=e.randomBytes===void 0?Ot:e.randomBytes,o=Object.assign(Zc(t.Fp,r),{seed:Math.max(On(r.ORDER),16)});function s(d){try{let E=r.fromBytes(d);return r.isValidNot0(E)}catch{return!1}}function i(d,E){let{publicKey:y,publicKeyUncompressed:x}=o;try{let v=d.length;return E===!0&&v!==y||E===!1&&v!==x?!1:!!t.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(o.seed):d,Dn(Z(d,o.seed,"seed"),r.ORDER)}function c(d,E=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(E)}function u(d){let{secretKey:E,publicKey:y,publicKeyUncompressed:x}=o,v=r._lengths;if(!yt(d))return;let I=Z(d,void 0,"key").length,g=I===y||I===x,B=I===E||!!v?.includes(I);if(!(g&&B))return g}function f(d,E,y=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(E)===!1)throw new Error("second arg must be public key");let x=r.fromBytes(d);return t.fromBytes(E).multiply(x).toBytes(y)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},h=Nn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:t,utils:l,lengths:o})}function Gc(t,e,r={}){xt(t);let n=e;bn(n),Be(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?Ot:o.randomBytes,i=o.hmac===void 0?(w,m)=>Hc(n,w,m):o.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:f}=c,l=On(u),h=vs(s,l),{keygen:d,getPublicKey:E,getSharedSecret:y,utils:x,lengths:v}=jd(t,o),I={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=u*jc+Rt<a.ORDER;function B(w){let m=u>>Rt;return w>m}function _(w,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return m}function M(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function K(w,m,A){return M(),(w===A?0:2)|Number(a.isOdd(m))}function k(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function R(w,m){ai(m);let A=v.signature,C=m==="compact"?A:m==="recovered"?A+1:void 0;return Z(w,C)}class N{r;s;recovery;constructor(m,A,C){if(this.r=_("r",m),this.s=_("s",A),C!=null){if(k(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(m,A=I.format){R(m,A);let C;if(A==="der"){let{r:Y,s:se}=oi.toSig(Z(m));return new N(Y,se)}A==="recovered"&&(C=m[0],A="compact",m=m.subarray(1));let F=v.signature/2,U=m.subarray(0,F),W=m.subarray(F,F*2);return new N(c.fromBytes(U),c.fromBytes(W),C)}static fromHex(m,A){return this.fromBytes(Gt(m),A)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new N(this.r,this.s,m)}recoverPublicKey(m){let{r:A,s:C}=this,F=this.assertRecovery(),U=F===2||F===3?A+u:A;if(!a.isValid(U))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let W=a.toBytes(U),Y=t.fromBytes(Pe(Wc((F&1)===0),W)),se=c.inv(U),Ee=D(Z(m,void 0,"msgHash")),ie=c.create(-Ee*se),ye=c.create(C*se),ze=t.BASE.mulAddUnsafe(ie,Y,ye);if(ze.is0())throw new Error("invalid recovery: point at infinify");return ze.assertValidity(),ze}hasHighS(){return B(this.s)}toBytes(m=I.format){if(ai(m),m==="der")return Gt(oi.hexFromSig(this));let{r:A,s:C}=this,F=c.toBytes(A),U=c.toBytes(C);return m==="recovered"?(k(),Pe(Uint8Array.of(this.assertRecovery()),F,U)):Pe(F,U)}toHex(m){return kr(this.toBytes(m))}}Object.freeze(N.prototype),Object.freeze(N);let z=o.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let A=Ze(m),C=m.length*8-f;return C>0?A>>BigInt(C):A}:o.bits2int,D=o.bits2int_modN===void 0?function(m){return c.create(z(m))}:o.bits2int_modN,ee=Ur(f);function O(w){return Xt("num < 2^"+f,w,nt,ee),c.toBytes(w)}function T(w,m){return Z(w,void 0,"message"),m?Z(n(w),void 0,"prehashed message"):w}function p(w,m,A){let{lowS:C,prehash:F,extraEntropy:U}=si(A,I);w=T(w,F);let W=D(w),Y=c.fromBytes(m);if(!c.isValidNot0(Y))throw new Error("invalid private key");let se=[O(Y),O(W)];if(U!=null&&U!==!1){let ze=U===!0?s(v.secretKey):U;se.push(Z(ze,void 0,"extraEntropy"))}let Ee=Pe(...se),ie=W;function ye(ze){let Vt=z(ze);if(!c.isValidNot0(Vt))return;let vr=t.BASE.multiply(Vt).toAffine(),at=c.create(vr.x);if(at===nt)return;let He;if(h!==void 0){let Sr=Ze(Dn(h(l),u)),tf=c.inv(c.mul(Sr,Vt)),rf=c.mul(Sr,ie),nf=c.mul(Sr,Y);He=c.create(tf*c.create(rf+nf*at))}else{let Sr=cc(Vt,u);He=c.create(Sr*c.create(ie+at*Y))}if(He===nt)return;let Ao=K(vr.x,vr.y,at),na=He;return C&&B(He)&&(na=c.neg(He),Ao^=1),new N(at,na,g?void 0:Ao)}return{seed:Ee,k2sig:ye}}function b(w,m,A={}){let{seed:C,k2sig:F}=p(w,m,A);return ec(n.outputLen,c.BYTES,i)(C,F).toBytes(A.format)}function S(w,m,A,C={}){let{lowS:F,prehash:U,format:W}=si(C,I);if(A=Z(A,void 0,"publicKey"),m=T(m,U),!yt(w)){let Y=w instanceof N?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+Y)}R(w,W);try{let Y=N.fromBytes(w,W),se=t.fromBytes(A);if(F&&Y.hasHighS())return!1;let{r:Ee,s:ie}=Y,ye=D(m),ze=c.inv(ie),Vt=c.create(ye*ze),vr=c.create(Ee*ze),at=t.BASE.mulAddUnsafe(Vt,se,vr);if(at.is0())return!1;let He=at.toAffine();return!(c.create(He.x)!==Ee||W==="recovered"&&Y.recovery!==K(He.x,He.y,Ee))}catch{return!1}}function P(w,m,A={}){let{prehash:C}=si(A,I);return m=T(m,C),N.fromBytes(w,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:d,getPublicKey:E,getSharedSecret:y,utils:x,lengths:v,Point:t,sign:b,verify:S,recoverPublicKey:P,Signature:N,hash:n})}var ui={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Yd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Xc=BigInt(2);function Wd(t){let e=ui.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=te(f,r,e)*f%e,h=te(l,r,e)*f%e,d=te(h,Xc,e)*u%e,E=te(d,o,e)*d%e,y=te(E,s,e)*E%e,x=te(y,a,e)*y%e,v=te(x,c,e)*x%e,I=te(v,a,e)*y%e,g=te(I,r,e)*f%e,B=te(g,i,e)*E%e,_=te(B,n,e)*u%e,M=te(_,Xc,e);if(!ci.eql(ci.sqr(M),t))throw new Error("Cannot find square root");return M}var ci=er(ui.p,{sqrt:Wd}),Zd=Yc(ui,{Fp:ci,endo:Yd}),sr=Gc(Zd,Zt);function Qc(t,e,r,n){let o=Tr.digest(r instanceof Uint8Array?r:r.subarray());if(Vn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),sr.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Vr(String(s))});try{return n?.signal?.throwIfAborted(),sr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new Vr(String(s))}}var Wn=class{type="secp256k1";raw;_key;constructor(e){this._key=eu(e),this.raw=Jc(this._key)}toMultihash(){return Ne.digest(Ye(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return ce.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}verify(e,r,n){return Qc(this._key,r,e,n)}};function fi(t){return new Wn(t)}function Jc(t){return sr.Point.fromBytes(t).toBytes()}function eu(t){try{return sr.Point.fromBytes(t),t}catch(e){throw new qt(String(e))}}function ir(t,e){let{Type:r,Data:n}=Xe.decode(t),o=n??new Uint8Array;switch(r){case oe.RSA:return ei(o,e);case oe.Ed25519:return Cs(o);case oe.secp256k1:return fi(o);case oe.ECDSA:return ts(o);default:throw new St}}function tu(t){let{Type:e,Data:r}=Xe.decode(t.digest),n=r??new Uint8Array;switch(e){case oe.Ed25519:return Cs(n);case oe.secp256k1:return fi(n);case oe.ECDSA:return ts(n);default:throw new St}}function Ye(t){return Xe.encode({Type:oe[t.type],Data:t.raw})}var Wr;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((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:he(0),payloadType:he(0),payload:he(0),signature:he(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 Me(s,t.codec())}t.encode=r;function n(s,i){return Ue(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Wr||(Wr={}));var Zn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var Qe=class t{static createFromProtobuf=e=>{let r=Wr.decode(e),n=ir(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=ru(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 Zn("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=Wr.encode({publicKey:Ye(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:fe(this.marshal(),e.marshal())}async validate(e,r){let n=ru(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},ru=(t,e,r)=>{let n=V(t),o=nr(n.byteLength),s=nr(e.length),i=nr(r.length);return new ue(o,n,s,e,i,r)};var nu=Symbol.for("nodejs.util.inspect.custom"),Gd=114,Zr=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()})`}[Bo]=!0;toString(){return this.string==null&&(this.string=ce.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return de.createV1(Gd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return fe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return fe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[nu](){return`PeerId(${this.toString()})`}},Gr=class extends Zr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Xr=class extends Zr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Qr=class extends Zr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Xd=2336,Jr=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ne.digest(V(this.url))}[nu](){return`PeerId(${this.url})`}[Bo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return de.createV1(Xd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=H(e)),e.toString()===this.toString())}};var Qd=114,ou=2336;function su(t){if(t.type==="Ed25519")return new Xr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Qr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Gr({multihash:t.toCID().multihash,publicKey:t});throw new St}function li(t){if(eh(t))return new Gr({multihash:t});if(Jd(t))try{let e=tu(t);if(e.type==="Ed25519")return new Xr({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Qr({multihash:t,publicKey:e})}catch{let r=H(t.digest);return new Jr(new URL(r))}throw new fn("Supplied PeerID Multihash is invalid")}function Gn(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Qd&&t.code!==ou)throw new un("Supplied PeerID CID is invalid");if(t.code===ou){let e=H(t.multihash.digest);return new Jr(new URL(e))}return li(t.multihash)}function Jd(t){return t.code===Ne.code}function eh(t){return t.code===Tr.code}var me=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ot=class extends Error{static name="ValidationError";name="ValidationError"},Xn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Qn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Jn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var iu=45,th=15,ar=new Jn;function eo(t){if(!(t.length>th))return ar.new(t).parseWith(()=>ar.readIPv4Addr())}function to(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>iu))return ar.new(t).parseWith(()=>ar.readIPv6Addr())}function cr(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>iu)return;let r=ar.new(t).parseWith(()=>ar.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 ur(t){return!!eo(t)}function ro(t){return!!to(t)}function hi(t){return e=>H(e,t)}function pi(t){return e=>V(e,t)}function fr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Nt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function au(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=Nt(n);return je([r,o],r.length+o.length)}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!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=ut.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=Nt(n);return je([r,o],r.length+o.length)}function mi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=H(e,"base32"),o=fr(r);return`${n}:${o}`}var yi=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 me("Invalid byte value in IP address");e[n]=o}),e},uu=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=ur(r[n]),i;s&&(i=yi(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 me("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},fu=function(t){if(t.byteLength!==4)throw new me("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},lu=function(t){if(t.byteLength!==16)throw new me("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 me(`Invalid IPv6 address "${r}"`)}};function du(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new me(`Invalid IPv6 address "${t}"`)}}var di=Object.values(Or).map(t=>t.decoder),rh=(function(){let t=di[0].or(di[1]);return di.slice(2).forEach(e=>t=t.or(e)),t})();function hu(t){return rh.decode(t)}function pu(t){return e=>t.encoder.encode(e)}function nh(t){if(parseInt(t).toString()!==t)throw new ot("Value must be an integer")}function oh(t){if(t<0)throw new ot("Value must be a positive integer, or zero")}function sh(t){return e=>{if(e>t)throw new ot(`Value must be smaller than or equal to ${t}`)}}function ih(...t){return e=>{for(let r of t)r(e)}}var en=ih(nh,oh,sh(65535));var pe=-1,gi=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 Qn(`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)}))}},it=new gi,wh=[{code:4,name:"ip4",size:32,valueToBytes:yi,bytesToValue:fu,validate:t=>{if(!ur(t))throw new ot(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Nt,bytesToValue:fr,validate:en},{code:273,name:"udp",size:16,valueToBytes:Nt,bytesToValue:fr,validate:en},{code:33,name:"dccp",size:16,valueToBytes:Nt,bytesToValue:fr,validate:en},{code:41,name:"ip6",size:128,valueToBytes:uu,bytesToValue:lu,stringToValue:du,validate:t=>{if(!ro(t))throw new ot(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:pe},{code:43,name:"ipcidr",size:8,bytesToValue:hi("base10"),valueToBytes:pi("base10")},{code:53,name:"dns",size:pe},{code:54,name:"dns4",size:pe},{code:55,name:"dns6",size:pe},{code:56,name:"dnsaddr",size:pe},{code:132,name:"sctp",size:16,valueToBytes:Nt,bytesToValue:fr,validate:en},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:pe,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:pe,bytesToValue:hi("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?pi("base58btc")(t):de.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:mi,valueToBytes:au},{code:445,name:"onion3",size:296,bytesToValue:mi,valueToBytes:cu},{code:446,name:"garlic64",size:pe},{code:447,name:"garlic32",size:pe},{code:448,name:"tls"},{code:449,name:"sni",size:pe},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:pe,bytesToValue:pu(qo),valueToBytes:hu},{code:480,name:"http"},{code:481,name:"http-path",size:pe,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:pe}];wh.forEach(t=>{it.addProtocol(t)});function mu(t){let e=[],r=0;for(;r<t.length;){let n=qr(t,r),o=it.getProtocol(n),s=_e(n),i=Eh(o,t,r+s),a=0;i>0&&o.size===pe&&(a=_e(i));let c=s+a+i,u={code:n,name:o.name,bytes:ve(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 yu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=it.getProtocol(n.code),s=_e(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===pe&&(c=_e(a)));let u=new Uint8Array(s+c+a),f=0;rr(n.code,u,f),f+=s,i!=null&&(o.size===pe&&(rr(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return je(r,e)}function gu(t){if(t.charAt(0)!=="/")throw new me('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=it.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 me(`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 me(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new me("Incomplete multiaddr");return e}function bu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=it.getProtocol(e.code);if(r==null)throw new me(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Eh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:qr(e,r)}var vh=Symbol.for("nodejs.util.inspect.custom"),Pi=Symbol.for("@multiformats/multiaddr");function Sh(t){if(t==null&&(t="/"),xu(t))return t.getComponents();if(t instanceof Uint8Array)return mu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),gu(t);if(Array.isArray(t))return t;throw new me("Must be a string, Uint8Array, Component[], or another Multiaddr")}var co=class t{[Pi]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Sh(e),r.validate!==!1&&Ah(this)}get bytes(){return this.#r==null&&(this.#r=yu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=bu(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 Xn(`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 fe(this.bytes,e.bytes)}[vh](){return`Multiaddr(${this.toString()})`}};function Ah(t){t.getComponents().forEach(e=>{let r=it.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function xu(t){return!!t?.[Pi]}function rn(t){return new co(t)}var wu="libp2p-peer-record",Eu=Uint8Array.from([3,1]);var nn;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=Ve((l,h,d={})=>{d.lengthDelimited!==!1&&h.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(h.uint32(10),h.bytes(l.multiaddr)),d.lengthDelimited!==!1&&h.ldelim()},(l,h,d={})=>{let E={multiaddr:he(0)},y=h==null?l.len:l.pos+h;for(;l.pos<y;){let x=l.uint32();x>>>3===1?E.multiaddr=l.bytes():l.skipType(x&7)}return E},function*(l,h,d,E={}){let y=h==null?l.len:l.pos+h;for(;l.pos<y;){let x=l.uint32();x>>>3===1?yield{field:`${d}.multiaddr`,value:l.bytes()}:l.skipType(x&7)}})),a);function c(l){return Me(l,i.codec())}i.encode=c;function u(l,h){return Ue(l,i.codec(),h)}i.decode=u;function f(l,h){return Ke(l,i.codec(),h)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=Ve((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:he(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 Ge('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let h=i.uint32();switch(h>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Ge('Streaming decode error - repeated field "addresses" had too many elements');for(let d of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...d,index:f.addresses};f.addresses++;break}default:{i.skipType(h&7);break}}}})),r);function n(i){return Me(i,t.codec())}t.encode=n;function o(i,a){return Ue(i,t.codec(),a)}t.decode=o;function s(i,a){return Ke(i,t.codec(),a)}t.stream=s})(nn||(nn={}));function vu(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var qe=class t{static createFromProtobuf=e=>{let r=nn.decode(e),n=li(_r(r.peerId)),o=(r.addresses??[]).map(i=>rn(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=wu;static CODEC=Eu;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=nn.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||!vu(this.multiaddrs,e.multiaddrs))}};function Ih(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 uo(t){let e=Ih(t);if(e==null)throw new re(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function Su(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 Au(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 Li(t){switch(t.length){case Ft:return t.join(".");case Ut:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function Iu(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 Ft=4,Ut=16,hw=parseInt("0xFFFF",16),Bh=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function on(t,e){e.length===Ut&&t.length===Ft&&Su(e,0,11)&&(e=e.slice(12)),e.length===Ft&&t.length===Ut&&Au(t,Bh,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 _u(t,e){if(typeof e=="string"&&(e=cr(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 Ri(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Ft,o=eo(e);if(o==null&&(n=Ut,o=to(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=Ni(s,8*n);return{network:on(o,i),mask:i}}function Ni(t,e){if(e!==8*Ft&&e!==8*Ut)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var sn=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Ri(e));else{let n=cr(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=cr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Ni(o,8*n.length);this.network=on(n,this.mask)}}contains(e){return _u({network:this.network,mask:this.mask},e)}toString(){let e=Iu(this.mask),r=e!==-1?String(e):Bu(this.mask);return Li(this.network)+"/"+r}};function Cu(t,e){return new sn(t).contains(e)}function Tu(t){try{let e=uo(t);return e.type==="ip6"?Cu("2000::/3",e.host):!1}catch{return!1}}var Lu=ff(Pu(),1),Lh=["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"],Rh=Lh.map(t=>new Lu.Netmask(t));function qi(t){for(let e of Rh)if(e.contains(t))return!0;return!1}function Nh(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function kh(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 qi(o)}function Fh(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function Uh(t){let e=t.split(":"),r=e[e.length-1];return qi(r)}function Mh(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 Ru(t){if(ur(t))return qi(t);if(Nh(t))return kh(t);if(Fh(t))return Uh(t);if(ro(t))return Mh(t)}function Nu(t){try{let e=uo(t);switch(e.type){case"ip4":case"ip6":return Ru(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var Q=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),L=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),ku=t=>({match:e=>t.match(e)===!1?e:!1}),q=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),we=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),j=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function J(...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 Kh=L(421),$w=J(Kh),ho=L(54),po=L(55),mo=L(56),Hi=L(53),jw=J(ho,q(L(421))),Yw=J(po,q(L(421))),Ww=J(mo,q(L(421))),Zw=J(we(Hi,mo,ho,po),q(L(421))),Fu=j(L(4),q(L(43))),Uu=j(q(L(42)),L(41),q(L(43))),$i=we(Fu,Uu),br=we($i,Hi,ho,po,mo),Mu=J(we($i,j(we(Hi,mo,ho,po),q(L(421))))),Gw=J(Fu),Xw=J(Uu),Qw=J($i),ji=j(br,L(6)),an=j(br,L(273)),Ku=J(j(ji,q(L(421)))),Jw=J(an),Yi=j(an,Q(460),q(L(421))),yo=j(an,Q(461),q(L(421))),Vh=we(Yi,yo),e1=J(Yi),t1=J(yo),zi=we(br,ji,an,Yi,yo),Vu=we(j(zi,Q(477),q(L(421)))),r1=J(Vu),qu=we(j(zi,Q(478),q(L(421))),j(zi,Q(448),q(L(449)),Q(477),q(L(421)))),n1=J(qu),zu=j(an,Q(280),q(L(466)),q(L(466)),q(L(421))),o1=J(zu),Hu=j(yo,Q(465),q(L(466)),q(L(466)),q(L(421))),s1=J(Hu),lo=we(Vu,qu,j(ji,q(L(421))),j(Vh,q(L(421))),j(br,q(L(421))),zu,Hu,L(421)),i1=J(lo),qh=j(q(lo),Q(290),ku(Q(281)),q(L(421))),a1=J(qh),zh=we(j(lo,Q(290),Q(281),q(L(421))),j(lo,Q(281),q(L(421))),j(Q(281),q(L(421)))),c1=J(zh),Hh=j(br,we(j(L(6,"80")),j(L(6),Q(480)),Q(480)),q(L(481)),q(L(421))),u1=J(Hh),$h=j(br,we(j(L(6,"443")),j(L(6,"443"),Q(480)),j(L(6),Q(443)),j(L(6),Q(448),Q(480)),j(Q(448),Q(480)),Q(448),Q(443)),q(L(481)),q(L(421))),f1=J($h),jh=we(j(L(777),q(L(421)))),l1=J(jh),Yh=we(j(L(400),q(L(421)))),d1=J(Yh);function xr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Wi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},$u=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Zi(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){h($u(i));return}if(i&&(c=()=>{h($u(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,h),r===Number.POSITIVE_INFINITY)return;let d=new Wi;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(E){h(E)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?h(o):(d.message=o??`Promise timed out after ${r} milliseconds`,h(d))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Wh=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 Zh(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}=Wh(t),l=async(...d)=>{let E=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(E))return}catch(y){n(),i(y);return}c.push(E),r.count===c.length&&(n(),s(c))},h=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,l);for(let d of r.rejectionEvents)a.includes(d)||f(d,h)};for(let d of a)u(d,l);for(let d of r.rejectionEvents)a.includes(d)||u(d,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=Zi(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function ju(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Zh(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Yu(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 Kt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Gh(t){return t.reason}async function Gi(t,e,r){if(e==null)return t;let n=r?.translateError??Gh;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Qh=4194304,go=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Qi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ji=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ea=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Jh(t){return typeof t?.closeRead=="function"}function ep(t){return typeof t?.close=="function"}function Xi(t){return Jh(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:ep(t)?t.status!=="open":!1}function tp(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function rp(t,e){let r=e?.maxBufferSize??Qh,n=new ue,o,s=!1;if(!tp(t))throw new re("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let a=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};t.addEventListener("close",a);let c=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(s===!0)throw new go("Stream was unwrapped");if(Xi(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Kt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await Gi(o.promise,f?.signal),Xi(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let h=f?.bytes??n.byteLength;if(n.byteLength<h){if(Xi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,h),new Kt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return u.read(f)}let d=n.sublist(0,h);return n.consume(h),d},async write(f,l){if(s===!0)throw new go("Stream was unwrapped");t.send(f)||await ju(t,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return u}function np(t,e={}){let r=rp(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=_e(e.maxDataLength));let n=e?.lengthDecoder??qr,o=e?.lengthEncoder??nr;return{async read(i){let a=-1,c=new ue;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 Qi("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ea(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Ji(`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 Kt(`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 Kt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new ue(o(i.byteLength),i),a)},async writeV(i,a){let c=new ue(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function wr(t,e){let r=np(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 op(t){return t[Symbol.asyncIterator]!=null}function sp(t){if(op(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Wu=sp;var bo=globalThis.CustomEvent??Event;async function*ta(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 y of t){if(s.length===r&&(i=xr(),await i.promise),f||l)break;let x={done:!1};s.push(x),y().then(v=>{x.done=!0,x.ok=!0,x.value=v,o.dispatchEvent(new bo("task-complete"))},v=>{x.done=!0,x.err=v,o.dispatchEvent(new bo("task-complete"))})}c=!0,o.dispatchEvent(new bo("task-complete"))}catch(y){u=y,o.dispatchEvent(new bo("task-complete"))}});function h(){return n?s[0]?.done:!!s.find(y=>y.done)}function*d(){for(;s.length>0&&s[0].done;){let y=s[0];if(s.shift(),y.ok)yield y.value;else throw f=!0,i.resolve(),y.err;i.resolve()}}function*E(){for(;h();)for(let y=0;y<s.length;y++)if(s[y].done){let x=s[y];if(s.splice(y,1),y--,x.ok)yield x.value;else throw f=!0,i.resolve(),x.err;i.resolve()}}try{for(;;){if(h()||(a=xr(),await a.promise),u!=null||(n?yield*d():yield*E(),u!=null))throw u;if(c&&s.length===0)break}}finally{l=!0,i.resolve()}}var Zu="0.1.0";var Gu="id/push",Xu="1.0.0",Qu="1.0.0";var vt;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((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 Ge('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 Ge('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 Ge('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 Ge('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 Me(s,t.codec())}t.encode=r;function n(s,i){return Ue(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(vt||(vt={}));var Ce={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function ef(t){return t.bytes.length===0}function ra(t){if(t!=null&&t.length>0)try{let e=rn(t);if(!ef(e))return e}catch{}}async function xo(t,e,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Re("message was null or undefined");let s={},i=o.listenAddrs.map(ra).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=ir(o.publicKey);if(!su(u).equals(n.remotePeer))throw new Re("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 Qe.openAndCertify(u,qe.DOMAIN),l=qe.createFromProtobuf(f.payload),h=Gn(f.publicKey.toCID());if(!l.peerId.equals(h))throw new Re("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(l.peerId))throw new Re("signing key does not match remote PeerId");let d;try{d=await t.get(l.peerId)}catch(y){if(y.name!=="NotFoundError")throw y}if(d!=null&&(s.metadata=d.metadata,d.peerRecordEnvelope!=null)){let y=Qe.createFromProtobuf(d.peerRecordEnvelope),x=qe.createFromProtobuf(y.payload);x.seqNumber>=l.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",x.seqNumber,l.seqNumber),l=x,u=d.peerRecordEnvelope)}s.peerRecordEnvelope=u;let E=l.multiaddrs.filter(y=>!ef(y));s.addresses=E.map(y=>({isCertified:!0,multiaddr:y})),a={seq:l.seqNumber,addresses:E}}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:rn(o.observedAddr),protocols:o.protocols,signedPeerRecord:a,connection:n};return e.safeDispatchEvent("peer:identify",{detail:c}),c}function wo(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 Eo(t,e,r,n){let o=wr(t,{maxDataLength:e}).pb(vt),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 Er=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??Ce.timeout,this.maxInboundStreams=r.maxInboundStreams??Ce.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Ce.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Ce.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Ce.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Ce.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Ce.protocolPrefix}/${Zu}`,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 vo=class extends Er{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Ce.protocolPrefix}/${Gu}/${Qu}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Ce.concurrency,this._push=Yu(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Ce.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[ln]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),r=new qe({peerId:this.components.peerId,multiaddrs:e}),n=await Qe.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 h,d=AbortSignal.timeout(c.timeout);try{h=await f.newStream(c.protocol,{signal:d,runOnLimitedConnection:c.runOnLimitedConnection}),await wr(h,{maxDataLength:c.maxMessageSize}).pb(vt).write({listenAddrs:e.map(y=>y.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:d}),await h.close({signal:d})}catch(E){h?.log.newScope("identify-push")?.error("could not push identify update to peer",E),h?.abort(E)}})}await Wu(ta(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 Eo(e,this.maxMessageSize,o,n);await xo(this.components.peerStore,this.components.events,n,r,wo(s)),n.trace("handled push from %p",r.remotePeer)}};var So=class extends Er{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Ce.protocolPrefix}/${"id"}/${Xu}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Ce.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[ln]=["@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 Eo(n,this.maxMessageSize,r,o);return wo(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 Re("Public key was missing from identify message");let a=ir(o),c=Gn(a.toCID());if(!e.remotePeer.equals(c))throw new Re("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new Re("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),xo(this.components.peerStore,this.components.events,this.log,e,n)}maybeAddObservedAddress(e){let r=ra(e);if(r==null||(this.log.trace("our observed address was %a",r),Nu(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Tu(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Ku.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(e,r){let n=e.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let f=new qe({peerId:this.components.peerId,multiaddrs:i});a=(await Qe.seal(f,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;Mu.matches(r.remoteAddr)||(c=void 0);let u=wr(e).pb(vt);n("send response"),await u.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ye(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 fp(t={}){return e=>new So(e,t)}function lp(t={}){return e=>new vo(e,t)}return lf(dp);})();
|
|
2
|
+
"use strict";var Libp2PIdentify=(()=>{var of=Object.create;var cn=Object.defineProperty;var sf=Object.getOwnPropertyDescriptor;var af=Object.getOwnPropertyNames;var cf=Object.getPrototypeOf,uf=Object.prototype.hasOwnProperty;var Io=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Se=(t,e)=>{for(var r in e)cn(t,r,{get:e[r],enumerable:!0})},oa=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of af(e))!uf.call(t,o)&&o!==r&&cn(t,o,{get:()=>e[o],enumerable:!(n=sf(e,o))||n.enumerable});return t};var ff=(t,e,r)=>(r=t!=null?of(cf(t)):{},oa(e||!t||!t.__esModule?cn(r,"default",{value:t,enumerable:!0}):r,t)),lf=t=>oa(cn({},"__esModule",{value:!0}),t);var Fi=Io(yr=>{"use strict";Object.defineProperty(yr,"__esModule",{value:!0});yr.Netmask4Impl=void 0;yr.ip2long=mr;yr.long2ip=Je;function Je(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 _h=48,Ch=97,Th=65;function Oh(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)-_h)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-Ch)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-Th)>>>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 mr(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]=Oh(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 ki=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=mr(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=(mr(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=Je(this.netLong),this.mask=Je(this.maskLong),this.hostmask=Je(~this.maskLong),this.first=this.bitmask<=30?Je(this.netLong+1):this.base,this.last=this.bitmask<=30?Je(this.netLong+this.size-2):Je(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Je(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):(mr(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(Je(this.netLong+this.size*e),this.mask)}forEach(e){let r=mr(this.first),n=mr(this.last),o=0;for(;r<=n;)e(Je(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};yr.Netmask4Impl=ki});var Du=Io(gr=>{"use strict";Object.defineProperty(gr,"__esModule",{value:!0});gr.Netmask6Impl=void 0;gr.ip6bigint=Mi;gr.bigint2ip6=Mt;var Dh=Fi(),Ui=(1n<<128n)-1n;function Mi(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,Dh.ip2long)(n),s=t.substring(0,r+1)+"0:0";return Ou(s)&~0xffffffffn|BigInt(o)}return Ou(t)}function Ou(t){let e=t.indexOf("::"),r;if(e!==-1){let o=t.substring(0,e),s=t.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(c).fill("0"),...a]}else r=t.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Mt(t){if(t<0n||t>Ui)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 Ki=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=Ui>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Mi(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Mt(this.netBigint),this.mask=Mt(this.maskBigint),this.hostmask=Mt(~this.maskBigint&Ui),this.first=this.base,this.last=Mt(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.last):(Mi(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Mt(this.netBigint+r*BigInt(e)),this.bitmask)}forEach(e){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)e(Mt(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};gr.Netmask6Impl=Ki});var Pu=Io(Et=>{"use strict";Object.defineProperty(Et,"__esModule",{value:!0});Et.long2ip=Et.ip2long=Et.Netmask=void 0;var fo=Fi();Object.defineProperty(Et,"ip2long",{enumerable:!0,get:function(){return fo.ip2long}});Object.defineProperty(Et,"long2ip",{enumerable:!0,get:function(){return fo.long2ip}});var Ph=Du(),Vi=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 Ph.Netmask6Impl(e,r):this._impl=new fo.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 fo.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()}};Et.Netmask=Vi});var dp={};Se(dp,{identify:()=>fp,identifyPush:()=>lp});var re=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},qt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var un=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},fn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Re=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var St=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Bo=Symbol.for("@libp2p/peer-id");var ln=Symbol.for("@libp2p/service-capabilities");var Do={};Se(Do,{base58btc:()=>ce,base58flickr:()=>xf});var Vp=new Uint8Array(0);function ia(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 Oe(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return At(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return At(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function aa(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var sa=4096;function ca(t){let e=t.length;if(e<=sa)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=sa));return r}function df(t){return t?.buffer instanceof ArrayBuffer}function At(t){return df(t)?t:t.slice()}function hf(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),h=Math.log(f)/Math.log(256),d=Math.log(256)/Math.log(f);function E(v){if(v instanceof Uint8Array||(ArrayBuffer.isView(v)?v=new Uint8Array(v.buffer,v.byteOffset,v.byteLength):Array.isArray(v)&&(v=Uint8Array.from(v))),!(v instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(v.length===0)return"";for(var I=0,g=0,B=0,_=v.length;B!==_&&v[B]===0;)B++,I++;for(var M=(_-B)*d+1>>>0,K=new Uint8Array(M);B!==_;){for(var k=v[B],R=0,N=M-1;(k!==0||R<g)&&N!==-1;N--,R++)k+=256*K[N]>>>0,K[N]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");g=R,B++}for(var z=M-g;z!==M&&K[z]===0;)z++;for(var D=l.repeat(I);z<M;++z)D+=t.charAt(K[z]);return D}function y(v){if(typeof v!="string")throw new TypeError("Expected String");if(v.length===0)return new Uint8Array;var I=0;if(v[I]!==" "){for(var g=0,B=0;v[I]===l;)g++,I++;for(var _=(v.length-I)*h+1>>>0,M=new Uint8Array(_);v[I];){var K=n[v.charCodeAt(I)];if(K===255)return;for(var k=0,R=_-1;(K!==0||k<B)&&R!==-1;R--,k++)K+=f*M[R]>>>0,M[R]=K%256>>>0,K=K/256>>>0;if(K!==0)throw new Error("Non-zero carry");B=k,I++}if(v[I]!==" "){for(var N=_-B;N!==_&&M[N]===0;)N++;for(var z=new Uint8Array(g+(_-N)),D=g;N!==_;)z[D++]=M[N++];return z}}}function x(v){var I=y(v);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:y,decode:x}}var pf=hf,mf=pf,fa=mf;var _o=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")}},Co=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 la(this,e)}},To=class{decoders;constructor(e){this.decoders=e}or(e){return la(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 la(t,e){return new To({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Oo=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 _o(e,r,n),this.decoder=new Co(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function zt({name:t,prefix:e,encode:r,decode:n}){return new Oo(t,e,r,n)}function ct({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=fa(r,t,n);return zt({prefix:e,name:t,encode:o,decode:i=>Oe(s(i))})}function yf(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 gf(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 bf(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 ae({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=bf(n,o);return zt({prefix:e,name:t,encode(i){return gf(i,n,r)},decode(i){return yf(i,s,r,t)}})}var ce=ct({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xf=ct({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Po={};Se(Po,{base32:()=>ut,base32hex:()=>Sf,base32hexpad:()=>If,base32hexpadupper:()=>Bf,base32hexupper:()=>Af,base32pad:()=>Ef,base32padupper:()=>vf,base32upper:()=>wf,base32z:()=>_f});var ut=ae({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),wf=ae({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Ef=ae({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),vf=ae({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Sf=ae({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Af=ae({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),If=ae({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Bf=ae({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),_f=ae({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Lo={};Se(Lo,{base36:()=>Ar,base36upper:()=>Cf});var Ar=ct({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Cf=ct({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Tf=pa,da=128,Of=127,Df=~Of,Pf=Math.pow(2,31);function pa(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Pf;)e[r++]=t&255|da,t/=128;for(;t&Df;)e[r++]=t&255|da,t>>>=7;return e[r]=t|0,pa.bytes=r-n+1,e}var Lf=Ro,Rf=128,ha=127;function Ro(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Ro.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&ha)<<o:(i&ha)*Math.pow(2,o),o+=7}while(i>=Rf);return Ro.bytes=s-n,r}var Nf=Math.pow(2,7),kf=Math.pow(2,14),Ff=Math.pow(2,21),Uf=Math.pow(2,28),Mf=Math.pow(2,35),Kf=Math.pow(2,42),Vf=Math.pow(2,49),qf=Math.pow(2,56),zf=Math.pow(2,63),Hf=function(t){return t<Nf?1:t<kf?2:t<Ff?3:t<Uf?4:t<Mf?5:t<Kf?6:t<Vf?7:t<qf?8:t<zf?9:10},$f={encode:Tf,decode:Lf,encodingLength:Hf},jf=$f,Ir=jf;function Br(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 Ht(t,e,r=0){return Ir.encode(t,e,r),e}function $t(t){return Ir.encodingLength(t)}function $e(t,e){let r=e.byteLength,n=$t(t),o=n+$t(r),s=new Uint8Array(o+r);return Ht(t,s,0),Ht(r,s,n),s.set(e,o),new jt(t,r,e,s)}function _r(t){let e=Oe(t),[r,n]=Br(e),[o,s]=Br(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new jt(r,o,i,e)}function ma(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ia(t.bytes,r.bytes)}}var jt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=At(n),this.bytes=At(o)}};function ya(t,e){let{bytes:r,version:n}=t;return n===0?Wf(r,No(t),e??ce.encoder):Zf(r,No(t),e??ut.encoder)}var ga=new WeakMap;function No(t){let e=ga.get(t);if(e==null){let r=new Map;return ga.set(t,r),r}return e}var de=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=At(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!==Cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Gf)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=$e(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&&ma(e.multihash,n.multihash)}toString(e){return ya(this,e)}toJSON(){return{"/":ya(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??ba(n,o,s.bytes))}else if(r[Xf]===!0){let{version:n,multihash:o,code:s}=r,i=_r(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!==Cr)throw new Error(`Version 0 CID must use dag-pb (code: ${Cr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ba(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Cr,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=Oe(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new jt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Br(e.subarray(r));return r+=h,l},o=n(),s=Cr;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]=Yf(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 No(s).set(n,e),s}};function Yf(t,e){switch(t[0]){case"Q":{let r=e??ce;return[ce.prefix,r.decode(`${ce.prefix}${t}`)]}case ce.prefix:{let r=e??ce;return[ce.prefix,r.decode(t)]}case ut.prefix:{let r=e??ut;return[ut.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 Wf(t,e,r){let{prefix:n}=r;if(n!==ce.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 Zf(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 Cr=112,Gf=18;function ba(t,e,r){let n=$t(t),o=n+$t(e),s=new Uint8Array(o+r.byteLength);return Ht(t,s,0),Ht(e,s,n),s.set(r,o),s}var Xf=Symbol.for("@ipld/js-cid/CID");var ko={};Se(ko,{identity:()=>Ne});var xa=0,Qf="identity",wa=Oe;function Jf(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 $e(xa,wa(t))}var Ne={code:xa,name:Qf,encode:wa,digest:Jf};function fe(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 el(t){return t.buffer instanceof ArrayBuffer}function ve(t){return el(t)?t:t.slice()}async function Ea(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,ve(e),ve(r.subarray()));return n?.signal?.throwIfAborted(),s}function he(t=0){return new Uint8Array(t)}function ge(t=0){return new Uint8Array(t)}function tl(t){return t?.buffer instanceof ArrayBuffer}function Fo(t){if(tl(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function je(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=ge(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Fo(r)}var Sa=Symbol.for("@achingbrain/uint8arraylist");function va(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 hn(t){return!!t?.[Sa]}var ue=class t{bufs;length;[Sa]=!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(hn(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(hn(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=va(this.bufs,e);return r.buf[r.index]}set(e,r){let n=va(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(hn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return je(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:je(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!hn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let d=this.get(l+h);if(n[h]!==d){f=Math.max(1,h-a[d]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=ge(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=he(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=he(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=he(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=ge(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=he(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=he(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=he(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=he(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=he(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(!fe(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 Uo={};Se(Uo,{base10:()=>rl});var rl=ct({prefix:"9",name:"base10",alphabet:"0123456789"});var Mo={};Se(Mo,{base16:()=>nl,base16upper:()=>ol});var nl=ae({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),ol=ae({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Ko={};Se(Ko,{base2:()=>sl});var sl=ae({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Vo={};Se(Vo,{base256emoji:()=>fl});var Aa=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}"),il=Aa.reduce((t,e,r)=>(t[r]=e,t),[]),al=Aa.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function cl(t){return t.reduce((e,r)=>(e+=il[r],e),"")}function ul(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=al[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var fl=zt({prefix:"\u{1F680}",name:"base256emoji",encode:cl,decode:ul});var zo={};Se(zo,{base64:()=>ll,base64pad:()=>dl,base64url:()=>qo,base64urlpad:()=>hl});var ll=ae({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),dl=ae({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qo=ae({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),hl=ae({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ho={};Se(Ho,{base8:()=>pl});var pl=ae({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $o={};Se($o,{identity:()=>ml});var ml=zt({prefix:"\0",name:"identity",encode:t=>ca(Oe(t)),decode:t=>Oe(aa(t))});var Bm=new TextEncoder,_m=new TextDecoder;var Wo={};Se(Wo,{sha256:()=>Tr,sha512:()=>xl});var bl=20;function Yo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new jo(t,e,r,n,o)}var jo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??bl,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?Ia(n,this.code,r?.truncate):n.then(o=>Ia(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ia(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 $e(e,t)}function _a(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Tr=Yo({name:"sha2-256",code:18,encode:_a("SHA-256")}),xl=Yo({name:"sha2-512",code:19,encode:_a("SHA-512")});var Or={...$o,...Ko,...Ho,...Uo,...Mo,...Po,...Lo,...Do,...zo,...Vo},Mm={...Wo,...ko};function Ta(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ca=Ta("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Zo=Ta("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=ge(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),wl={utf8:Ca,"utf-8":Ca,hex:Or.base16,latin1:Zo,ascii:Zo,binary:Zo,...Or},pn=wl;function V(t,e="utf8"){let r=pn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function H(t,e="utf8"){let r=pn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var El=parseInt("11111",2),Go=parseInt("10000000",2),vl=parseInt("01111111",2),Oa={0:Dr,1:Dr,2:Sl,3:Bl,4:_l,5:Il,6:Al,16:Dr,22:Dr,48:Dr};function et(t,e={offset:0}){let r=t[e.offset]&El;if(e.offset++,Oa[r]!=null)return Oa[r](t,e);throw new Error("No decoder for tag "+r)}function Pr(t,e){let r=0;if((t[e.offset]&Go)===Go){let n=t[e.offset]&vl,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=et(t,e);if(n===null)break;r.push(n)}return r}function Sl(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 Al(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 Il(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 _l(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 ue;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Xo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Cl(t.byteLength);return new ue(Uint8Array.from([e.byteLength|Go]),e)}function Ae(t){let e=new ue,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ue(Uint8Array.from([2]),Xo(e),e)}function mn(t){let e=Uint8Array.from([0]),r=new ue(e,t);return new ue(Uint8Array.from([3]),Xo(r),r)}function ft(t,e=48){let r=new ue;for(let n of t)r.append(n);return new ue(Uint8Array.from([e]),Xo(r),r)}var Tl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ol=Uint8Array.from([6,5,43,129,4,0,34]),Dl=Uint8Array.from([6,5,43,129,4,0,35]),Pl={ext:!0,kty:"EC",crv:"P-256"},Ll={ext:!0,kty:"EC",crv:"P-384"},Rl={ext:!0,kty:"EC",crv:"P-521"},Qo=32,Jo=48,es=66;function ts(t){let e=et(t);return Da(e)}function Da(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Qo*2+1)return n=H(e.subarray(r,r+Qo),"base64url"),o=H(e.subarray(r+Qo),"base64url"),new Yt({...Pl,key_ops:["verify"],x:n,y:o});if(e.byteLength===Jo*2+1)return n=H(e.subarray(r,r+Jo),"base64url"),o=H(e.subarray(r+Jo),"base64url"),new Yt({...Ll,key_ops:["verify"],x:n,y:o});if(e.byteLength===es*2+1)return n=H(e.subarray(r,r+es),"base64url"),o=H(e.subarray(r+es),"base64url"),new Yt({...Rl,key_ops:["verify"],x:n,y:o});throw new re(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Pa(t){return ft([Ae(Uint8Array.from([1])),ft([Nl(t.crv)],160),ft([mn(new ue(Uint8Array.from([4]),V(t.x??"","base64url"),V(t.y??"","base64url")))],161)]).subarray()}function Nl(t){if(t==="P-256")return Tl;if(t==="P-384")return Ol;if(t==="P-521")return Dl;throw new re(`Invalid curve ${t}`)}var Yt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Pa(this.jwk)),this._raw}toMultihash(){return Ne.digest(Ye(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return ce.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}async verify(e,r,n){return Ea(this.jwk,r,e,n)}};var yn=BigInt(4294967295),La=BigInt(32);function kl(t,e=!1){return e?{h:Number(t&yn),l:Number(t>>La&yn)}:{h:Number(t>>La&yn)|0,l:Number(t&yn)|0}}function Ra(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}=kl(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Fl=t=>t/2**32|0,Ul=t=>t>>>0;function Na(t,e,r,n){let o=Fl(r),s=Ul(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var rs=(t,e,r)=>t>>>r,ns=(t,e,r)=>t<<32-r|e>>>r,Bt=(t,e,r)=>t>>>r|e<<32-r,_t=(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 We(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var ka=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Fa=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Ua=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ma=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Ka=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Va=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function gn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var os=t=>t?`"${t}" `:"";function tt(t,e=""){if(typeof t!="number")throw new TypeError(os(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(os(e)+"expected integer >= 0, got "+t);return t}function De(t,e,r=""){if(gn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&tt(e,"length");let n=gn(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=os(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function bn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(tt(t.outputLen),tt(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var qa=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};function Wt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function xn(t,e){De(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ct(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function wn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function ke(t,e){return t<<32-e|t>>>e}var Ha=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Kl=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function En(t){if(De(t),Ha)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Kl[t[r]];return e}function za(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function vn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Ha)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=za(t.charCodeAt(s)),a=za(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 ss(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];De(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 Vl(t,e,r="opts"){return qa(t,"defaults"),e!==void 0&&qa(e,r),Object.assign(t,e)}function is(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Vl({},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 $a(t=32){tt(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 as=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function ja(t,e,r){return t&e^~t&r}function Ya(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=wn(this.buffer)}update(e){Wt(this),De(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=wn(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){Wt(this),xn(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)),Na(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:wn(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()}},Wa=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Za=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var ql=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]),lt=new Uint32Array(64),cs=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)lt[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=lt[l-15],d=lt[l-2],E=ke(h,7)^ke(h,18)^h>>>3,y=ke(d,17)^ke(d,19)^d>>>10;lt[l]=y+lt[l-7]+E+lt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=ke(a,6)^ke(a,11)^ke(a,25),d=f+h+ja(a,c,u)+ql[l]+lt[l]|0,y=(ke(n,2)^ke(n,13)^ke(n,22))+Ya(n,o,s)|0;f=u,u=c,c=a,a=i+d|0,i=s,s=o,o=n,n=d+y|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(){Ct(lt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ct(this.buffer)}},us=class extends cs{constructor(){super(32,Wa)}};var Ga=Ra(["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))),zl=Ga[0],Hl=Ga[1],dt=new Uint32Array(80),ht=new Uint32Array(80),fs=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:h,Gh:d,Gl:E,Hh:y,Hl:x}=this;return[e,r,n,o,s,i,a,c,u,f,l,h,d,E,y,x]}set(e,r,n,o,s,i,a,c,u,f,l,h,d,E,y,x){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=E|0,this.Hh=y|0,this.Hl=x|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)dt[g]=e.getUint32(r),ht[g]=e.getUint32(r+=4);for(let g=16;g<80;g++){let B=dt[g-15]|0,_=ht[g-15]|0,M=Bt(B,_,1)^Bt(B,_,8)^rs(B,_,7),K=_t(B,_,1)^_t(B,_,8)^ns(B,_,7),k=dt[g-2]|0,R=ht[g-2]|0,N=Bt(k,R,19)^Lr(k,R,61)^rs(k,R,6),z=_t(k,R,19)^Rr(k,R,61)^ns(k,R,6),D=Ua(K,z,ht[g-7],ht[g-16]),ee=Ma(D,M,N,dt[g-7],dt[g-16]);dt[g]=ee|0,ht[g]=D|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:d,Fl:E,Gh:y,Gl:x,Hh:v,Hl:I}=this;for(let g=0;g<80;g++){let B=Bt(l,h,14)^Bt(l,h,18)^Lr(l,h,41),_=_t(l,h,14)^_t(l,h,18)^Rr(l,h,41),M=l&d^~l&y,K=h&E^~h&x,k=Ka(I,_,K,Hl[g],ht[g]),R=Va(k,v,B,M,zl[g],dt[g]),N=k|0,z=Bt(n,o,28)^Lr(n,o,34)^Lr(n,o,39),D=_t(n,o,28)^Rr(n,o,34)^Rr(n,o,39),ee=n&s^n&a^s&a,O=o&i^o&c^i&c;v=y|0,I=x|0,y=d|0,x=E|0,d=l|0,E=h|0,{h:l,l:h}=We(u|0,f|0,R|0,N|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let T=ka(N,D,O);n=Fa(T,R,z,ee),o=T|0}({h:n,l:o}=We(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=We(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=We(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=We(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=We(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:E}=We(this.Fh|0,this.Fl|0,d|0,E|0),{h:y,l:x}=We(this.Gh|0,this.Gl|0,y|0,x|0),{h:v,l:I}=We(this.Hh|0,this.Hl|0,v|0,I|0),this.set(n,o,s,i,a,c,u,f,l,h,d,E,y,x,v,I)}roundClean(){Ct(dt,ht)}destroy(){this.destroyed=!0,Ct(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ls=class extends fs{constructor(){super(64,Za)}};var Zt=is(()=>new us,as(1));var ds=is(()=>new ls,as(3));function An(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 Z=(t,e,r)=>De(t,e,r),hs=tt;function Qa(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function pt(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 Tt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var kr=En,Pe=(...t)=>ss(...t),Gt=t=>vn(t),yt=gn,Ot=t=>$a(t),Sn=BigInt(0),Xa=BigInt(1),$l=t=>t?`"${t}" `:"";function Ie(t,e=""){if(typeof t!="boolean")throw new TypeError($l(e)+"expected boolean, got type="+typeof t);return t}function In(t){if(typeof t=="bigint"){if(!mt(t))throw new RangeError("positive bigint expected, got "+t)}else hs(t);return t}function gt(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=In(t).toString(16);return e.length&1?"0"+e:e}function Ja(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Sn:BigInt("0x"+t)}function Ze(t){return Ja(En(t))}function Dt(t){return Ja(En(_n(De(t)).reverse()))}function Bn(t,e){if(tt(e),e===0)throw new Error("zero output length is invalid");t=In(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return vn(n.padStart(r,"0"))}function ps(t,e){return Bn(t,e).reverse()}function _n(t){return Uint8Array.from(Z(t))}function mt(t){return typeof t=="bigint"&&Sn<=t}function ms(t,e,r){return mt(t)&&mt(e)&&mt(r)&&e<=t&&t<r}function Xt(t,e,r,n){if(!ms(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Qt(t){if(t<Sn)throw new Error("expected non-negative bigint, got "+t);return t===Sn?0:t.toString(2).length}var Ur=t=>(gt(t,"n"),(Xa<<BigInt(t))-Xa);function ec(t,e,r){if(tt(t,"hashLen"),tt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=x=>new Uint8Array(x),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...x)=>r(u,Pe(c,...x)),d=(x=o)=>{u=h(s,x),c=h(),x.length!==0&&(u=h(i,x),c=h())},E=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let x=0,v=[];for(;x<e;){c=h();let I=c.slice();v.push(I),x+=c.length}return Pe(...v)};return(x,v)=>{l(),d(x);let I;for(;(I=v(E()))===void 0;)d();return l(),I}}function Be(t,e={},r={},n="object"){pt(t,n),pt(e,"fields"),pt(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 le=BigInt(0),G=BigInt(1),bt=BigInt(2),nc=BigInt(3),ys=BigInt(4),oc=BigInt(5),jl=BigInt(7),sc=BigInt(8),Yl=BigInt(9),Wl=BigInt(15),ic=BigInt(16),Zl=BigInt("0x10000000000000000");function ne(t,e){if(e<=le)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=le?r:e+r}function ac(t,e,r){if(r<=G)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<le)throw new Error("invalid exponent, negatives unsupported");if(e===le)return G;if(e===G)return t;let n=t%r;if(n<le&&(n+=r),e<Zl){let a=G;for(;e>le;)e&G&&(a=a*n%r),n=n*n%r,e>>=G;return a}let o=[];for(;e>le;)o.push(Number(e&Wl)),e>>=ys;let s=new Array(16);s[0]=G,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 te(t,e,r){if(r<=G)throw new Error("pow2: expected modulus > 1, got "+r);if(e<le)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >le;)n*=n,n%=r;return n}function tc(t,e){if(t===le)throw new Error("invert: expected non-zero number");if(e<=G)throw new Error("invert: expected modulus > 1, got "+e);let r=ne(t,e),n=e,o=le,s=G;for(;r!==le;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==G)throw new Error("invert: does not exist");return ne(o,e)}function cc(t,e){if(e<=G)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ne(t,e);if(r===le)throw new Error("invertCt: expected non-zero number");let n=ac(r,e-bt,e);if(ne(r*n,e)!==G)throw new Error("invertCt: does not exist");return n}function gs(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function bs(t,e){if((t&G)===le)throw new Error(e+": expected odd modulus, got "+t)}function uc(t,e){let r=t,n=(r.ORDER+G)/ys,o=r.pow(e,n);return gs(r,o,e),o}function Gl(t,e){let r=t,n=(r.ORDER-oc)/sc,o=r.mul(e,bt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,bt),s),c=r.mul(i,r.sub(a,r.ONE));return gs(r,c,e),c}function Xl(t){let e=er(t),r=fc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+jl)/ic;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),h=u.mul(f,o),d=u.mul(f,s),E=u.eql(u.sqr(l),c),y=u.eql(u.sqr(h),c);f=u.cmov(f,l,E),l=u.cmov(d,h,y);let x=u.eql(u.sqr(l),c),v=u.cmov(f,l,x);return gs(u,v,c),v})}function fc(t){if(t<nc)throw new Error("sqrt is not defined for small field");bs(t,"tonelliShanks");let e=t-G,r=0;for(;e%bt===le;)e/=bt,r++;let n=bt,o=er(t);for(;Mr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return uc;let s=o.pow(n,e),i=(e+G)/bt;return function(c,u){let f=c;if(f.is0(u))return u;if(Mr(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,s),d=f.pow(u,e),E=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 y=1,x=f.sqr(d);for(;!f.eql(x,f.ONE);)if(y++,x=f.sqr(x),y===l)throw new Error("Cannot find square root");let v=G<<BigInt(l-y-1),I=f.pow(h,v);l=y,h=f.sqr(I),d=f.mul(d,h),E=f.mul(E,I)}return E}}function Ql(t){return bs(t,"Fp.sqrt"),t%ys===nc?uc:t%sc===oc?Gl:t%ic===Yl?Xl(t):fc(t)}var lc=(t,e)=>(ne(t,e)&G)===G,Jl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jt(t){if(pt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);gt(t.BYTES,"BYTES"),gt(t.BITS,"BITS");for(let e of Jl)Tt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=G)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Tn(t,e,r=!1){Jt(t),An(e,"nums"),Ie(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 Mr(t,e){Jt(t);let r=t;bs(r.ORDER,"FpLegendre");let n=(r.ORDER-G)/bt,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 ed(t,e){if(e!==void 0&&hs(e),t<=le)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=Qt(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 rc=new WeakMap,Cn=class{ORDER;BITS;BYTES;isLE;ZERO=le;ONE=G;_lengths;_mod;constructor(e,r={}){if(e<=G)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}=ed(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 ne(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return le<=e&&e<this.ORDER}is0(e){return e===le}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&G)===G}neg(e){return ne(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ne(e*e,this.ORDER)}add(e,r){return ne(e+r,this.ORDER)}sub(e,r){return ne(e-r,this.ORDER)}mul(e,r){return ne(e*r,this.ORDER)}pow(e,r){return ac(e,r,this.ORDER)}div(e,r){return ne(e*tc(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 tc(e,this.ORDER)}sqrt(e){let r=rc.get(this);return r||rc.set(this,r=Ql(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?ps(e,this.BYTES):Bn(e,this.BYTES)}fromBytes(e,r=!1){Z(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?Dt(e):Ze(e);if(a&&(c=ne(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Tn(this,e,!0)}cmov(e,r,n){return Ie(n,"condition"),n?r:e}};function er(t,e={}){return Object.freeze(Cn.prototype),new Cn(t,e)}function dc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=G)throw new Error("field order must be greater than 1");let e=Qt(t-G);return Math.ceil(e/8)}function On(t){let e=dc(t);return e+Math.ceil(e/2)}function Dn(t,e,r=!1){Z(t);let n=t.length,o=dc(e),s=Math.max(On(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Dt(t):Ze(t),a=ne(i,e-G)+G;return r?ps(a,o):Bn(a,o)}var Es=BigInt(0),Kr=BigInt(1),td=BigInt(4),xs=16,hc=128,rd=5,pc=2**31;function xt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Tt(e.fromAffine,"Point.fromAffine"),Tt(e.fromBytes,"Point.fromBytes"),Tt(e.fromHex,"Point.fromHex"),pt(e.BASE,"Point.BASE"),pt(e.ZERO,"Point.ZERO"),Jt(e.Fp),Jt(e.Fn)}function Pn(t,e){xt(t),yc(e,t);let r=Tn(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function nd(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 od(t,e){let r=t*(4*e+128);if(r>pc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+pc/2**20+" MiB")}function vs(t,e){if(t!==void 0){Tt(t,"randomBytes");try{let r=t(e);if(!yt(r)||r.length!==e)return}catch{return}return t}}function yc(t,e){An(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function sd(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):mt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var gc=new WeakMap;function ws(t){return gc.get(t)||1}function id(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 ad(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>Es;){let i=0;t&Kr&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=Kr}return s}function cd(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+=Kr),a.push(u)}if(t!==Es)throw new Error("invalid wnaf");return a}function ud(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 tr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){xt(e),this.randomBytes=vs(r,xs),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=cd(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],h=f*i,d=Math.abs(l)-1,E=s[h];for(let x=1;x<i;x++)E=x===d?s[h+x]:E;let y=E.negate();l===0?u=u.add(s[h]):c=c.add(l<0?y:E)}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),!ms(r,Kr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=ws(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+hc,s=this.randomBytes(xs);if(!yt(s)||s.length!==xs)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Ze(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=rd,s=1<<o,i=Ur(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),h=a[0];for(let d=1;d<s;d++)h=d===l?a[d]:h;u=u.add(h)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Kr?!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),!mt(r))throw new Error("invalid scalar");let o=ws(e);if(o===1||r>=this.Point.Fn.ORDER)return Ln(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),nd(r,this.bits);let n=Math.ceil((this.bits+hc)/r)+1;od(n*2**(r-1),this.Point.Fp.BYTES),gc.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return ws(e)!==1}};function Ln(t,e,r,n=!1){if(xt(t),yc(e,t),Ie(n,"allowOversized"),sd(r,t.Fn,n?t.Fn.ORDER**td:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>id(i,4)),s=r.map(i=>ad(i,4));return ud(t.ZERO,o,s)}function mc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Jt(e),e}else return er(t,{isLE:r})}function Rn(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`);Be(r);for(let c of["p","n","h"]){let u=e[c];if(!(mt(u)&&u!==Es))throw new Error(`CURVE.${c} must be positive bigint`)}let o=mc(e.p,r.Fp,n),s=mc(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 Nn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var kn=BigInt(0),Fn=BigInt(1),Un=BigInt(2),fd=BigInt(4),bc=BigInt(8);function ld(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={}){Be(e,{},{},"extraOpts");let r=e,n=Rn("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(Mr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Mr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Be(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Ot:r.randomBytes,u=Un<<BigInt(o.BYTES*8)-Fn;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:kn}}}:r.uvRatio;if(!ld(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let h=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,B=!1){let _=B?Fn:kn;return Xt("coordinate "+I,g,_,u),g}function E(I){if(!(I instanceof y))throw new Error("EdwardsPoint expected")}class y{static BASE=new y(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new y(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(g,B,_,M){this.X=d("x",g),this.Y=d("y",B),this.Z=d("z",_,!0),this.T=d("t",M),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof y)throw new Error("extended point not allowed");let{x:B,y:_}=g||{};return d("x",B),d("y",_),new y(B,_,o.ONE,o.mul(B,_))}static fromBytes(g,B=!1){let _=o.BYTES,{a:M,d:K}=i;g=_n(Z(g,_,"point")),Ie(B,"zip215");let k=_n(g),R=g[_-1];k[_-1]=R&-129;let N=Dt(k),z=B?u:o.ORDER;Xt("point.y",N,kn,z);let D=o.sqr(N),ee=o.sub(D,o.ONE),O=o.sub(o.mulN(K,D),M),{isValid:T,value:p}=l(ee,O);if(!T)throw new Error("bad point: invalid y coordinate");let b=f(p),S=(R&128)!==0;if(!B&&o.is0(p)&&S)throw new Error("bad point: x=0 and x_0=1");return S!==b&&(p=o.neg(p)),y.fromAffine({x:p,y:N})}static fromHex(g,B=!1){return y.fromBytes(Gt(g),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=6,B=!0){return v.setWindowSize(this,g),B||this.multiply(Un),this}assertValidity(){let g=this,{a:B,d:_}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:M,Y:K,Z:k,T:R}=g,N=o.sqr(M),z=o.sqr(K),D=o.sqr(k),ee=o.sqr(D),O=o.mul(N,B),T=o.mul(o.add(O,z),D),p=o.add(ee,o.mul(_,o.mul(N,z)));if(!o.eql(T,p))throw new Error("bad point: equation left != right (1)");let b=o.mul(M,K),S=o.mul(k,R);if(!o.eql(b,S))throw new Error("bad point: equation left != right (2)")}equals(g){E(g);let{X:B,Y:_,Z:M}=this,{X:K,Y:k,Z:R}=g,N=o.mul(B,R),z=o.mul(K,M),D=o.mul(_,R),ee=o.mul(k,M);return o.eql(N,z)&&o.eql(D,ee)}is0(){return this.equals(y.ZERO)}negate(){return new y(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:g,Y:B,Z:_}=this,M=o.sqr(g),K=o.sqr(B),k=o.mul(o.sqr(_),Un),R=h(M),N=o.addN(g,B),z=o.sub(o.subN(o.sqr(N),M),K),D=o.addN(R,K),ee=o.subN(D,k),O=o.subN(R,K),T=o.mul(z,ee),p=o.mul(D,O),b=o.mul(z,O),S=o.mul(ee,D);return new y(T,p,S,b)}add(g){E(g);let{d:B}=i,{X:_,Y:M,Z:K,T:k}=this,{X:R,Y:N,Z:z,T:D}=g,ee=o.mul(_,R),O=o.mul(M,N),T=o.mul(o.mulN(k,B),D),p=o.mul(K,z),b=o.sub(o.subN(o.mulN(o.addN(_,M),o.addN(R,N)),ee),O),S=o.subN(p,T),P=o.addN(p,T),w=o.sub(O,h(ee)),m=o.mul(b,S),A=o.mul(P,w),C=o.mul(b,w),F=o.mul(S,P);return new y(m,A,F,C)}subtract(g){return E(g),this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:_}=v.mulSecret(this,g,a,x);return x([B,_])[0]}multiplyUnsafe(g){if(!s.isValid(g))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return g===kn?y.ZERO:this.is0()||g===Fn?this:v.mulUnsafe(this,g,x)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return v.mulUnsafe(this,i.n).is0()}toAffine(g){let B=this,_=g;if(_!=null&&typeof _!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof _);let{X:M,Y:K,Z:k}=B,R=B.is0();_==null&&(_=R?o.create(bc):o.inv(k));let N=o.mul(M,_),z=o.mul(K,_),D=o.mul(k,_);if(R)return{x:o.ZERO,y:o.ONE};if(!o.eql(D,o.ONE))throw new Error("invZ was invalid");return{x:N,y:z}}clearCofactor(){return a===Fn?this:a===Un?this.double():a===fd?this.double().double():a===bc?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:g,y:B}=this.toAffine(),_=o.toBytes(B);return _[_.length-1]|=f(g)?128:0,_}toHex(){return kr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let x=I=>Pn(y,I),v=new tr(y,c);return v.bits>=6&&y.BASE.precompute(6),Object.freeze(y.prototype),Object.freeze(y),y}function wc(t,e,r={}){if(xt(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Be(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&&(gt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Ot:o.randomBytes,h=o.toMontgomery,d=o.toMontgomerySecret,E=o.adjustScalarBytes===void 0?O=>O:o.adjustScalarBytes,y=o.domain===void 0?(O,T,p)=>{if(Ie(p,"phflag"),T.length||p)throw new Error("Contexts/pre-hash are not supported");return O}:o.domain;function x(O){return c.create(Dt(O))}function v(O){let T=R.secretKey;Z(O,R.secretKey,"secretKey");let p=Z(n(O),2*T,"hashedSecretKey"),b=E(p.slice(0,T)),S=p.slice(T,2*T),P=x(b);return{head:b,prefix:S,scalar:P}}function I(O){let{head:T,prefix:p,scalar:b}=v(O),S=i.multiply(b),P=S.toBytes();return{head:T,prefix:p,scalar:b,point:S,pointBytes:P}}function g(O){return I(O).pointBytes}function B(O=Uint8Array.of(),...T){let p=Pe(...T);return x(n(y(p,Z(O,void 0,"context"),!!s)))}function _(O,T,p={}){Be(p,{},{},"options"),O=Z(O,void 0,"message"),s&&(O=s(O));let{prefix:b,scalar:S,pointBytes:P}=I(T),w=B(p.context,b,O),m=i.multiply(w).toBytes(),A=B(p.context,m,P,O),C=c.create(w+A*S);if(!c.isValid(C))throw new Error("sign failed: invalid s");let F=Pe(m,c.toBytes(C));return Z(F,R.signature,"result")}let M={zip215:o.zip215};function K(O,T,p,b=M){Be(b);let{context:S}=b,P=b.zip215===void 0?!!M.zip215:b.zip215,w=R.signature;O=Z(O,w,"signature"),T=Z(T,void 0,"message"),p=Z(p,R.publicKey,"publicKey"),P!==void 0&&Ie(P,"zip215"),s&&(T=s(T));let m=w/2,A=O.subarray(0,m),C=Dt(O.subarray(m,w)),F,U,W;try{F=t.fromBytes(p,P),U=t.fromBytes(A,P),W=i.multiplyUnsafe(C)}catch{return!1}if(!P&&F.isSmallOrder())return!1;let Y=B(S,A,p,T);return U.add(F.multiplyUnsafe(Y)).subtract(W).clearCofactor().is0()}let k=a.BYTES,R={secretKey:k,publicKey:k,signature:2*k,seed:k};function N(O){return O=O===void 0?l(R.seed):O,Z(O,R.seed,"seed")}function z(O){return yt(O)&&O.length===R.secretKey}function D(O,T){try{return!!t.fromBytes(O,T===void 0?M.zip215:T)}catch{return!1}}let ee={getExtendedPublicKey:I,randomSecretKey:N,isValidSecretKey:z,isValidPublicKey:D,toMontgomery(O){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(t.fromBytes(O))},toMontgomerySecret(O){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(O)}};return Object.freeze(R),Object.freeze(ee),Object.freeze({keygen:Nn(N,g),getPublicKey:g,sign:_,verify:K,utils:ee,Point:t,lengths:R})}var Ss=BigInt(1),Ec=BigInt(2);var dd=BigInt(5),hd=BigInt(8),As=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),pd={p:As,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:hd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function md(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=As,a=t*t%s*t%s,c=te(a,Ec,s)*a%s,u=te(c,Ss,s)*t%s,f=te(u,dd,s)*u%s,l=te(f,e,s)*f%s,h=te(l,r,s)*l%s,d=te(h,n,s)*h%s,E=te(d,o,s)*d%s,y=te(E,o,s)*d%s,x=te(y,e,s)*f%s;return{pow_p_5_8:te(x,Ec,s)*t%s,b2:a}}function Ac(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var vc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function yd(t,e){let r=As,n=ne(e*e*e,r),o=ne(n*n*e,r),s=md(t*o).pow_p_5_8,i=ne(t*n*s,r),a=ne(e*i*i,r),c=i,u=ne(i*vc,r),f=a===t,l=a===ne(-t,r),h=a===ne(-t*vc,r);return f&&(i=c),(l||h)&&(i=u),lc(i,r)&&(i=ne(-i,r)),{isValid:f||l,value:i}}var Is=xc(pd,{uvRatio:yd}),Sc=Is.Fp;function gd(t){let{y:e}=t;return Sc.toBytes(Sc.div(Ss+e,Ss-e))}function bd(t){let e=Is.Fp.BYTES;return De(t,e),Ac(ds(t.subarray(0,e))).subarray(0,e)}function xd(t){return wc(Is,ds,Object.assign({adjustScalarBytes:Ac,toMontgomery:gd,toMontgomerySecret:bd,zip215:!0},t))}var Ic=xd({});var Vr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Mn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Le={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Mn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Kn=32;var Bs,wd=(async()=>{try{return await Le.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Ed(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Le.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Le.get().subtle.verify({name:"Ed25519"},n,ve(e),ve(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function vd(t,e,r){return Ic.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Bc(t,e,r){return Bs==null&&(Bs=await wd),Bs?Ed(t,e,r):vd(t,e,r)}function Vn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var qn=class{type="Ed25519";raw;constructor(e){this.raw=_s(e,Kn)}toMultihash(){return Ne.digest(Ye(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return ce.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=Bc(this.raw,r,e);return Vn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Cs(t){return t=_s(t,Kn),new qn(t)}function _s(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new re(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var Ad=Math.pow(2,7),Id=Math.pow(2,14),Bd=Math.pow(2,21),Ts=Math.pow(2,28),Os=Math.pow(2,35),Ds=Math.pow(2,42),Ps=Math.pow(2,49),X=128,be=127;function _e(t){if(t<Ad)return 1;if(t<Id)return 2;if(t<Bd)return 3;if(t<Ts)return 4;if(t<Os)return 5;if(t<Ds)return 6;if(t<Ps)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function rr(t,e,r=0){switch(_e(t)){case 8:e[r++]=t&255|X,t/=128;case 7:e[r++]=t&255|X,t/=128;case 6:e[r++]=t&255|X,t/=128;case 5:e[r++]=t&255|X,t/=128;case 4:e[r++]=t&255|X,t>>>=7;case 3:e[r++]=t&255|X,t>>>=7;case 2:e[r++]=t&255|X,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function _d(t,e,r=0){switch(_e(t)){case 8:e.set(r++,t&255|X),t/=128;case 7:e.set(r++,t&255|X),t/=128;case 6:e.set(r++,t&255|X),t/=128;case 5:e.set(r++,t&255|X),t/=128;case 4:e.set(r++,t&255|X),t>>>=7;case 3:e.set(r++,t&255|X),t>>>=7;case 2:e.set(r++,t&255|X),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function Ls(t,e){let r=t[e],n=0;if(n+=r&be,r<X||(r=t[e+1],n+=(r&be)<<7,r<X)||(r=t[e+2],n+=(r&be)<<14,r<X)||(r=t[e+3],n+=(r&be)<<21,r<X)||(r=t[e+4],n+=(r&be)*Ts,r<X)||(r=t[e+5],n+=(r&be)*Os,r<X)||(r=t[e+6],n+=(r&be)*Ds,r<X)||(r=t[e+7],n+=(r&be)*Ps,r<X))return n;throw new RangeError("Could not decode varint")}function Cd(t,e){let r=t.get(e),n=0;if(n+=r&be,r<X||(r=t.get(e+1),n+=(r&be)<<7,r<X)||(r=t.get(e+2),n+=(r&be)<<14,r<X)||(r=t.get(e+3),n+=(r&be)<<21,r<X)||(r=t.get(e+4),n+=(r&be)*Ts,r<X)||(r=t.get(e+5),n+=(r&be)*Os,r<X)||(r=t.get(e+6),n+=(r&be)*Ds,r<X)||(r=t.get(e+7),n+=(r&be)*Ps,r<X))return n;throw new RangeError("Could not decode varint")}function nr(t,e,r=0){return e==null&&(e=ge(_e(t))),e instanceof Uint8Array?rr(t,e,r):_d(t,e,r)}function qr(t,e=0){return t instanceof Uint8Array?Ls(t,e):Cd(t,e)}var Ns=new Float32Array([-0]),wt=new Uint8Array(Ns.buffer);function Cc(t,e,r){Ns[0]=t,e[r]=wt[0],e[r+1]=wt[1],e[r+2]=wt[2],e[r+3]=wt[3]}function Tc(t,e){return wt[0]=t[e],wt[1]=t[e+1],wt[2]=t[e+2],wt[3]=t[e+3],Ns[0]}var ks=new Float64Array([-0]),xe=new Uint8Array(ks.buffer);function Oc(t,e,r){ks[0]=t,e[r]=xe[0],e[r+1]=xe[1],e[r+2]=xe[2],e[r+3]=xe[3],e[r+4]=xe[4],e[r+5]=xe[5],e[r+6]=xe[6],e[r+7]=xe[7]}function Dc(t,e){return xe[0]=t[e],xe[1]=t[e+1],xe[2]=t[e+2],xe[3]=t[e+3],xe[4]=t[e+4],xe[5]=t[e+5],xe[6]=t[e+6],xe[7]=t[e+7],ks[0]}var Td=BigInt(Number.MAX_SAFE_INTEGER),Od=BigInt(Number.MIN_SAFE_INTEGER),Te=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Pt;if(e<Td&&e>Od)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>Pc&&(o=0n,++n>Pc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Pt;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):Pt}},Pt=new Te(0,0);Pt.toBigInt=function(){return 0n};Pt.zzEncode=Pt.zzDecode=function(){return this};Pt.length=function(){return 1};var Pc=4294967296n;function Lc(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 Rc(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 Fs(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 Fe(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function zn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Us=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=ve(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,Fe(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 Fe(this,4);return zn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Fe(this,4);return zn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Fe(this,4);let e=Tc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Fe(this,4);let e=Dc(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 Fe(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Rc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Fe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Fe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Te(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Fe(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 Fe(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 Fe(this,8);let e=zn(this.buf,this.pos+=4),r=zn(this.buf,this.pos+=4);return new Te(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ls(this.buf,this.pos);return this.pos+=_e(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function zr(t){return new Us(t instanceof Uint8Array?t:t.subarray())}function Ue(t,e,r){let n=zr(t);return e.decode(n,void 0,r)}function Ms(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return ge(i);o+i>e&&(n=ge(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Lt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Ks(){}var qs=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Dd=Ms();function Pd(t){return globalThis.Buffer!=null?ge(t):Dd(t)}var $r=class{len;head;tail;states;constructor(){this.len=0,this.head=new Lt(Ks,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Lt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new zs((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(Hn,10,Te.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Te.fromBigInt(e);return this._push(Hn,r.length(),r)}uint64Number(e){return this._push(rr,_e(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Te.fromBigInt(e).zzEncode();return this._push(Hn,r.length(),r)}sint64Number(e){let r=Te.fromNumber(e).zzEncode();return this._push(Hn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Vs,1,e?1:0)}fixed32(e){return this._push(Hr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Te.fromBigInt(e);return this._push(Hr,4,r.lo)._push(Hr,4,r.hi)}fixed64Number(e){let r=Te.fromNumber(e);return this._push(Hr,4,r.lo)._push(Hr,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(Oc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Vs,1,0):this.uint32(r)._push(Rd,r,e)}string(e){let r=Lc(e);return r!==0?this.uint32(r)._push(Fs,r,e):this._push(Vs,1,0)}fork(){return this.states=new qs(this),this.head=this.tail=new Lt(Ks,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 Lt(Ks,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=Pd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Vs(t,e,r){e[r]=t&255}function Ld(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var zs=class extends Lt{next;constructor(e,r){super(Ld,e,r),this.next=void 0}};function Hn(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 Hr(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 Rd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&($r.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Nd,e,t),this},$r.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(kd,e,t),this});function Nd(t,e,r){e.set(t,r)}function kd(t,e,r){t.length<40?Fs(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(V(t),r)}function Hs(){return new $r}function Me(t,e){let r=Hs();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ke(t,e,r){let n=zr(t);yield*e.stream(n,void 0,"$",r)}var $n={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function jn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function $s(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return jn("enum",$n.VARINT,r,n,o)}function Ve(t,e,r){return jn("message",$n.LENGTH_DELIMITED,t,e,r)}var Ge=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var oe;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(oe||(oe={}));var js;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(js||(js={}));(function(t){t.codec=()=>$s(js)})(oe||(oe={}));var Xe;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),oe.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=oe.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:oe.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 Me(s,t.codec())}t.encode=r;function n(s,i){return Ue(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Xe||(Xe={}));var Ys;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),oe.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=oe.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:oe.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 Me(s,t.codec())}t.encode=r;function n(s,i){return Ue(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Ys||(Ys={}));var Yr={};Se(Yr,{MAX_RSA_KEY_SIZE:()=>Ws,generateRSAKeyPair:()=>Kc,jwkToJWKKeyPair:()=>Vc,jwkToPkcs1:()=>Kd,jwkToPkix:()=>Qs,jwkToRSAPrivateKey:()=>ri,pkcs1MessageToJwk:()=>Gs,pkcs1MessageToRSAPrivateKey:()=>Js,pkcs1ToJwk:()=>Md,pkcs1ToRSAPrivateKey:()=>Mc,pkixMessageToJwk:()=>Xs,pkixMessageToRSAPublicKey:()=>ti,pkixToJwk:()=>Vd,pkixToRSAPublicKey:()=>ei});var or=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Yr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return de.createV1(114,this._multihash)}toString(){return ce.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}verify(e,r,n){return Uc(this.jwk,r,e,n)}},jr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Yr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}sign(e,r){return Fc(this.jwk,e,r)}};var Ws=8192,Zs=18,Fd=1062,Ud=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Md(t){let e=et(t);return Gs(e)}function Gs(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 Kd(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 re("JWK was missing components");return ft([Ae(Uint8Array.from([0])),Ae(V(t.n,"base64url")),Ae(V(t.e,"base64url")),Ae(V(t.d,"base64url")),Ae(V(t.p,"base64url")),Ae(V(t.q,"base64url")),Ae(V(t.dp,"base64url")),Ae(V(t.dq,"base64url")),Ae(V(t.qi,"base64url"))]).subarray()}function Vd(t){let e=et(t,{offset:0});return Xs(e)}function Xs(t){let e=et(t[1],{offset:0});return{kty:"RSA",n:H(e[0],"base64url"),e:H(e[1],"base64url")}}function Qs(t){if(t.n==null||t.e==null)throw new re("JWK was missing components");return ft([Ud,mn(ft([Ae(V(t.n,"base64url")),Ae(V(t.e,"base64url"))]))]).subarray()}function Mc(t){let e=et(t);return Js(e)}function Js(t){let e=Gs(t);return ri(e)}function ei(t,e){if(t.byteLength>=Fd)throw new qt("Key size is too large");let r=et(t,{offset:0});return ti(r,t,e)}function ti(t,e,r){let n=Xs(t);if(r==null){let o=Zt(Xe.encode({Type:oe.RSA,Data:e}));r=$e(Zs,o)}return new or(n,r)}function ri(t){if(zc(t)>Ws)throw new re("Key size is too large");let e=Vc(t),r=Zt(Xe.encode({Type:oe.RSA,Data:Qs(e.publicKey)})),n=$e(Zs,r);return new jr(e.privateKey,new or(e.publicKey,n))}async function Kc(t){if(t>Ws)throw new re("Key size is too large");let e=await qc(t),r=Zt(Xe.encode({Type:oe.RSA,Data:Qs(e.publicKey)})),n=$e(Zs,r);return new jr(e.privateKey,new or(e.publicKey,n))}function Vc(t){if(t==null)throw new re("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function qc(t,e){let r=await Le.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 qd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Fc(t,e,r){let n=await Le.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Le.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,ve(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Uc(t,e,r,n){let o=await Le.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Le.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,ve(e),ve(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function qd(t,e){if(t.privateKey==null||t.publicKey==null)throw new re("Private and public key are required");let r=await Promise.all([Le.get().subtle.exportKey("jwk",t.privateKey),Le.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function zc(t){if(t.kty!=="RSA")throw new re("invalid key type");if(t.n==null)throw new re("invalid key modulus");return V(t.n,"base64url").length*8}var Yn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(bn(e),De(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),Ct(o)}update(e){return Wt(this),this.iHash.update(e),this}digestInto(e){Wt(this),xn(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()}},Hc=(()=>{let t=((e,r,n)=>new Yn(e,r).update(n).digest());return t.create=(e,r)=>new Yn(e,r),t})();var zd=BigInt(0),ni=class extends Error{constructor(e=""){super(e)}},rt={Err:ni,_tlv:{encode:(t,e)=>{let{Err:r}=rt;if(gt(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Qa(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}=rt;e=Z(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}=rt;if(In(t),t<zd)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}=rt;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 Ze(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=rt,o=Z(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=rt;Be(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)}},oi=(Object.freeze(rt._tlv),Object.freeze(rt._int),Object.freeze(rt));var $c=(t,e)=>(t+(t>=0?e:-e)/jc)/e;function Hd(t,e,r){Xt("scalar",t,nt,r);let[[n,o],[s,i]]=e,a=$c(i*t,r),c=$c(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,l=u<nt,h=f<nt;l&&(u=-u),h&&(f=-f);let d=Ur(Math.ceil(Qt(r)/2))+Rt;if(u<nt||u>=d||f<nt||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function ai(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function si(t,e){Be(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ie(r.lowS,"lowS"),Ie(r.prehash,"prehash"),r.format!==void 0&&ai(r.format),r}var nt=BigInt(0),Rt=BigInt(1),jc=BigInt(2),ii=BigInt(3),$d=BigInt(4);function Yc(t,e={}){let r=Rn("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Be(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u}=e,f=e.randomBytes===void 0?Ot: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 l=Zc(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(T,p,b){if(u&&p.is0())return Uint8Array.of(0);let{x:S,y:P}=p.toAffine(),w=n.toBytes(S);if(Ie(b,"isCompressed"),b){h();let m=!n.isOdd(P);return Pe(Wc(m),w)}else return Pe(Uint8Array.of(4),w,n.toBytes(P))}function E(T){Z(T,void 0,"Point");let{publicKey:p,publicKeyUncompressed:b}=l,S=T.length,P=T[0],w=T.subarray(1);if(u&&S===1&&P===0)return{x:n.ZERO,y:n.ZERO};if(S===p&&(P===2||P===3)){let m=n.fromBytes(w);if(!n.isValid(m))throw new Error("bad point: is not on curve, wrong x");let A=g(m),C;try{C=n.sqrt(A)}catch(W){let Y=W instanceof Error?": "+W.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}h();let F=n.isOdd(C);return(P&1)===1!==F&&(C=n.neg(C)),{x:m,y:C}}else if(S===b&&P===4){let m=n.BYTES,A=n.fromBytes(w.subarray(0,m)),C=n.fromBytes(w.subarray(m,m*2));if(!B(A,C))throw new Error("bad point: is not on curve");return{x:A,y:C}}else throw new Error(`bad point: got length ${S}, expected compressed=${p} or uncompressed=${b}`)}let y=e.toBytes===void 0?d:e.toBytes,x=e.fromBytes===void 0?E:e.fromBytes,v=n.mul(s.b,ii),I=n.is0(s.a)?T=>n.ZERO:T=>n.mul(s.a,T);function g(T){let p=n.sqr(T),b=n.mul(p,T);return n.add(n.add(b,n.mul(T,s.a)),s.b)}function B(T,p){let b=n.sqr(p),S=g(T);return n.eql(b,S)}if(!B(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let _=n.mul(n.pow(s.a,ii),$d),M=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(_,M)))throw new Error("bad curve params: a or b");function K(T,p,b=!1){if(!n.isValid(p)||b&&n.is0(p))throw new Error(`bad point coordinate ${T}`);return p}function k(T){if(!(T instanceof D))throw new Error("Weierstrass Point expected")}function R(T){if(!c||!c.basises)throw new Error("no endo");return Hd(T,c.basises,o.ORDER)}function N(T,p,b,S){if(!o.isValid(S))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:P,k1:w,k2neg:m,k2:A}=R(S),C=new D(n.mul(b.X,c.beta),b.Y,b.Z);T.push(P?b.negate():b,m?C.negate():C),p.push(w,A)}else T.push(b),p.push(S)}let z=new WeakSet;class D{static BASE=new D(s.Gx,s.Gy,n.ONE);static ZERO=new D(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,b,S){this.X=K("x",p),this.Y=K("y",b,!0),this.Z=K("z",S),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:b,y:S}=p||{};if(!p||!n.isValid(b)||!n.isValid(S))throw new Error("invalid affine point");if(p instanceof D)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(S)?D.ZERO:new D(b,S,n.ONE)}static fromBytes(p){let b=D.fromAffine(x(Z(p,void 0,"point")));return b.assertValidity(),b}static fromHex(p){return D.fromBytes(Gt(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,b=!0){return O.setWindowSize(this,p),b||this.multiply(ii),this}assertValidity(){let p=this;if(p.is0()){if(e.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(z.has(p))return;let{x:b,y:S}=p.toAffine();if(!n.isValid(b)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!B(b,S))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");z.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){k(p);let{X:b,Y:S,Z:P}=this,{X:w,Y:m,Z:A}=p,C=n.eql(n.mul(b,A),n.mul(w,P)),F=n.eql(n.mul(S,A),n.mul(m,P));return C&&F}negate(){return new D(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:b,Z:S}=this,P=n.ZERO,w=n.ZERO,m=n.ZERO,A=n.mul(p,p),C=n.mul(b,b),F=n.mul(S,S),U=n.mul(p,b);return U=n.add(U,U),m=n.mul(p,S),m=n.add(m,m),P=I(m),w=n.mul(v,F),w=n.add(P,w),P=n.sub(C,w),w=n.add(C,w),w=n.mul(P,w),P=n.mul(U,P),m=n.mul(v,m),F=I(F),U=n.sub(A,F),U=I(U),U=n.add(U,m),m=n.add(A,A),A=n.add(m,A),A=n.add(A,F),A=n.mul(A,U),w=n.add(w,A),F=n.mul(b,S),F=n.add(F,F),A=n.mul(F,U),P=n.sub(P,A),m=n.mul(F,C),m=n.add(m,m),m=n.add(m,m),new D(P,w,m)}add(p){k(p);let{X:b,Y:S,Z:P}=this,{X:w,Y:m,Z:A}=p,C=n.ZERO,F=n.ZERO,U=n.ZERO,W=n.mul(b,w),Y=n.mul(S,m),se=n.mul(P,A),Ee=n.add(b,S),ie=n.add(w,m);Ee=n.mul(Ee,ie),ie=n.add(W,Y),Ee=n.sub(Ee,ie),ie=n.add(b,P);let ye=n.add(w,A);return ie=n.mul(ie,ye),ye=n.add(W,se),ie=n.sub(ie,ye),ye=n.add(S,P),C=n.add(m,A),ye=n.mul(ye,C),C=n.add(Y,se),ye=n.sub(ye,C),U=I(ie),C=n.mul(v,se),U=n.add(C,U),C=n.sub(Y,U),U=n.add(Y,U),F=n.mul(C,U),Y=n.add(W,W),Y=n.add(Y,W),se=I(se),ie=n.mul(v,ie),Y=n.add(Y,se),se=n.sub(W,se),se=I(se),ie=n.add(ie,se),W=n.mul(Y,ie),F=n.add(F,W),W=n.mul(ye,ie),C=n.mul(Ee,C),C=n.sub(C,W),W=n.mul(Ee,Y),U=n.mul(ye,U),U=n.add(U,W),new D(C,F,U)}subtract(p){return k(p),this.add(p.negate())}is0(){return this.equals(D.ZERO)}multiply(p){if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:b,f:S}=O.mulSecret(this,p,i,ee);return ee([b,S])[0]}multiplyUnsafe(p){let b=this,S=p;if(!o.isValid(S))throw new RangeError("invalid scalar: out of range");if(S===nt||b.is0())return D.ZERO;if(S===Rt)return b;if(O.hasWindowSize(this))return O.mulUnsafe(b,S,ee);let P=[],w=[];return N(P,w,b,S),Ln(D,P,w)}mulAddUnsafe(p,b,S){k(b);let P=[],w=[];return N(P,w,this,p),N(P,w,b,S),Ln(D,P,w)}toAffine(p){let b=this,S=p;if(S!=null&&!n.isValid(S))throw new RangeError('"invertedZ" expected valid field element');let{X:P,Y:w,Z:m}=b;if(n.eql(m,n.ONE))return{x:P,y:w};let A=b.is0();S==null&&(S=A?n.ONE:n.inv(m));let C=n.mul(P,S),F=n.mul(w,S),U=n.mul(m,S);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(U,n.ONE))throw new Error("invZ was invalid");return{x:C,y:F}}isTorsionFree(){let{isTorsionFree:p}=e;return i===Rt?!0:p?p(D,this):O.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=e;return i===Rt?this:p?p(D,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Rt?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Ie(p,"isCompressed"),this.assertValidity(),y(D,this,p)}toHex(p=!0){return kr(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let ee=T=>Pn(D,T),O=new tr(D,f);return O.bits>=6&&D.BASE.precompute(6),Object.freeze(D.prototype),Object.freeze(D),D}function Wc(t){return Uint8Array.of(t?2:3)}function Zc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function jd(t,e={}){xt(t);let{Fn:r}=t,n=e.randomBytes===void 0?Ot:e.randomBytes,o=Object.assign(Zc(t.Fp,r),{seed:Math.max(On(r.ORDER),16)});function s(d){try{let E=r.fromBytes(d);return r.isValidNot0(E)}catch{return!1}}function i(d,E){let{publicKey:y,publicKeyUncompressed:x}=o;try{let v=d.length;return E===!0&&v!==y||E===!1&&v!==x?!1:!!t.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(o.seed):d,Dn(Z(d,o.seed,"seed"),r.ORDER)}function c(d,E=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(E)}function u(d){let{secretKey:E,publicKey:y,publicKeyUncompressed:x}=o,v=r._lengths;if(!yt(d))return;let I=Z(d,void 0,"key").length,g=I===y||I===x,B=I===E||!!v?.includes(I);if(!(g&&B))return g}function f(d,E,y=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(E)===!1)throw new Error("second arg must be public key");let x=r.fromBytes(d);return t.fromBytes(E).multiply(x).toBytes(y)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},h=Nn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:t,utils:l,lengths:o})}function Gc(t,e,r={}){xt(t);let n=e;bn(n),Be(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?Ot:o.randomBytes,i=o.hmac===void 0?(w,m)=>Hc(n,w,m):o.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:f}=c,l=On(u),h=vs(s,l),{keygen:d,getPublicKey:E,getSharedSecret:y,utils:x,lengths:v}=jd(t,o),I={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=u*jc+Rt<a.ORDER;function B(w){let m=u>>Rt;return w>m}function _(w,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return m}function M(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function K(w,m,A){return M(),(w===A?0:2)|Number(a.isOdd(m))}function k(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function R(w,m){ai(m);let A=v.signature,C=m==="compact"?A:m==="recovered"?A+1:void 0;return Z(w,C)}class N{r;s;recovery;constructor(m,A,C){if(this.r=_("r",m),this.s=_("s",A),C!=null){if(k(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(m,A=I.format){R(m,A);let C;if(A==="der"){let{r:Y,s:se}=oi.toSig(Z(m));return new N(Y,se)}A==="recovered"&&(C=m[0],A="compact",m=m.subarray(1));let F=v.signature/2,U=m.subarray(0,F),W=m.subarray(F,F*2);return new N(c.fromBytes(U),c.fromBytes(W),C)}static fromHex(m,A){return this.fromBytes(Gt(m),A)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new N(this.r,this.s,m)}recoverPublicKey(m){let{r:A,s:C}=this,F=this.assertRecovery(),U=F===2||F===3?A+u:A;if(!a.isValid(U))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let W=a.toBytes(U),Y=t.fromBytes(Pe(Wc((F&1)===0),W)),se=c.inv(U),Ee=D(Z(m,void 0,"msgHash")),ie=c.create(-Ee*se),ye=c.create(C*se),ze=t.BASE.mulAddUnsafe(ie,Y,ye);if(ze.is0())throw new Error("invalid recovery: point at infinify");return ze.assertValidity(),ze}hasHighS(){return B(this.s)}toBytes(m=I.format){if(ai(m),m==="der")return Gt(oi.hexFromSig(this));let{r:A,s:C}=this,F=c.toBytes(A),U=c.toBytes(C);return m==="recovered"?(k(),Pe(Uint8Array.of(this.assertRecovery()),F,U)):Pe(F,U)}toHex(m){return kr(this.toBytes(m))}}Object.freeze(N.prototype),Object.freeze(N);let z=o.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let A=Ze(m),C=m.length*8-f;return C>0?A>>BigInt(C):A}:o.bits2int,D=o.bits2int_modN===void 0?function(m){return c.create(z(m))}:o.bits2int_modN,ee=Ur(f);function O(w){return Xt("num < 2^"+f,w,nt,ee),c.toBytes(w)}function T(w,m){return Z(w,void 0,"message"),m?Z(n(w),void 0,"prehashed message"):w}function p(w,m,A){let{lowS:C,prehash:F,extraEntropy:U}=si(A,I);w=T(w,F);let W=D(w),Y=c.fromBytes(m);if(!c.isValidNot0(Y))throw new Error("invalid private key");let se=[O(Y),O(W)];if(U!=null&&U!==!1){let ze=U===!0?s(v.secretKey):U;se.push(Z(ze,void 0,"extraEntropy"))}let Ee=Pe(...se),ie=W;function ye(ze){let Vt=z(ze);if(!c.isValidNot0(Vt))return;let vr=t.BASE.multiply(Vt).toAffine(),at=c.create(vr.x);if(at===nt)return;let He;if(h!==void 0){let Sr=Ze(Dn(h(l),u)),tf=c.inv(c.mul(Sr,Vt)),rf=c.mul(Sr,ie),nf=c.mul(Sr,Y);He=c.create(tf*c.create(rf+nf*at))}else{let Sr=cc(Vt,u);He=c.create(Sr*c.create(ie+at*Y))}if(He===nt)return;let Ao=K(vr.x,vr.y,at),na=He;return C&&B(He)&&(na=c.neg(He),Ao^=1),new N(at,na,g?void 0:Ao)}return{seed:Ee,k2sig:ye}}function b(w,m,A={}){let{seed:C,k2sig:F}=p(w,m,A);return ec(n.outputLen,c.BYTES,i)(C,F).toBytes(A.format)}function S(w,m,A,C={}){let{lowS:F,prehash:U,format:W}=si(C,I);if(A=Z(A,void 0,"publicKey"),m=T(m,U),!yt(w)){let Y=w instanceof N?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+Y)}R(w,W);try{let Y=N.fromBytes(w,W),se=t.fromBytes(A);if(F&&Y.hasHighS())return!1;let{r:Ee,s:ie}=Y,ye=D(m),ze=c.inv(ie),Vt=c.create(ye*ze),vr=c.create(Ee*ze),at=t.BASE.mulAddUnsafe(Vt,se,vr);if(at.is0())return!1;let He=at.toAffine();return!(c.create(He.x)!==Ee||W==="recovered"&&Y.recovery!==K(He.x,He.y,Ee))}catch{return!1}}function P(w,m,A={}){let{prehash:C}=si(A,I);return m=T(m,C),N.fromBytes(w,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:d,getPublicKey:E,getSharedSecret:y,utils:x,lengths:v,Point:t,sign:b,verify:S,recoverPublicKey:P,Signature:N,hash:n})}var ui={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Yd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Xc=BigInt(2);function Wd(t){let e=ui.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=te(f,r,e)*f%e,h=te(l,r,e)*f%e,d=te(h,Xc,e)*u%e,E=te(d,o,e)*d%e,y=te(E,s,e)*E%e,x=te(y,a,e)*y%e,v=te(x,c,e)*x%e,I=te(v,a,e)*y%e,g=te(I,r,e)*f%e,B=te(g,i,e)*E%e,_=te(B,n,e)*u%e,M=te(_,Xc,e);if(!ci.eql(ci.sqr(M),t))throw new Error("Cannot find square root");return M}var ci=er(ui.p,{sqrt:Wd}),Zd=Yc(ui,{Fp:ci,endo:Yd}),sr=Gc(Zd,Zt);function Qc(t,e,r,n){let o=Tr.digest(r instanceof Uint8Array?r:r.subarray());if(Vn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),sr.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Vr(String(s))});try{return n?.signal?.throwIfAborted(),sr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new Vr(String(s))}}var Wn=class{type="secp256k1";raw;_key;constructor(e){this._key=eu(e),this.raw=Jc(this._key)}toMultihash(){return Ne.digest(Ye(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return ce.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}verify(e,r,n){return Qc(this._key,r,e,n)}};function fi(t){return new Wn(t)}function Jc(t){return sr.Point.fromBytes(t).toBytes()}function eu(t){try{return sr.Point.fromBytes(t),t}catch(e){throw new qt(String(e))}}function ir(t,e){let{Type:r,Data:n}=Xe.decode(t),o=n??new Uint8Array;switch(r){case oe.RSA:return ei(o,e);case oe.Ed25519:return Cs(o);case oe.secp256k1:return fi(o);case oe.ECDSA:return ts(o);default:throw new St}}function tu(t){let{Type:e,Data:r}=Xe.decode(t.digest),n=r??new Uint8Array;switch(e){case oe.Ed25519:return Cs(n);case oe.secp256k1:return fi(n);case oe.ECDSA:return ts(n);default:throw new St}}function Ye(t){return Xe.encode({Type:oe[t.type],Data:t.raw})}var Wr;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((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:he(0),payloadType:he(0),payload:he(0),signature:he(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 Me(s,t.codec())}t.encode=r;function n(s,i){return Ue(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Wr||(Wr={}));var Zn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var Qe=class t{static createFromProtobuf=e=>{let r=Wr.decode(e),n=ir(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=ru(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 Zn("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=Wr.encode({publicKey:Ye(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:fe(this.marshal(),e.marshal())}async validate(e,r){let n=ru(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},ru=(t,e,r)=>{let n=V(t),o=nr(n.byteLength),s=nr(e.length),i=nr(r.length);return new ue(o,n,s,e,i,r)};var nu=Symbol.for("nodejs.util.inspect.custom"),Gd=114,Zr=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()})`}[Bo]=!0;toString(){return this.string==null&&(this.string=ce.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return de.createV1(Gd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return fe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return fe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[nu](){return`PeerId(${this.toString()})`}},Gr=class extends Zr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Xr=class extends Zr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Qr=class extends Zr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Xd=2336,Jr=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ne.digest(V(this.url))}[nu](){return`PeerId(${this.url})`}[Bo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return de.createV1(Xd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=H(e)),e.toString()===this.toString())}};var Qd=114,ou=2336;function su(t){if(t.type==="Ed25519")return new Xr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Qr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Gr({multihash:t.toCID().multihash,publicKey:t});throw new St}function li(t){if(eh(t))return new Gr({multihash:t});if(Jd(t))try{let e=tu(t);if(e.type==="Ed25519")return new Xr({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Qr({multihash:t,publicKey:e})}catch{let r=H(t.digest);return new Jr(new URL(r))}throw new fn("Supplied PeerID Multihash is invalid")}function Gn(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Qd&&t.code!==ou)throw new un("Supplied PeerID CID is invalid");if(t.code===ou){let e=H(t.multihash.digest);return new Jr(new URL(e))}return li(t.multihash)}function Jd(t){return t.code===Ne.code}function eh(t){return t.code===Tr.code}var me=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ot=class extends Error{static name="ValidationError";name="ValidationError"},Xn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Qn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Jn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var iu=45,th=15,ar=new Jn;function eo(t){if(!(t.length>th))return ar.new(t).parseWith(()=>ar.readIPv4Addr())}function to(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>iu))return ar.new(t).parseWith(()=>ar.readIPv6Addr())}function cr(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>iu)return;let r=ar.new(t).parseWith(()=>ar.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 ur(t){return!!eo(t)}function ro(t){return!!to(t)}function hi(t){return e=>H(e,t)}function pi(t){return e=>V(e,t)}function fr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Nt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function au(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=Nt(n);return je([r,o],r.length+o.length)}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!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=ut.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=Nt(n);return je([r,o],r.length+o.length)}function mi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=H(e,"base32"),o=fr(r);return`${n}:${o}`}var yi=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 me("Invalid byte value in IP address");e[n]=o}),e},uu=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=ur(r[n]),i;s&&(i=yi(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 me("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},fu=function(t){if(t.byteLength!==4)throw new me("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},lu=function(t){if(t.byteLength!==16)throw new me("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 me(`Invalid IPv6 address "${r}"`)}};function du(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new me(`Invalid IPv6 address "${t}"`)}}var di=Object.values(Or).map(t=>t.decoder),rh=(function(){let t=di[0].or(di[1]);return di.slice(2).forEach(e=>t=t.or(e)),t})();function hu(t){return rh.decode(t)}function pu(t){return e=>t.encoder.encode(e)}function nh(t){if(parseInt(t).toString()!==t)throw new ot("Value must be an integer")}function oh(t){if(t<0)throw new ot("Value must be a positive integer, or zero")}function sh(t){return e=>{if(e>t)throw new ot(`Value must be smaller than or equal to ${t}`)}}function ih(...t){return e=>{for(let r of t)r(e)}}var en=ih(nh,oh,sh(65535));var pe=-1,gi=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 Qn(`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)}))}},it=new gi,wh=[{code:4,name:"ip4",size:32,valueToBytes:yi,bytesToValue:fu,validate:t=>{if(!ur(t))throw new ot(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Nt,bytesToValue:fr,validate:en},{code:273,name:"udp",size:16,valueToBytes:Nt,bytesToValue:fr,validate:en},{code:33,name:"dccp",size:16,valueToBytes:Nt,bytesToValue:fr,validate:en},{code:41,name:"ip6",size:128,valueToBytes:uu,bytesToValue:lu,stringToValue:du,validate:t=>{if(!ro(t))throw new ot(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:pe},{code:43,name:"ipcidr",size:8,bytesToValue:hi("base10"),valueToBytes:pi("base10")},{code:53,name:"dns",size:pe},{code:54,name:"dns4",size:pe},{code:55,name:"dns6",size:pe},{code:56,name:"dnsaddr",size:pe},{code:132,name:"sctp",size:16,valueToBytes:Nt,bytesToValue:fr,validate:en},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:pe,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:pe,bytesToValue:hi("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?pi("base58btc")(t):de.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:mi,valueToBytes:au},{code:445,name:"onion3",size:296,bytesToValue:mi,valueToBytes:cu},{code:446,name:"garlic64",size:pe},{code:447,name:"garlic32",size:pe},{code:448,name:"tls"},{code:449,name:"sni",size:pe},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:pe,bytesToValue:pu(qo),valueToBytes:hu},{code:480,name:"http"},{code:481,name:"http-path",size:pe,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:pe}];wh.forEach(t=>{it.addProtocol(t)});function mu(t){let e=[],r=0;for(;r<t.length;){let n=qr(t,r),o=it.getProtocol(n),s=_e(n),i=Eh(o,t,r+s),a=0;i>0&&o.size===pe&&(a=_e(i));let c=s+a+i,u={code:n,name:o.name,bytes:ve(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 yu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=it.getProtocol(n.code),s=_e(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===pe&&(c=_e(a)));let u=new Uint8Array(s+c+a),f=0;rr(n.code,u,f),f+=s,i!=null&&(o.size===pe&&(rr(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return je(r,e)}function gu(t){if(t.charAt(0)!=="/")throw new me('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=it.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 me(`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 me(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new me("Incomplete multiaddr");return e}function bu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=it.getProtocol(e.code);if(r==null)throw new me(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Eh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:qr(e,r)}var vh=Symbol.for("nodejs.util.inspect.custom"),Pi=Symbol.for("@multiformats/multiaddr");function Sh(t){if(t==null&&(t="/"),xu(t))return t.getComponents();if(t instanceof Uint8Array)return mu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),gu(t);if(Array.isArray(t))return t;throw new me("Must be a string, Uint8Array, Component[], or another Multiaddr")}var co=class t{[Pi]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Sh(e),r.validate!==!1&&Ah(this)}get bytes(){return this.#r==null&&(this.#r=yu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=bu(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 Xn(`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 fe(this.bytes,e.bytes)}[vh](){return`Multiaddr(${this.toString()})`}};function Ah(t){t.getComponents().forEach(e=>{let r=it.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function xu(t){return!!t?.[Pi]}function rn(t){return new co(t)}var wu="libp2p-peer-record",Eu=Uint8Array.from([3,1]);var nn;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=Ve((l,h,d={})=>{d.lengthDelimited!==!1&&h.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(h.uint32(10),h.bytes(l.multiaddr)),d.lengthDelimited!==!1&&h.ldelim()},(l,h,d={})=>{let E={multiaddr:he(0)},y=h==null?l.len:l.pos+h;for(;l.pos<y;){let x=l.uint32();x>>>3===1?E.multiaddr=l.bytes():l.skipType(x&7)}return E},function*(l,h,d,E={}){let y=h==null?l.len:l.pos+h;for(;l.pos<y;){let x=l.uint32();x>>>3===1?yield{field:`${d}.multiaddr`,value:l.bytes()}:l.skipType(x&7)}})),a);function c(l){return Me(l,i.codec())}i.encode=c;function u(l,h){return Ue(l,i.codec(),h)}i.decode=u;function f(l,h){return Ke(l,i.codec(),h)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=Ve((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:he(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 Ge('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let h=i.uint32();switch(h>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Ge('Streaming decode error - repeated field "addresses" had too many elements');for(let d of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...d,index:f.addresses};f.addresses++;break}default:{i.skipType(h&7);break}}}})),r);function n(i){return Me(i,t.codec())}t.encode=n;function o(i,a){return Ue(i,t.codec(),a)}t.decode=o;function s(i,a){return Ke(i,t.codec(),a)}t.stream=s})(nn||(nn={}));function vu(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var qe=class t{static createFromProtobuf=e=>{let r=nn.decode(e),n=li(_r(r.peerId)),o=(r.addresses??[]).map(i=>rn(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=wu;static CODEC=Eu;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=nn.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||!vu(this.multiaddrs,e.multiaddrs))}};function Ih(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 uo(t){let e=Ih(t);if(e==null)throw new re(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function Su(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 Au(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 Li(t){switch(t.length){case Ft:return t.join(".");case Ut:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function Iu(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 Ft=4,Ut=16,hw=parseInt("0xFFFF",16),Bh=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function on(t,e){e.length===Ut&&t.length===Ft&&Su(e,0,11)&&(e=e.slice(12)),e.length===Ft&&t.length===Ut&&Au(t,Bh,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 _u(t,e){if(typeof e=="string"&&(e=cr(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 Ri(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Ft,o=eo(e);if(o==null&&(n=Ut,o=to(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=Ni(s,8*n);return{network:on(o,i),mask:i}}function Ni(t,e){if(e!==8*Ft&&e!==8*Ut)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var sn=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Ri(e));else{let n=cr(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=cr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Ni(o,8*n.length);this.network=on(n,this.mask)}}contains(e){return _u({network:this.network,mask:this.mask},e)}toString(){let e=Iu(this.mask),r=e!==-1?String(e):Bu(this.mask);return Li(this.network)+"/"+r}};function Cu(t,e){return new sn(t).contains(e)}function Tu(t){try{let e=uo(t);return e.type==="ip6"?Cu("2000::/3",e.host):!1}catch{return!1}}var Lu=ff(Pu(),1),Lh=["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"],Rh=Lh.map(t=>new Lu.Netmask(t));function qi(t){for(let e of Rh)if(e.contains(t))return!0;return!1}function Nh(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function kh(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 qi(o)}function Fh(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function Uh(t){let e=t.split(":"),r=e[e.length-1];return qi(r)}function Mh(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 Ru(t){if(ur(t))return qi(t);if(Nh(t))return kh(t);if(Fh(t))return Uh(t);if(ro(t))return Mh(t)}function Nu(t){try{let e=uo(t);switch(e.type){case"ip4":case"ip6":return Ru(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var Q=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),L=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),ku=t=>({match:e=>t.match(e)===!1?e:!1}),q=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),we=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),j=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function J(...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 Kh=L(421),$w=J(Kh),ho=L(54),po=L(55),mo=L(56),Hi=L(53),jw=J(ho,q(L(421))),Yw=J(po,q(L(421))),Ww=J(mo,q(L(421))),Zw=J(we(Hi,mo,ho,po),q(L(421))),Fu=j(L(4),q(L(43))),Uu=j(q(L(42)),L(41),q(L(43))),$i=we(Fu,Uu),br=we($i,Hi,ho,po,mo),Mu=J(we($i,j(we(Hi,mo,ho,po),q(L(421))))),Gw=J(Fu),Xw=J(Uu),Qw=J($i),ji=j(br,L(6)),an=j(br,L(273)),Ku=J(j(ji,q(L(421)))),Jw=J(an),Yi=j(an,Q(460),q(L(421))),yo=j(an,Q(461),q(L(421))),Vh=we(Yi,yo),e1=J(Yi),t1=J(yo),zi=we(br,ji,an,Yi,yo),Vu=we(j(zi,Q(477),q(L(421)))),r1=J(Vu),qu=we(j(zi,Q(478),q(L(421))),j(zi,Q(448),q(L(449)),Q(477),q(L(421)))),n1=J(qu),zu=j(an,Q(280),q(L(466)),q(L(466)),q(L(421))),o1=J(zu),Hu=j(yo,Q(465),q(L(466)),q(L(466)),q(L(421))),s1=J(Hu),lo=we(Vu,qu,j(ji,q(L(421))),j(Vh,q(L(421))),j(br,q(L(421))),zu,Hu,L(421)),i1=J(lo),qh=j(q(lo),Q(290),ku(Q(281)),q(L(421))),a1=J(qh),zh=we(j(lo,Q(290),Q(281),q(L(421))),j(lo,Q(281),q(L(421))),j(Q(281),q(L(421)))),c1=J(zh),Hh=j(br,we(j(L(6,"80")),j(L(6),Q(480)),Q(480)),q(L(481)),q(L(421))),u1=J(Hh),$h=j(br,we(j(L(6,"443")),j(L(6,"443"),Q(480)),j(L(6),Q(443)),j(L(6),Q(448),Q(480)),j(Q(448),Q(480)),Q(448),Q(443)),q(L(481)),q(L(421))),f1=J($h),jh=we(j(L(777),q(L(421)))),l1=J(jh),Yh=we(j(L(400),q(L(421)))),d1=J(Yh);function xr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Wi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},$u=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Zi(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){h($u(i));return}if(i&&(c=()=>{h($u(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,h),r===Number.POSITIVE_INFINITY)return;let d=new Wi;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(E){h(E)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?h(o):(d.message=o??`Promise timed out after ${r} milliseconds`,h(d))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Wh=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 Zh(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}=Wh(t),l=async(...d)=>{let E=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(E))return}catch(y){n(),i(y);return}c.push(E),r.count===c.length&&(n(),s(c))},h=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,l);for(let d of r.rejectionEvents)a.includes(d)||f(d,h)};for(let d of a)u(d,l);for(let d of r.rejectionEvents)a.includes(d)||u(d,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=Zi(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function ju(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Zh(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Yu(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 Kt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Gh(t){return t.reason}function Gi(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??Gh;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 Qh=4194304,go=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Qi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ji=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ea=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Jh(t){return typeof t?.closeRead=="function"}function ep(t){return typeof t?.close=="function"}function Xi(t){return Jh(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:ep(t)?t.status!=="open":!1}function tp(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function rp(t,e){let r=e?.maxBufferSize??Qh,n=new ue,o,s=!1;if(!tp(t))throw new re("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let a=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};t.addEventListener("close",a);let c=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(s===!0)throw new go("Stream was unwrapped");if(Xi(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Kt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await Gi(o.promise,f?.signal),Xi(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let h=f?.bytes??n.byteLength;if(n.byteLength<h){if(Xi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,h),new Kt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return u.read(f)}let d=n.sublist(0,h);return n.consume(h),d},async write(f,l){if(s===!0)throw new go("Stream was unwrapped");t.send(f)||await ju(t,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return u}function np(t,e={}){let r=rp(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=_e(e.maxDataLength));let n=e?.lengthDecoder??qr,o=e?.lengthEncoder??nr;return{async read(i){let a=-1,c=new ue;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 Qi("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ea(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Ji(`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 Kt(`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 Kt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new ue(o(i.byteLength),i),a)},async writeV(i,a){let c=new ue(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function wr(t,e){let r=np(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 op(t){return t[Symbol.asyncIterator]!=null}function sp(t){if(op(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Wu=sp;var bo=globalThis.CustomEvent??Event;async function*ta(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 y of t){if(s.length===r&&(i=xr(),await i.promise),f||l)break;let x={done:!1};s.push(x),y().then(v=>{x.done=!0,x.ok=!0,x.value=v,o.dispatchEvent(new bo("task-complete"))},v=>{x.done=!0,x.err=v,o.dispatchEvent(new bo("task-complete"))})}c=!0,o.dispatchEvent(new bo("task-complete"))}catch(y){u=y,o.dispatchEvent(new bo("task-complete"))}});function h(){return n?s[0]?.done:!!s.find(y=>y.done)}function*d(){for(;s.length>0&&s[0].done;){let y=s[0];if(s.shift(),y.ok)yield y.value;else throw f=!0,i.resolve(),y.err;i.resolve()}}function*E(){for(;h();)for(let y=0;y<s.length;y++)if(s[y].done){let x=s[y];if(s.splice(y,1),y--,x.ok)yield x.value;else throw f=!0,i.resolve(),x.err;i.resolve()}}try{for(;;){if(h()||(a=xr(),await a.promise),u!=null||(n?yield*d():yield*E(),u!=null))throw u;if(c&&s.length===0)break}}finally{l=!0,i.resolve()}}var Zu="0.1.0";var Gu="id/push",Xu="1.0.0",Qu="1.0.0";var vt;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((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 Ge('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 Ge('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 Ge('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 Ge('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 Me(s,t.codec())}t.encode=r;function n(s,i){return Ue(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(vt||(vt={}));var Ce={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function ef(t){return t.bytes.length===0}function ra(t){if(t!=null&&t.length>0)try{let e=rn(t);if(!ef(e))return e}catch{}}async function xo(t,e,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Re("message was null or undefined");let s={},i=o.listenAddrs.map(ra).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=ir(o.publicKey);if(!su(u).equals(n.remotePeer))throw new Re("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 Qe.openAndCertify(u,qe.DOMAIN),l=qe.createFromProtobuf(f.payload),h=Gn(f.publicKey.toCID());if(!l.peerId.equals(h))throw new Re("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(l.peerId))throw new Re("signing key does not match remote PeerId");let d;try{d=await t.get(l.peerId)}catch(y){if(y.name!=="NotFoundError")throw y}if(d!=null&&(s.metadata=d.metadata,d.peerRecordEnvelope!=null)){let y=Qe.createFromProtobuf(d.peerRecordEnvelope),x=qe.createFromProtobuf(y.payload);x.seqNumber>=l.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",x.seqNumber,l.seqNumber),l=x,u=d.peerRecordEnvelope)}s.peerRecordEnvelope=u;let E=l.multiaddrs.filter(y=>!ef(y));s.addresses=E.map(y=>({isCertified:!0,multiaddr:y})),a={seq:l.seqNumber,addresses:E}}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:rn(o.observedAddr),protocols:o.protocols,signedPeerRecord:a,connection:n};return e.safeDispatchEvent("peer:identify",{detail:c}),c}function wo(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 Eo(t,e,r,n){let o=wr(t,{maxDataLength:e}).pb(vt),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 Er=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??Ce.timeout,this.maxInboundStreams=r.maxInboundStreams??Ce.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Ce.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Ce.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Ce.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Ce.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Ce.protocolPrefix}/${Zu}`,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 vo=class extends Er{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Ce.protocolPrefix}/${Gu}/${Qu}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Ce.concurrency,this._push=Yu(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Ce.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[ln]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),r=new qe({peerId:this.components.peerId,multiaddrs:e}),n=await Qe.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 h,d=AbortSignal.timeout(c.timeout);try{h=await f.newStream(c.protocol,{signal:d,runOnLimitedConnection:c.runOnLimitedConnection}),await wr(h,{maxDataLength:c.maxMessageSize}).pb(vt).write({listenAddrs:e.map(y=>y.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:d}),await h.close({signal:d})}catch(E){h?.log.newScope("identify-push")?.error("could not push identify update to peer",E),h?.abort(E)}})}await Wu(ta(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 Eo(e,this.maxMessageSize,o,n);await xo(this.components.peerStore,this.components.events,n,r,wo(s)),n.trace("handled push from %p",r.remotePeer)}};var So=class extends Er{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Ce.protocolPrefix}/${"id"}/${Xu}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Ce.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[ln]=["@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 Eo(n,this.maxMessageSize,r,o);return wo(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 Re("Public key was missing from identify message");let a=ir(o),c=Gn(a.toCID());if(!e.remotePeer.equals(c))throw new Re("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new Re("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),xo(this.components.peerStore,this.components.events,this.log,e,n)}maybeAddObservedAddress(e){let r=ra(e);if(r==null||(this.log.trace("our observed address was %a",r),Nu(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Tu(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Ku.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(e,r){let n=e.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let f=new qe({peerId:this.components.peerId,multiaddrs:i});a=(await Qe.seal(f,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;Mu.matches(r.remoteAddr)||(c=void 0);let u=wr(e).pb(vt);n("send response"),await u.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ye(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 fp(t={}){return e=>new So(e,t)}function lp(t={}){return e=>new vo(e,t)}return lf(dp);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|