@libp2p/identify 3.0.38-cb1c14e62 → 3.0.38-cf9aab5c8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PIdentify = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PIdentify=(()=>{var pu=Object.create;var bn=Object.defineProperty;var mu=Object.getOwnPropertyDescriptor;var yu=Object.getOwnPropertyNames;var bu=Object.getPrototypeOf,gu=Object.prototype.hasOwnProperty;var xu=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),xt=(r,t)=>{for(var e in t)bn(r,e,{get:t[e],enumerable:!0})},Ci=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of yu(t))!gu.call(r,o)&&o!==e&&bn(r,o,{get:()=>t[o],enumerable:!(n=mu(t,o))||n.enumerable});return r};var wu=(r,t,e)=>(e=r!=null?pu(bu(r)):{},Ci(t||!r||!r.__esModule?bn(e,"default",{value:r,enumerable:!0}):e,r)),Eu=r=>Ci(bn({},"__esModule",{value:!0}),r);var eu=xu(mn=>{(function(){var r,t,e,n,o,s,i,a;a=function(c){var u,d,l,f;return u=(c&255<<24)>>>24,d=(c&255<<16)>>>16,l=(c&65280)>>>8,f=c&255,[u,d,l,f].join(".")},i=function(c){var u,d,l,f,h,p;for(u=[],l=f=0;f<=3&&c.length!==0;l=++f){if(l>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}p=t(c),h=p[0],d=p[1],c=c.substring(d),u.push(h)}if(c.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},e=function(c){return c.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(c){var u,d,l,f,h;for(f=0,u=10,d="9",l=0,c.length>1&&c[l]==="0"&&(c[l+1]==="x"||c[l+1]==="X"?(l+=2,u=16):"0"<=c[l+1]&&c[l+1]<="9"&&(l++,u=8,d="7")),h=l;l<c.length;){if("0"<=c[l]&&c[l]<=d)f=f*u+(e(c[l])-n)>>>0;else if(u===16)if("a"<=c[l]&&c[l]<="f")f=f*u+(10+e(c[l])-s)>>>0;else if("A"<=c[l]&&c[l]<="F")f=f*u+(10+e(c[l])-o)>>>0;else break;else break;if(f>4294967295)throw new Error("too large");l++}if(l===h)throw new Error("empty octet");return[f,l]},r=function(){function c(u,d){var l,f,h,p;if(typeof u!="string")throw new Error("Missing `net' parameter");if(d||(p=u.split("/",2),u=p[0],d=p[1]),d||(d=32),typeof d=="string"&&d.indexOf(".")>-1){try{this.maskLong=i(d)}catch(m){throw l=m,new Error("Invalid mask: "+d)}for(f=h=32;h>=0;f=--h)if(this.maskLong===4294967295<<32-f>>>0){this.bitmask=f;break}}else if(d||d===0)this.bitmask=parseInt(d,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(u)&this.maskLong)>>>0}catch(m){throw l=m,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+d);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var d,l,f;for(f=i(this.first),l=i(this.last),d=0;f<=l;)u(a(f),f,d),d++,f++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),mn.ip2long=i,mn.long2ip=a,mn.Netmask=r}).call(mn)});var sh={};xt(sh,{identify:()=>nh,identifyPush:()=>oh});var xo=Symbol.for("@libp2p/peer-id");var at=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ze=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var gn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},xn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},wn=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},Rt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Be=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var En=Symbol.for("@libp2p/service-capabilities"),uh=Symbol.for("@libp2p/service-dependencies");var Ao={};xt(Ao,{base58btc:()=>J,base58flickr:()=>Du});var Ph=new Uint8Array(0);function Di(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Xt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Bi(r){return new TextEncoder().encode(r)}function Ti(r){return new TextDecoder().decode(r)}function Su(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var m=0,x=0,S=0,C=p.length;S!==C&&p[S]===0;)S++,m++;for(var I=(C-S)*d+1>>>0,B=new Uint8Array(I);S!==C;){for(var N=p[S],_=0,K=I-1;(N!==0||_<x)&&K!==-1;K--,_++)N+=256*B[K]>>>0,B[K]=N%a>>>0,N=N/a>>>0;if(N!==0)throw new Error("Non-zero carry");x=_,S++}for(var k=I-x;k!==I&&B[k]===0;)k++;for(var T=c.repeat(m);k<I;++k)T+=r.charAt(B[k]);return T}function f(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var m=0;if(p[m]!==" "){for(var x=0,S=0;p[m]===c;)x++,m++;for(var C=(p.length-m)*u+1>>>0,I=new Uint8Array(C);p[m];){var B=e[p.charCodeAt(m)];if(B===255)return;for(var N=0,_=C-1;(B!==0||N<S)&&_!==-1;_--,N++)B+=a*I[_]>>>0,I[_]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");S=N,m++}if(p[m]!==" "){for(var K=C-S;K!==C&&I[K]===0;)K++;for(var k=new Uint8Array(x+(C-K)),T=x;K!==C;)k[T++]=I[K++];return k}}}function h(p){var m=f(p);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:f,decode:h}}var vu=Su,Au=vu,Oi=Au;var wo=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Eo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Li(this,t)}},So=class{decoders;constructor(t){this.decoders=t}or(t){return Li(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Li(r,t){return new So({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var vo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new wo(t,e,n),this.decoder=new Eo(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ye({name:r,prefix:t,encode:e,decode:n}){return new vo(r,t,e,n)}function me({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Oi(e,r);return Ye({prefix:t,name:r,encode:n,decode:s=>Xt(o(s))})}function Iu(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let d=t[r[u]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function _u(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Cu(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function tt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Cu(n);return Ye({prefix:t,name:r,encode(s){return _u(s,n,e)},decode(s){return Iu(s,o,e,r)}})}var J=me({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Du=me({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Io={};xt(Io,{base32:()=>ye,base32hex:()=>Ou,base32hexpad:()=>Ru,base32hexpadupper:()=>Nu,base32hexupper:()=>Lu,base32pad:()=>Tu,base32padupper:()=>Pu,base32upper:()=>Bu,base32z:()=>Uu});var ye=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Bu=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Tu=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Pu=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ou=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Lu=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ru=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Nu=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Uu=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _o={};xt(_o,{base36:()=>Dr,base36upper:()=>Ku});var Dr=me({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ku=me({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ku=Ui,Ri=128,Mu=127,Vu=~Mu,Fu=Math.pow(2,31);function Ui(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Fu;)t[e++]=r&255|Ri,r/=128;for(;r&Vu;)t[e++]=r&255|Ri,r>>>=7;return t[e]=r|0,Ui.bytes=e-n+1,t}var Hu=Co,qu=128,Ni=127;function Co(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Co.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Ni)<<o:(i&Ni)*Math.pow(2,o),o+=7}while(i>=qu);return Co.bytes=s-n,e}var zu=Math.pow(2,7),Gu=Math.pow(2,14),$u=Math.pow(2,21),Zu=Math.pow(2,28),Yu=Math.pow(2,35),Wu=Math.pow(2,42),ju=Math.pow(2,49),Xu=Math.pow(2,56),Qu=Math.pow(2,63),Ju=function(r){return r<zu?1:r<Gu?2:r<$u?3:r<Zu?4:r<Yu?5:r<Wu?6:r<ju?7:r<Xu?8:r<Qu?9:10},tf={encode:ku,decode:Hu,encodingLength:Ju},ef=tf,Br=ef;function Tr(r,t=0){return[Br.decode(r,t),Br.decode.bytes]}function We(r,t,e=0){return Br.encode(r,t,e),t}function je(r){return Br.encodingLength(r)}function Nt(r,t){let e=t.byteLength,n=je(r),o=n+je(e),s=new Uint8Array(o+e);return We(r,s,0),We(e,s,n),s.set(t,o),new Xe(r,e,t,s)}function Pr(r){let t=Xt(r),[e,n]=Tr(t),[o,s]=Tr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Xe(e,o,i,t)}function Ki(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Di(r.bytes,e.bytes)}}var Xe=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ki(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return nf(e,Do(r),t??J.encoder);default:return of(e,Do(r),t??ye.encoder)}}var Mi=new WeakMap;function Do(r){let t=Mi.get(r);if(t==null){let e=new Map;return Mi.set(r,e),e}return t}var st=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Or)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==sf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Nt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Ki(t.multihash,n.multihash)}toString(t){return ki(this,t)}toJSON(){return{"/":ki(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Vi(n,o,s.bytes))}else if(e[af]===!0){let{version:n,multihash:o,code:s}=e,i=Pr(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Or)throw new Error(`Version 0 CID must use dag-pb (code: ${Or}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Vi(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Or,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Xt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Xe(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,f]=Tr(t.subarray(e));return e+=f,l},o=n(),s=Or;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,d=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:u}}static parse(t,e){let[n,o]=rf(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Do(s).set(n,t),s}};function rf(r,t){switch(r[0]){case"Q":{let e=t??J;return[J.prefix,e.decode(`${J.prefix}${r}`)]}case J.prefix:{let e=t??J;return[J.prefix,e.decode(r)]}case ye.prefix:{let e=t??ye;return[ye.prefix,e.decode(r)]}case Dr.prefix:{let e=t??Dr;return[Dr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function nf(r,t,e){let{prefix:n}=e;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function of(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Or=112,sf=18;function Vi(r,t,e){let n=je(r),o=n+je(t),s=new Uint8Array(o+e.byteLength);return We(r,s,0),We(t,s,n),s.set(e,o),s}var af=Symbol.for("@ipld/js-cid/CID");var Bo={};xt(Bo,{identity:()=>Ut});var Fi=0,cf="identity",Hi=Xt;function uf(r){return Nt(Fi,Hi(r))}var Ut={code:Fi,name:cf,encode:Hi,digest:uf};function ut(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function dt(r=0){return new Uint8Array(r)}function wt(r=0){return new Uint8Array(r)}function Qt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=wt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var zi=Symbol.for("@achingbrain/uint8arraylist");function qi(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function vn(r){return!!r?.[zi]}var nt=class r{bufs;length;[zi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(vn(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(vn(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=qi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=qi(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(vn(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Qt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Qt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,d=e>a&&e<=c;if(u&&d){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!vn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,d;for(let l=e;l<=c;l+=d){d=0;for(let f=u;f>=0;f--){let h=this.get(l+f);if(n[f]!==h){d=Math.max(1,f-a[h]);break}}if(d===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=wt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=dt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=dt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=dt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=wt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=dt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=dt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=dt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=dt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=dt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!ut(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var To={};xt(To,{base10:()=>ff});var ff=me({prefix:"9",name:"base10",alphabet:"0123456789"});var Po={};xt(Po,{base16:()=>lf,base16upper:()=>df});var lf=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),df=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Oo={};xt(Oo,{base2:()=>hf});var hf=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Lo={};xt(Lo,{base256emoji:()=>gf});var Gi=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),pf=Gi.reduce((r,t,e)=>(r[e]=t,r),[]),mf=Gi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function yf(r){return r.reduce((t,e)=>(t+=pf[e],t),"")}function bf(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=mf[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var gf=Ye({prefix:"\u{1F680}",name:"base256emoji",encode:yf,decode:bf});var No={};xt(No,{base64:()=>xf,base64pad:()=>wf,base64url:()=>Ro,base64urlpad:()=>Ef});var xf=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),wf=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ro=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ef=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Uo={};xt(Uo,{base8:()=>Sf});var Sf=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ko={};xt(Ko,{identity:()=>vf});var vf=Ye({prefix:"\0",name:"identity",encode:r=>Ti(r),decode:r=>Bi(r)});var pp=new TextEncoder,mp=new TextDecoder;var Vo={};xt(Vo,{sha256:()=>Lr,sha512:()=>_f});function Mo({name:r,code:t,encode:e}){return new ko(r,t,e)}var ko=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Nt(this.code,e):e.then(n=>Nt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Zi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Lr=Mo({name:"sha2-256",code:18,encode:Zi("SHA-256")}),_f=Mo({name:"sha2-512",code:19,encode:Zi("SHA-512")});var Rr={...Ko,...Oo,...Uo,...To,...Po,...Io,..._o,...Ao,...No,...Lo},Cp={...Vo,...Bo};function Wi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Yi=Wi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Fo=Wi("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=wt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Cf={utf8:Yi,"utf-8":Yi,hex:Rr.base16,latin1:Fo,ascii:Fo,binary:Fo,...Rr},An=Cf;function V(r,t="utf8"){let e=An[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function F(r,t="utf8"){let e=An[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Df=parseInt("11111",2),Ho=parseInt("10000000",2),Bf=parseInt("01111111",2),ji={0:Nr,1:Nr,2:Tf,3:Lf,4:Rf,5:Of,6:Pf,16:Nr,22:Nr,48:Nr};function Jt(r,t={offset:0}){let e=r[t.offset]&Df;if(t.offset++,ji[e]!=null)return ji[e](r,t);throw new Error("No decoder for tag "+e)}function Ur(r,t){let e=0;if((r[t.offset]&Ho)===Ho){let n=r[t.offset]&Bf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Nr(r,t){Ur(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Jt(r,t);if(n===null)break;e.push(n)}return e}function Tf(r,t){let e=Ur(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Pf(r,t){let e=Ur(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let d=0;for(let l=0;l<c.length;l++)d+=c[l]<<l*7;a+=`.${d}`,c=[]}}return a}function Of(r,t){return t.offset++,null}function Lf(r,t){let e=Ur(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Rf(r,t){let e=Ur(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Nf(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new nt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function qo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Nf(r.byteLength);return new nt(Uint8Array.from([t.byteLength|Ho]),t)}function Et(r){let t=new nt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new nt(Uint8Array.from([2]),qo(t),t)}function In(r){let t=Uint8Array.from([0]),e=new nt(t,r);return new nt(Uint8Array.from([3]),qo(e),e)}function be(r,t=48){let e=new nt;for(let n of r)e.append(n);return new nt(Uint8Array.from([t]),qo(e),e)}async function Xi(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Uf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Kf=Uint8Array.from([6,5,43,129,4,0,34]),kf=Uint8Array.from([6,5,43,129,4,0,35]),Mf={ext:!0,kty:"EC",crv:"P-256"},Vf={ext:!0,kty:"EC",crv:"P-384"},Ff={ext:!0,kty:"EC",crv:"P-521"},zo=32,Go=48,$o=66;function Zo(r){let t=Jt(r);return Qi(t)}function Qi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===zo*2+1)return n=F(t.subarray(e,e+zo),"base64url"),o=F(t.subarray(e+zo),"base64url"),new Qe({...Mf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Go*2+1)return n=F(t.subarray(e,e+Go),"base64url"),o=F(t.subarray(e+Go),"base64url"),new Qe({...Vf,key_ops:["verify"],x:n,y:o});if(t.byteLength===$o*2+1)return n=F(t.subarray(e,e+$o),"base64url"),o=F(t.subarray(e+$o),"base64url"),new Qe({...Ff,key_ops:["verify"],x:n,y:o});throw new at(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ji(r){return be([Et(Uint8Array.from([1])),be([Hf(r.crv)],160),be([In(new nt(Uint8Array.from([4]),V(r.x??"","base64url"),V(r.y??"","base64url")))],161)]).subarray()}function Hf(r){if(r==="P-256")return Uf;if(r==="P-384")return Kf;if(r==="P-521")return kf;throw new at(`Invalid curve ${r}`)}var Qe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ji(this.jwk)),this._raw}toMultihash(){return Ut.digest(zt(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}async verify(t,e,n){return Xi(this.jwk,e,t,n)}};var Pe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Oe(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Kr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function et(r,...t){if(!Oe(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function _n(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Kr(r.outputLen),Kr(r.blockLen)}function tr(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function ea(r,t){et(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function ee(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Cn(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Kt(r,t){return r<<32-t|r>>>t}var ra=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",qf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Ot(r){if(et(r),ra)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=qf[r[e]];return t}var te={_0:48,_9:57,A:65,F:70,a:97,f:102};function ta(r){if(r>=te._0&&r<=te._9)return r-te._0;if(r>=te.A&&r<=te.F)return r-(te.A-10);if(r>=te.a&&r<=te.f)return r-(te.a-10)}function Le(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(ra)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=ta(r.charCodeAt(s)),a=ta(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Yo(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function kr(r){return typeof r=="string"&&(r=Yo(r)),et(r),r}function St(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];et(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Je=class{};function Wo(r){let t=n=>r().update(kr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Mr(r=32){if(Pe&&typeof Pe.getRandomValues=="function")return Pe.getRandomValues(new Uint8Array(r));if(Pe&&typeof Pe.randomBytes=="function")return Uint8Array.from(Pe.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function zf(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}function na(r,t,e){return r&t^~r&e}function oa(r,t,e){return r&t^r&e^t&e}var Vr=class extends Je{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Cn(this.buffer)}update(t){tr(this),t=kr(t),et(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Cn(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){tr(this),ea(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,ee(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;zf(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Cn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,d[l],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},re=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ht=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Dn=BigInt(4294967295),sa=BigInt(32);function Gf(r,t=!1){return t?{h:Number(r&Dn),l:Number(r>>sa&Dn)}:{h:Number(r>>sa&Dn)|0,l:Number(r&Dn)|0}}function ia(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Gf(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var jo=(r,t,e)=>r>>>e,Xo=(r,t,e)=>r<<32-e|t>>>e,Re=(r,t,e)=>r>>>e|t<<32-e,Ne=(r,t,e)=>r<<32-e|t>>>e,Fr=(r,t,e)=>r<<64-e|t>>>e-32,Hr=(r,t,e)=>r>>>e-32|t<<64-e;function Gt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var aa=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ca=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,ua=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),fa=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,la=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),da=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Zf=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]),ge=new Uint32Array(64),Bn=class extends Vr{constructor(t=32){super(64,t,8,!1),this.A=re[0]|0,this.B=re[1]|0,this.C=re[2]|0,this.D=re[3]|0,this.E=re[4]|0,this.F=re[5]|0,this.G=re[6]|0,this.H=re[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)ge[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let f=ge[l-15],h=ge[l-2],p=Kt(f,7)^Kt(f,18)^f>>>3,m=Kt(h,17)^Kt(h,19)^h>>>10;ge[l]=m+ge[l-7]+p+ge[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:d}=this;for(let l=0;l<64;l++){let f=Kt(a,6)^Kt(a,11)^Kt(a,25),h=d+f+na(a,c,u)+Zf[l]+ge[l]|0,m=(Kt(n,2)^Kt(n,13)^Kt(n,22))+oa(n,o,s)|0;d=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,u,d)}roundClean(){ee(ge)}destroy(){this.set(0,0,0,0,0,0,0,0),ee(this.buffer)}};var ha=ia(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Yf=ha[0],Wf=ha[1],xe=new Uint32Array(80),we=new Uint32Array(80),Qo=class extends Vr{constructor(t=64){super(128,t,16,!1),this.Ah=ht[0]|0,this.Al=ht[1]|0,this.Bh=ht[2]|0,this.Bl=ht[3]|0,this.Ch=ht[4]|0,this.Cl=ht[5]|0,this.Dh=ht[6]|0,this.Dl=ht[7]|0,this.Eh=ht[8]|0,this.El=ht[9]|0,this.Fh=ht[10]|0,this.Fl=ht[11]|0,this.Gh=ht[12]|0,this.Gl=ht[13]|0,this.Hh=ht[14]|0,this.Hl=ht[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:d,Fh:l,Fl:f,Gh:h,Gl:p,Hh:m,Hl:x}=this;return[t,e,n,o,s,i,a,c,u,d,l,f,h,p,m,x]}set(t,e,n,o,s,i,a,c,u,d,l,f,h,p,m,x){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=d|0,this.Fh=l|0,this.Fl=f|0,this.Gh=h|0,this.Gl=p|0,this.Hh=m|0,this.Hl=x|0}process(t,e){for(let I=0;I<16;I++,e+=4)xe[I]=t.getUint32(e),we[I]=t.getUint32(e+=4);for(let I=16;I<80;I++){let B=xe[I-15]|0,N=we[I-15]|0,_=Re(B,N,1)^Re(B,N,8)^jo(B,N,7),K=Ne(B,N,1)^Ne(B,N,8)^Xo(B,N,7),k=xe[I-2]|0,T=we[I-2]|0,b=Re(k,T,19)^Fr(k,T,61)^jo(k,T,6),y=Ne(k,T,19)^Hr(k,T,61)^Xo(k,T,6),E=ua(K,y,we[I-7],we[I-16]),v=fa(E,_,b,xe[I-7],xe[I-16]);xe[I]=v|0,we[I]=E|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:d,Eh:l,El:f,Fh:h,Fl:p,Gh:m,Gl:x,Hh:S,Hl:C}=this;for(let I=0;I<80;I++){let B=Re(l,f,14)^Re(l,f,18)^Fr(l,f,41),N=Ne(l,f,14)^Ne(l,f,18)^Hr(l,f,41),_=l&h^~l&m,K=f&p^~f&x,k=la(C,N,K,Wf[I],we[I]),T=da(k,S,B,_,Yf[I],xe[I]),b=k|0,y=Re(n,o,28)^Fr(n,o,34)^Fr(n,o,39),E=Ne(n,o,28)^Hr(n,o,34)^Hr(n,o,39),v=n&s^n&a^s&a,P=o&i^o&c^i&c;S=m|0,C=x|0,m=h|0,x=p|0,h=l|0,p=f|0,{h:l,l:f}=Gt(u|0,d|0,T|0,b|0),u=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let L=aa(b,E,P);n=ca(L,T,y,v),o=L|0}({h:n,l:o}=Gt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Gt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Gt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:d}=Gt(this.Dh|0,this.Dl|0,u|0,d|0),{h:l,l:f}=Gt(this.Eh|0,this.El|0,l|0,f|0),{h,l:p}=Gt(this.Fh|0,this.Fl|0,h|0,p|0),{h:m,l:x}=Gt(this.Gh|0,this.Gl|0,m|0,x|0),{h:S,l:C}=Gt(this.Hh|0,this.Hl|0,S|0,C|0),this.set(n,o,s,i,a,c,u,d,l,f,h,p,m,x,S,C)}roundClean(){ee(xe,we)}destroy(){ee(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Tn=Wo(()=>new Bn);var pa=Wo(()=>new Qo);var es=BigInt(0),ts=BigInt(1);function ne(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function qr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function ma(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?es:BigInt("0x"+r)}function er(r){return ma(Ot(r))}function oe(r){return et(r),ma(Ot(Uint8Array.from(r).reverse()))}function Pn(r,t){return Le(r.toString(16).padStart(t*2,"0"))}function se(r,t){return Pn(r,t).reverse()}function Z(r,t,e){let n;if(typeof t=="string")try{n=Le(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Oe(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function ya(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}var Jo=r=>typeof r=="bigint"&&es<=r;function ba(r,t,e){return Jo(r)&&Jo(t)&&Jo(e)&&t<=r&&r<e}function Ee(r,t,e,n){if(!ba(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function On(r){let t;for(t=0;r>es;r>>=ts,t+=1);return t}var Se=r=>(ts<<BigInt(r))-ts;function ga(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},u=(...h)=>e(i,s,...h),d=(h=n(0))=>{i=u(o(0),h),s=u(),h.length!==0&&(i=u(o(1),h),s=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,p=[];for(;h<t;){s=u();let m=s.slice();p.push(m),h+=s.length}return St(...p)};return(h,p)=>{c(),d(h);let m;for(;!(m=p(l()));)d();return c(),m}}function ve(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function rr(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var gt=BigInt(0),ft=BigInt(1),Ue=BigInt(2),Ea=BigInt(3),Sa=BigInt(4),va=BigInt(5),jf=BigInt(7),Aa=BigInt(8),Xf=BigInt(9),Ia=BigInt(16);function rt(r,t){let e=r%t;return e>=gt?e:t+e}function X(r,t,e){let n=r;for(;t-- >gt;)n*=n,n%=e;return n}function xa(r,t){if(r===gt)throw new Error("invert: expected non-zero number");if(t<=gt)throw new Error("invert: expected positive modulus, got "+t);let e=rt(r,t),n=t,o=gt,s=ft,i=ft,a=gt;for(;e!==gt;){let u=n/e,d=n%e,l=o-i*u,f=s-a*u;n=e,e=d,o=i,s=a,i=l,a=f}if(n!==ft)throw new Error("invert: does not exist");return rt(o,t)}function rs(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function _a(r,t){let e=(r.ORDER+ft)/Sa,n=r.pow(t,e);return rs(r,n,t),n}function Qf(r,t){let e=(r.ORDER-va)/Aa,n=r.mul(t,Ue),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,Ue),o),a=r.mul(s,r.sub(i,r.ONE));return rs(r,a,t),a}function Jf(r){let t=Bt(r),e=Ca(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+jf)/Ia;return(a,c)=>{let u=a.pow(c,i),d=a.mul(u,n),l=a.mul(u,o),f=a.mul(u,s),h=a.eql(a.sqr(d),c),p=a.eql(a.sqr(l),c);u=a.cmov(u,d,h),d=a.cmov(f,l,p);let m=a.eql(a.sqr(d),c),x=a.cmov(u,d,m);return rs(a,x,c),x}}function Ca(r){if(r<Ea)throw new Error("sqrt is not defined for small field");let t=r-ft,e=0;for(;t%Ue===gt;)t/=Ue,e++;let n=Ue,o=Bt(r);for(;wa(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return _a;let s=o.pow(n,t),i=(t+ft)/Ue;return function(c,u){if(c.is0(u))return u;if(wa(c,u)!==1)throw new Error("Cannot find square root");let d=e,l=c.mul(c.ONE,s),f=c.pow(u,t),h=c.pow(u,i);for(;!c.eql(f,c.ONE);){if(c.is0(f))return c.ZERO;let p=1,m=c.sqr(f);for(;!c.eql(m,c.ONE);)if(p++,m=c.sqr(m),p===d)throw new Error("Cannot find square root");let x=ft<<BigInt(d-p-1),S=c.pow(l,x);d=p,l=c.sqr(S),f=c.mul(f,l),h=c.mul(h,S)}return h}}function tl(r){return r%Sa===Ea?_a:r%Aa===va?Qf:r%Ia===Xf?Jf(r):Ca(r)}var ie=(r,t)=>(rt(r,t)&ft)===ft,el=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ns(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=el.reduce((n,o)=>(n[o]="function",n),t);return ve(r,e),r}function rl(r,t,e){if(e<gt)throw new Error("invalid exponent, negatives unsupported");if(e===gt)return r.ONE;if(e===ft)return t;let n=r.ONE,o=t;for(;e>gt;)e&ft&&(n=r.mul(n,o)),o=r.sqr(o),e>>=ft;return n}function zr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function wa(r,t){let e=(r.ORDER-ft)/Ue,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Da(r,t){t!==void 0&&Kr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Bt(r,t,e=!1,n={}){if(r<=gt)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(e=f.isLE),typeof f.modOnDecode=="boolean"&&(i=f.modOnDecode),a=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:u}=Da(r,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,l=Object.freeze({ORDER:r,isLE:e,BITS:c,BYTES:u,MASK:Se(c),ZERO:gt,ONE:ft,allowedLengths:a,create:f=>rt(f,r),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return gt<=f&&f<r},is0:f=>f===gt,isValidNot0:f=>!l.is0(f)&&l.isValid(f),isOdd:f=>(f&ft)===ft,neg:f=>rt(-f,r),eql:(f,h)=>f===h,sqr:f=>rt(f*f,r),add:(f,h)=>rt(f+h,r),sub:(f,h)=>rt(f-h,r),mul:(f,h)=>rt(f*h,r),pow:(f,h)=>rl(l,f,h),div:(f,h)=>rt(f*xa(h,r),r),sqrN:f=>f*f,addN:(f,h)=>f+h,subN:(f,h)=>f-h,mulN:(f,h)=>f*h,inv:f=>xa(f,r),sqrt:s||(f=>(d||(d=tl(r)),d(l,f))),toBytes:f=>e?se(f,u):Pn(f,u),fromBytes:(f,h=!0)=>{if(a){if(!a.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);let m=new Uint8Array(u);m.set(f,e?0:m.length-f.length),f=m}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let p=e?oe(f):er(f);if(i&&(p=rt(p,r)),!h&&!l.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:f=>zr(l,f),cmov:(f,h,p)=>p?h:f});return Object.freeze(l)}function Ba(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function os(r){let t=Ba(r);return t+Math.ceil(t/2)}function ss(r,t,e=!1){let n=r.length,o=Ba(t),s=os(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?oe(r):er(r),a=rt(i,t-ft)+ft;return e?se(a,o):Pn(a,o)}var nr=BigInt(0),Ke=BigInt(1);function Gr(r,t){let e=t.negate();return r?e:t}function ae(r,t){let e=zr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function La(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function is(r,t){La(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=Se(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ta(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=Ke);let u=t*n,d=u+Math.abs(a)-1,l=a===0,f=a<0,h=t%2!==0;return{nextN:c,offset:d,isZero:l,isNeg:f,isNegF:h,offsetF:u}}function nl(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function ol(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var as=new WeakMap,Ra=new WeakMap;function cs(r){return Ra.get(r)||1}function Pa(r){if(r!==nr)throw new Error("invalid wNAF")}var or=class{constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>nr;)e&Ke&&(n=n.add(o)),o=o.double(),e>>=Ke;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=is(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=is(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:d,isNeg:l,isNegF:f,offsetF:h}=Ta(n,a,i);n=c,d?s=s.add(Gr(f,e[h])):o=o.add(Gr(l,e[u]))}return Pa(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=is(t,this.bits);for(let i=0;i<s.windows&&n!==nr;i++){let{nextN:a,offset:c,isZero:u,isNeg:d}=Ta(n,i,s);if(n=a,!u){let l=e[c];o=o.add(d?l.negate():l)}}return Pa(n),o}getPrecomputes(t,e,n){let o=as.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),as.set(e,o))),o}cached(t,e,n){let o=cs(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=cs(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){La(e,this.bits),Ra.set(t,e),as.delete(t)}hasCache(t){return cs(t)!==1}};function Na(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>nr||n>nr;)e&Ke&&(s=s.add(o)),n&Ke&&(i=i.add(o)),o=o.double(),e>>=Ke,n>>=Ke;return{p1:s,p2:i}}function sr(r,t,e,n){nl(e,r),ol(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=On(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=Se(c),d=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,f=i;for(let h=l;h>=0;h-=c){d.fill(i);for(let m=0;m<s;m++){let x=n[m],S=Number(x>>BigInt(h)&u);d[S]=d[S].add(e[m])}let p=i;for(let m=d.length-1,x=i;m>0;m--)x=x.add(d[m]),p=p.add(x);if(f=f.add(p),h!==0)for(let m=0;m<c;m++)f=f.double()}return f}function Oa(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ns(t),t}else return Bt(r)}function Ln(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>nr))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Oa(t.p,e.Fp),o=Oa(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var $t=BigInt(0),ct=BigInt(1),us=BigInt(2),sl=BigInt(8);function il(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function al(r,t={}){let{Fp:e,Fn:n}=Ln("edwards",r,t),{h:o,n:s}=r;ve(t,{},{uvRatio:"function"});let i=us<<BigInt(n.BYTES*8)-ct,a=m=>e.create(m),c=t.uvRatio||((m,x)=>{try{return{isValid:!0,value:e.sqrt(e.div(m,x))}}catch{return{isValid:!1,value:$t}}});if(!il(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function u(m,x,S=!1){let C=S?ct:$t;return Ee("coordinate "+m,x,C,i),x}function d(m){if(!(m instanceof h))throw new Error("ExtendedPoint expected")}let l=rr((m,x)=>{let{X:S,Y:C,Z:I}=m,B=m.is0();x==null&&(x=B?sl:e.inv(I));let N=a(S*x),_=a(C*x),K=e.mul(I,x);if(B)return{x:$t,y:ct};if(K!==ct)throw new Error("invZ was invalid");return{x:N,y:_}}),f=rr(m=>{let{a:x,d:S}=r;if(m.is0())throw new Error("bad point: ZERO");let{X:C,Y:I,Z:B,T:N}=m,_=a(C*C),K=a(I*I),k=a(B*B),T=a(k*k),b=a(_*x),y=a(k*a(b+K)),E=a(T+a(S*a(_*K)));if(y!==E)throw new Error("bad point: equation left != right (1)");let v=a(C*I),P=a(B*N);if(v!==P)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(x,S,C,I){this.X=u("x",x),this.Y=u("y",S),this.Z=u("z",C,!0),this.T=u("t",I),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(x){return ae(h,x)}static msm(x,S){return sr(h,n,x,S)}_setWindowSize(x){this.precompute(x)}static fromAffine(x){if(x instanceof h)throw new Error("extended point not allowed");let{x:S,y:C}=x||{};return u("x",S),u("y",C),new h(S,C,ct,a(S*C))}precompute(x=8,S=!0){return p.createCache(this,x),S||this.multiply(us),this}assertValidity(){f(this)}equals(x){d(x);let{X:S,Y:C,Z:I}=this,{X:B,Y:N,Z:_}=x,K=a(S*_),k=a(B*I),T=a(C*_),b=a(N*I);return K===k&&T===b}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:x}=r,{X:S,Y:C,Z:I}=this,B=a(S*S),N=a(C*C),_=a(us*a(I*I)),K=a(x*B),k=S+C,T=a(a(k*k)-B-N),b=K+N,y=b-_,E=K-N,v=a(T*y),P=a(b*E),L=a(T*E),w=a(y*b);return new h(v,P,w,L)}add(x){d(x);let{a:S,d:C}=r,{X:I,Y:B,Z:N,T:_}=this,{X:K,Y:k,Z:T,T:b}=x,y=a(I*K),E=a(B*k),v=a(_*C*b),P=a(N*T),L=a((I+B)*(K+k)-y-E),w=P-v,g=P+v,A=a(E-S*y),D=a(L*w),R=a(g*A),U=a(L*A),M=a(w*g);return new h(D,R,M,U)}subtract(x){return this.add(x.negate())}multiply(x){let S=x;Ee("scalar",S,ct,s);let{p:C,f:I}=p.cached(this,S,B=>ae(h,B));return ae(h,[C,I])[0]}multiplyUnsafe(x,S=h.ZERO){let C=x;return Ee("scalar",C,$t,s),C===$t?h.ZERO:this.is0()||C===ct?this:p.unsafe(this,C,I=>ae(h,I),S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return p.unsafe(this,s).is0()}toAffine(x){return l(this,x)}clearCofactor(){return o===ct?this:this.multiplyUnsafe(o)}static fromBytes(x,S=!1){return et(x),h.fromHex(x,S)}static fromHex(x,S=!1){let{d:C,a:I}=r,B=e.BYTES;x=Z("pointHex",x,B),ne("zip215",S);let N=x.slice(),_=x[B-1];N[B-1]=_&-129;let K=oe(N),k=S?i:e.ORDER;Ee("pointHex.y",K,$t,k);let T=a(K*K),b=a(T-ct),y=a(C*T-I),{isValid:E,value:v}=c(b,y);if(!E)throw new Error("Point.fromHex: invalid y coordinate");let P=(v&ct)===ct,L=(_&128)!==0;if(!S&&v===$t&&L)throw new Error("Point.fromHex: x=0 and x_0=1");return L!==P&&(v=a(-v)),h.fromAffine({x:v,y:K})}toBytes(){let{x,y:S}=this.toAffine(),C=se(S,e.BYTES);return C[C.length-1]|=x&ct?128:0,C}toRawBytes(){return this.toBytes()}toHex(){return Ot(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}h.BASE=new h(r.Gx,r.Gy,ct,a(r.Gx*r.Gy)),h.ZERO=new h($t,ct,ct,$t),h.Fp=e,h.Fn=n;let p=new or(h,n.BYTES*8);return h}var Rn=class{constructor(t){this.ep=t}static fromBytes(t){throw new Error("fromBytes must be implemented by subclass")}static fromHex(t){throw new Error("fromHex must be implemented by subclass")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toRawBytes(){return this.toBytes()}toHex(){return Ot(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,e){return this.init(this.ep.precompute(t,e))}};function cl(r,t,e){if(typeof t!="function")throw new Error('"hash" function param is required');ve(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,c=e.randomBytes||Mr,u=e.adjustScalarBytes||(y=>y),d=e.domain||((y,E,v)=>{if(ne("phflag",v),E.length||v)throw new Error("Contexts/pre-hash are not supported");return y});function l(y){return i.create(y)}function f(y){return l(oe(y))}function h(y){let E=s.BYTES;y=Z("private key",y,E);let v=Z("hashed private key",t(y),2*E),P=u(v.slice(0,E)),L=v.slice(E,2*E),w=f(P);return{head:P,prefix:L,scalar:w}}function p(y){let{head:E,prefix:v,scalar:P}=h(y),L=o.multiply(P),w=L.toBytes();return{head:E,prefix:v,scalar:P,point:L,pointBytes:w}}function m(y){return p(y).pointBytes}function x(y=Uint8Array.of(),...E){let v=St(...E);return f(t(d(v,Z("context",y),!!n)))}function S(y,E,v={}){y=Z("message",y),n&&(y=n(y));let{prefix:P,scalar:L,pointBytes:w}=p(E),g=x(v.context,P,y),A=o.multiply(g).toBytes(),D=x(v.context,A,w,y),R=l(g+D*L);Ee("signature.s",R,$t,a);let U=s.BYTES,M=St(A,se(R,U));return Z("result",M,U*2)}let C={zip215:!0};function I(y,E,v,P=C){let{context:L,zip215:w}=P,g=s.BYTES;y=Z("signature",y,2*g),E=Z("message",E),v=Z("publicKey",v,g),w!==void 0&&ne("zip215",w),n&&(E=n(E));let A=oe(y.slice(g,2*g)),D,R,U;try{D=r.fromHex(v,w),R=r.fromHex(y.slice(0,g),w),U=o.multiplyUnsafe(A)}catch{return!1}if(!w&&D.isSmallOrder())return!1;let M=x(L,R.toBytes(),D.toBytes(),E);return R.add(D.multiplyUnsafe(M)).subtract(U).clearCofactor().is0()}o.precompute(8);let B=s.BYTES,N={secret:B,public:B,signature:2*B,seed:B};function _(y=c(N.seed)){return y}let K={getExtendedPublicKey:p,randomSecretKey:_,isValidSecretKey:T,isValidPublicKey:b,randomPrivateKey:_,toMontgomery(y){let{y:E}=r.fromBytes(y),v=B===32;if(!v&&B!==57)throw new Error("only defined for 25519 and 448");let P=v?s.div(ct+E,ct-E):s.div(E-ct,E+ct);return s.toBytes(P)},toMontgomeryPriv(y){et(y,B);let E=t(y.subarray(0,B));return u(E).subarray(0,B)},precompute(y=8,E=r.BASE){return E.precompute(y,!1)}};function k(y){let E=K.randomSecretKey(y);return{secretKey:E,publicKey:m(E)}}function T(y){try{return!!i.fromBytes(y,!1)}catch{return!1}}function b(y,E){try{return!!r.fromBytes(y,E)}catch{return!1}}return Object.freeze({keygen:k,getPublicKey:m,sign:S,verify:I,utils:K,Point:r,info:{type:"edwards",lengths:N}})}function ul(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Bt(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,hash:r.hash,eddsaOpts:s}}function fl(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function Ua(r){let{CURVE:t,curveOpts:e,hash:n,eddsaOpts:o}=ul(r),s=al(t,e),i=cl(s,n,o);return fl(r,i)}var ll=BigInt(0),ce=BigInt(1),Ka=BigInt(2),N0=BigInt(3),dl=BigInt(5),hl=BigInt(8),$r={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:hl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function pl(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=$r.p,a=r*r%s*r%s,c=X(a,Ka,s)*a%s,u=X(c,ce,s)*r%s,d=X(u,dl,s)*u%s,l=X(d,t,s)*d%s,f=X(l,e,s)*l%s,h=X(f,n,s)*f%s,p=X(h,o,s)*h%s,m=X(p,o,s)*h%s,x=X(m,t,s)*d%s;return{pow_p_5_8:X(x,Ka,s)*r%s,b2:a}}function ml(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var fs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function hs(r,t){let e=$r.p,n=rt(t*t*t,e),o=rt(n*n*t,e),s=pl(r*o).pow_p_5_8,i=rt(r*n*s,e),a=rt(t*i*i,e),c=i,u=rt(i*fs,e),d=a===r,l=a===rt(-r,e),f=a===rt(-r*fs,e);return d&&(i=c),(l||f)&&(i=u),ie(i,e)&&(i=rt(-i,e)),{isValid:d||l,value:i}}var ke=Bt($r.p,{isLE:!0}),yl=Bt($r.n,{isLE:!0}),bl={...$r,Fp:ke,hash:pa,adjustScalarBytes:ml,uvRatio:hs},Tt=Ua(bl);var ls=fs,gl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),xl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),wl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),El=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),ka=r=>hs(ce,r),Sl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),ds=r=>Tt.CURVE.Fp.create(oe(r)&Sl);function Ma(r){let{d:t}=Tt.CURVE,e=Tt.CURVE.Fp.ORDER,n=Tt.CURVE.Fp.create,o=n(ls*r*r),s=n((o+ce)*wl),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=hs(s,a),d=n(u*r);ie(d,e)||(d=n(-d)),c||(u=d),c||(i=o);let l=n(i*(o-ce)*El-a),f=u*u,h=n((u+u)*a),p=n(l*gl),m=n(ce-f),x=n(ce+f);return new Tt.Point(n(h*x),n(m*p),n(p*x),n(h*m))}function vl(r){et(r,64);let t=ds(r.subarray(0,32)),e=Ma(t),n=ds(r.subarray(32,64)),o=Ma(n);return new ue(e.add(o))}var ue=class r extends Rn{constructor(t){super(t)}static fromAffine(t){return new r(Tt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static hashToCurve(t){return vl(Z("ristrettoHash",t,64))}static fromBytes(t){et(t,32);let{a:e,d:n}=Tt.CURVE,o=ke.ORDER,s=ke.create,i=ds(t);if(!ya(se(i,32),t)||ie(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(ce+e*a),u=s(ce-e*a),d=s(c*c),l=s(u*u),f=s(e*n*d-l),{isValid:h,value:p}=ka(s(f*l)),m=s(p*u),x=s(p*m*f),S=s((i+i)*m);ie(S,o)&&(S=s(-S));let C=s(c*x),I=s(S*C);if(!h||ie(I,o)||C===ll)throw new Error("invalid ristretto255 encoding 2");return new r(new Tt.Point(S,C,ce,I))}static fromHex(t){return r.fromBytes(Z("ristrettoHex",t,32))}static msm(t,e){return sr(r,Tt.Point.Fn,t,e)}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=ke.ORDER,i=ke.create,a=i(i(n+e)*i(n-e)),c=i(t*e),u=i(c*c),{value:d}=ka(i(a*u)),l=i(d*a),f=i(d*c),h=i(l*f*o),p;if(ie(o*h,s)){let x=i(e*ls),S=i(t*ls);t=x,e=S,p=i(l*xl)}else p=f;ie(t*h,s)&&(e=i(-e));let m=i((n-e)*p);return ie(m,s)&&(m=i(-m)),se(m,32)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=ke.create,a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};ue.BASE=new ue(Tt.Point.BASE);ue.ZERO=new ue(Tt.Point.ZERO);ue.Fp=ke;ue.Fn=yl;var Zr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Nn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Va={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Nn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Lt=Va;var Un=32;var ps,Al=(async()=>{try{return await Lt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Il(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Lt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Lt.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function _l(r,t,e){return Tt.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Fa(r,t,e){return ps==null&&(ps=await Al),ps?Il(r,t,e):_l(r,t,e)}function Kn(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var kn=class{type="Ed25519";raw;constructor(t){this.raw=ms(t,Un)}toMultihash(){return Ut.digest(zt(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Fa(this.raw,e,t);return Kn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ys(r){return r=ms(r,Un),new kn(r)}function ms(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new at(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Dl=Math.pow(2,7),Bl=Math.pow(2,14),Tl=Math.pow(2,21),bs=Math.pow(2,28),gs=Math.pow(2,35),xs=Math.pow(2,42),ws=Math.pow(2,49),z=128,mt=127;function vt(r){if(r<Dl)return 1;if(r<Bl)return 2;if(r<Tl)return 3;if(r<bs)return 4;if(r<gs)return 5;if(r<xs)return 6;if(r<ws)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ir(r,t,e=0){switch(vt(r)){case 8:t[e++]=r&255|z,r/=128;case 7:t[e++]=r&255|z,r/=128;case 6:t[e++]=r&255|z,r/=128;case 5:t[e++]=r&255|z,r/=128;case 4:t[e++]=r&255|z,r>>>=7;case 3:t[e++]=r&255|z,r>>>=7;case 2:t[e++]=r&255|z,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Pl(r,t,e=0){switch(vt(r)){case 8:t.set(e++,r&255|z),r/=128;case 7:t.set(e++,r&255|z),r/=128;case 6:t.set(e++,r&255|z),r/=128;case 5:t.set(e++,r&255|z),r/=128;case 4:t.set(e++,r&255|z),r>>>=7;case 3:t.set(e++,r&255|z),r>>>=7;case 2:t.set(e++,r&255|z),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Es(r,t){let e=r[t],n=0;if(n+=e&mt,e<z||(e=r[t+1],n+=(e&mt)<<7,e<z)||(e=r[t+2],n+=(e&mt)<<14,e<z)||(e=r[t+3],n+=(e&mt)<<21,e<z)||(e=r[t+4],n+=(e&mt)*bs,e<z)||(e=r[t+5],n+=(e&mt)*gs,e<z)||(e=r[t+6],n+=(e&mt)*xs,e<z)||(e=r[t+7],n+=(e&mt)*ws,e<z))return n;throw new RangeError("Could not decode varint")}function Ol(r,t){let e=r.get(t),n=0;if(n+=e&mt,e<z||(e=r.get(t+1),n+=(e&mt)<<7,e<z)||(e=r.get(t+2),n+=(e&mt)<<14,e<z)||(e=r.get(t+3),n+=(e&mt)<<21,e<z)||(e=r.get(t+4),n+=(e&mt)*bs,e<z)||(e=r.get(t+5),n+=(e&mt)*gs,e<z)||(e=r.get(t+6),n+=(e&mt)*xs,e<z)||(e=r.get(t+7),n+=(e&mt)*ws,e<z))return n;throw new RangeError("Could not decode varint")}function ar(r,t,e=0){return t==null&&(t=wt(vt(r))),t instanceof Uint8Array?ir(r,t,e):Pl(r,t,e)}function Yr(r,t=0){return r instanceof Uint8Array?Es(r,t):Ol(r,t)}var vs=new Float32Array([-0]),Ae=new Uint8Array(vs.buffer);function qa(r,t,e){vs[0]=r,t[e]=Ae[0],t[e+1]=Ae[1],t[e+2]=Ae[2],t[e+3]=Ae[3]}function za(r,t){return Ae[0]=r[t],Ae[1]=r[t+1],Ae[2]=r[t+2],Ae[3]=r[t+3],vs[0]}var As=new Float64Array([-0]),yt=new Uint8Array(As.buffer);function Ga(r,t,e){As[0]=r,t[e]=yt[0],t[e+1]=yt[1],t[e+2]=yt[2],t[e+3]=yt[3],t[e+4]=yt[4],t[e+5]=yt[5],t[e+6]=yt[6],t[e+7]=yt[7]}function $a(r,t){return yt[0]=r[t],yt[1]=r[t+1],yt[2]=r[t+2],yt[3]=r[t+3],yt[4]=r[t+4],yt[5]=r[t+5],yt[6]=r[t+6],yt[7]=r[t+7],As[0]}var Ll=BigInt(Number.MAX_SAFE_INTEGER),Rl=BigInt(Number.MIN_SAFE_INTEGER),Pt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Me;if(t<Ll&&t>Rl)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Za&&(o=0n,++n>Za&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Me;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Me}},Me=new Pt(0,0);Me.toBigInt=function(){return 0n};Me.zzEncode=Me.zzDecode=function(){return this};Me.length=function(){return 1};var Za=4294967296n;function Ya(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Wa(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Is(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function kt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Mn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var _s=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,kt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw kt(this,4);return Mn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw kt(this,4);return Mn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw kt(this,4);let t=za(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw kt(this,4);let t=$a(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw kt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Wa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw kt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Pt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw kt(this,8);let t=Mn(this.buf,this.pos+=4),e=Mn(this.buf,this.pos+=4);return new Pt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Es(this.buf,this.pos);return this.pos+=vt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Cs(r){return new _s(r instanceof Uint8Array?r:r.subarray())}function Mt(r,t,e){let n=Cs(r);return t.decode(n,void 0,e)}function Ds(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return wt(i);o+i>t&&(n=wt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ve=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Bs(){}var Ps=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Nl=Ds();function Ul(r){return globalThis.Buffer!=null?wt(r):Nl(r)}var jr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ve(Bs,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ve(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Os((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Vn,10,Pt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Pt.fromBigInt(t);return this._push(Vn,e.length(),e)}uint64Number(t){return this._push(ir,vt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Pt.fromBigInt(t).zzEncode();return this._push(Vn,e.length(),e)}sint64Number(t){let e=Pt.fromNumber(t).zzEncode();return this._push(Vn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ts,1,t?1:0)}fixed32(t){return this._push(Wr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Pt.fromBigInt(t);return this._push(Wr,4,e.lo)._push(Wr,4,e.hi)}fixed64Number(t){let e=Pt.fromNumber(t);return this._push(Wr,4,e.lo)._push(Wr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(qa,4,t)}double(t){return this._push(Ga,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ts,1,0):this.uint32(e)._push(kl,e,t)}string(t){let e=Ya(t);return e!==0?this.uint32(e)._push(Is,e,t):this._push(Ts,1,0)}fork(){return this.states=new Ps(this),this.head=this.tail=new Ve(Bs,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 Ve(Bs,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Ul(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ts(r,t,e){t[e]=r&255}function Kl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Os=class extends Ve{next;constructor(t,e){super(Kl,t,e),this.next=void 0}};function Vn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Wr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function kl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(jr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ml,t,r),this},jr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Vl,t,r),this});function Ml(r,t,e){t.set(r,e)}function Vl(r,t,e){r.length<40?Is(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(V(r),e)}function Ls(){return new jr}function Vt(r,t){let e=Ls();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var cr;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(cr||(cr={}));function Fn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Rs(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Fn("enum",cr.VARINT,e,n)}function Ft(r,t){return Fn("message",cr.LENGTH_DELIMITED,r,t)}var Fe=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ot;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ot||(ot={}));var Ns;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Ns||(Ns={}));(function(r){r.codec=()=>Rs(Ns)})(ot||(ot={}));var Zt;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ot.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=ot.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Vt(e,r.codec()),r.decode=(e,n)=>Mt(e,r.codec(),n)})(Zt||(Zt={}));var Us;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ot.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=ot.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Vt(e,r.codec()),r.decode=(e,n)=>Mt(e,r.codec(),n)})(Us||(Us={}));var Qr={};xt(Qr,{MAX_RSA_KEY_SIZE:()=>Ks,generateRSAKeyPair:()=>ec,jwkToJWKKeyPair:()=>rc,jwkToPkcs1:()=>zl,jwkToPkix:()=>Fs,jwkToRSAPrivateKey:()=>Gs,pkcs1MessageToJwk:()=>Ms,pkcs1MessageToRSAPrivateKey:()=>Hs,pkcs1ToJwk:()=>ql,pkcs1ToRSAPrivateKey:()=>tc,pkixMessageToJwk:()=>Vs,pkixMessageToRSAPublicKey:()=>zs,pkixToJwk:()=>Gl,pkixToRSAPublicKey:()=>qs});var Hn=Tn;var ur=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Qr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return st.createV1(114,this._multihash)}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,e,n){return Ja(this.jwk,e,t,n)}},Xr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Qr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}sign(t,e){return Qa(this.jwk,t,e)}};var Ks=8192,ks=18,Fl=1062,Hl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function ql(r){let t=Jt(r);return Ms(t)}function Ms(r){return{n:F(r[1],"base64url"),e:F(r[2],"base64url"),d:F(r[3],"base64url"),p:F(r[4],"base64url"),q:F(r[5],"base64url"),dp:F(r[6],"base64url"),dq:F(r[7],"base64url"),qi:F(r[8],"base64url"),kty:"RSA"}}function zl(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new at("JWK was missing components");return be([Et(Uint8Array.from([0])),Et(V(r.n,"base64url")),Et(V(r.e,"base64url")),Et(V(r.d,"base64url")),Et(V(r.p,"base64url")),Et(V(r.q,"base64url")),Et(V(r.dp,"base64url")),Et(V(r.dq,"base64url")),Et(V(r.qi,"base64url"))]).subarray()}function Gl(r){let t=Jt(r,{offset:0});return Vs(t)}function Vs(r){let t=Jt(r[1],{offset:0});return{kty:"RSA",n:F(t[0],"base64url"),e:F(t[1],"base64url")}}function Fs(r){if(r.n==null||r.e==null)throw new at("JWK was missing components");return be([Hl,In(be([Et(V(r.n,"base64url")),Et(V(r.e,"base64url"))]))]).subarray()}function tc(r){let t=Jt(r);return Hs(t)}function Hs(r){let t=Ms(r);return Gs(t)}function qs(r,t){if(r.byteLength>=Fl)throw new Ze("Key size is too large");let e=Jt(r,{offset:0});return zs(e,r,t)}function zs(r,t,e){let n=Vs(r);if(e==null){let o=Hn(Zt.encode({Type:ot.RSA,Data:t}));e=Nt(ks,o)}return new ur(n,e)}function Gs(r){if(oc(r)>Ks)throw new at("Key size is too large");let t=rc(r),e=Hn(Zt.encode({Type:ot.RSA,Data:Fs(t.publicKey)})),n=Nt(ks,e);return new Xr(t.privateKey,new ur(t.publicKey,n))}async function ec(r){if(r>Ks)throw new at("Key size is too large");let t=await nc(r),e=Hn(Zt.encode({Type:ot.RSA,Data:Fs(t.publicKey)})),n=Nt(ks,e);return new Xr(t.privateKey,new ur(t.publicKey,n))}function rc(r){if(r==null)throw new at("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function nc(r,t){let e=await Lt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await $l(e,t);return{privateKey:n[0],publicKey:n[1]}}async function Qa(r,t,e){let n=await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await Lt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ja(r,t,e,n){let o=await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Lt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function $l(r,t){if(r.privateKey==null||r.publicKey==null)throw new at("Private and public key are required");let e=await Promise.all([Lt.get().subtle.exportKey("jwk",r.privateKey),Lt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function oc(r){if(r.kty!=="RSA")throw new at("invalid key type");if(r.n==null)throw new at("invalid key modulus");return V(r.n,"base64url").length*8}var qn=class extends Je{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,_n(t);let n=kr(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),ee(s)}update(t){return tr(this),this.iHash.update(t),this}digestInto(t){tr(this),et(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},$s=(r,t,e)=>new qn(r,t).update(e).digest();$s.create=(r,t)=>new qn(r,t);var sc=(r,t)=>(r+(r>=0?t:-t)/ac)/t;function Zl(r,t,e){let[[n,o],[s,i]]=t,a=sc(i*r,e),c=sc(-o*r,e),u=r-a*n-c*s,d=-a*o-c*i,l=u<le,f=d<le;l&&(u=-u),f&&(d=-d);let h=Se(Math.ceil(On(e)/2))+lr;if(u<le||u>=h||d<le||d>=h)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:l,k1:u,k2neg:f,k2:d}}function ic(r){r.lowS!==void 0&&ne("lowS",r.lowS),r.prehash!==void 0&&ne("prehash",r.prehash)}var Zs=class extends Error{constructor(t=""){super(t)}},fe={Err:Zs,_tlv:{encode:(r,t)=>{let{Err:e}=fe;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=qr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?qr(o.length/2|128):"";return qr(r)+s+o+t},decode(r,t){let{Err:e}=fe,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let d of u)i=i<<8|d;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=fe;if(r<le)throw new t("integer: negative integers are not allowed");let e=qr(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=fe;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return er(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=fe,o=Z("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=fe,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},le=BigInt(0),lr=BigInt(1),ac=BigInt(2),zn=BigInt(3),Yl=BigInt(4);function Wl(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function fr(r,t){let{BYTES:e}=r,n;if(typeof t=="bigint")n=t;else{let o=Z("private key",t);try{n=r.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${e}, got ${typeof t}`)}}if(!r.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function jl(r,t={}){let{Fp:e,Fn:n}=Ln("weierstrass",r,t),{h:o,n:s}=r;ve(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||!Array.isArray(i.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(T,b,y){let{x:E,y:v}=b.toAffine(),P=e.toBytes(E);if(ne("isCompressed",y),y){a();let L=!e.isOdd(v);return St(cc(L),P)}else return St(Uint8Array.of(4),P,e.toBytes(v))}function u(T){et(T);let b=e.BYTES,y=b+1,E=2*b+1,v=T.length,P=T[0],L=T.subarray(1);if(v===y&&(P===2||P===3)){let w=e.fromBytes(L);if(!e.isValid(w))throw new Error("bad point: is not on curve, wrong x");let g=f(w),A;try{A=e.sqrt(g)}catch(U){let M=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+M)}a();let D=e.isOdd(A);return(P&1)===1!==D&&(A=e.neg(A)),{x:w,y:A}}else if(v===E&&P===4){let w=e.fromBytes(L.subarray(b*0,b*1)),g=e.fromBytes(L.subarray(b*1,b*2));if(!h(w,g))throw new Error("bad point: is not on curve");return{x:w,y:g}}else throw new Error(`bad point: got length ${v}, expected compressed=${y} or uncompressed=${E}`)}let d=t.toBytes||c,l=t.fromBytes||u,f=Wl(e,r.a,r.b);function h(T,b){let y=e.sqr(b),E=f(T);return e.eql(y,E)}if(!h(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let p=e.mul(e.pow(r.a,zn),Yl),m=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(p,m)))throw new Error("bad curve params: a or b");function x(T,b,y=!1){if(!e.isValid(b)||y&&e.is0(b))throw new Error(`bad point coordinate ${T}`);return b}function S(T){if(!(T instanceof _))throw new Error("ProjectivePoint expected")}function C(T){if(!i||!i.basises)throw new Error("no endo");return Zl(T,i.basises,n.ORDER)}let I=rr((T,b)=>{let{X:y,Y:E,Z:v}=T;if(e.eql(v,e.ONE))return{x:y,y:E};let P=T.is0();b==null&&(b=P?e.ONE:e.inv(v));let L=e.mul(y,b),w=e.mul(E,b),g=e.mul(v,b);if(P)return{x:e.ZERO,y:e.ZERO};if(!e.eql(g,e.ONE))throw new Error("invZ was invalid");return{x:L,y:w}}),B=rr(T=>{if(T.is0()){if(t.allowInfinityPoint&&!e.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:b,y}=T.toAffine();if(!e.isValid(b)||!e.isValid(y))throw new Error("bad point: x or y not field elements");if(!h(b,y))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function N(T,b,y,E,v){return y=new _(e.mul(y.X,T),y.Y,y.Z),b=Gr(E,b),y=Gr(v,y),b.add(y)}class _{constructor(b,y,E){this.X=x("x",b),this.Y=x("y",y,!0),this.Z=x("z",E),Object.freeze(this)}static fromAffine(b){let{x:y,y:E}=b||{};if(!b||!e.isValid(y)||!e.isValid(E))throw new Error("invalid affine point");if(b instanceof _)throw new Error("projective point not allowed");return e.is0(y)&&e.is0(E)?_.ZERO:new _(y,E,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}static normalizeZ(b){return ae(_,b)}static fromBytes(b){return et(b),_.fromHex(b)}static fromHex(b){let y=_.fromAffine(l(Z("pointHex",b)));return y.assertValidity(),y}static fromPrivateKey(b){return _.BASE.multiply(fr(n,b))}static msm(b,y){return sr(_,n,b,y)}_setWindowSize(b){this.precompute(b)}precompute(b=8,y=!0){return k.createCache(this,b),y||this.multiply(zn),this}assertValidity(){B(this)}hasEvenY(){let{y:b}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(b)}equals(b){S(b);let{X:y,Y:E,Z:v}=this,{X:P,Y:L,Z:w}=b,g=e.eql(e.mul(y,w),e.mul(P,v)),A=e.eql(e.mul(E,w),e.mul(L,v));return g&&A}negate(){return new _(this.X,e.neg(this.Y),this.Z)}double(){let{a:b,b:y}=r,E=e.mul(y,zn),{X:v,Y:P,Z:L}=this,w=e.ZERO,g=e.ZERO,A=e.ZERO,D=e.mul(v,v),R=e.mul(P,P),U=e.mul(L,L),M=e.mul(v,P);return M=e.add(M,M),A=e.mul(v,L),A=e.add(A,A),w=e.mul(b,A),g=e.mul(E,U),g=e.add(w,g),w=e.sub(R,g),g=e.add(R,g),g=e.mul(w,g),w=e.mul(M,w),A=e.mul(E,A),U=e.mul(b,U),M=e.sub(D,U),M=e.mul(b,M),M=e.add(M,A),A=e.add(D,D),D=e.add(A,D),D=e.add(D,U),D=e.mul(D,M),g=e.add(g,D),U=e.mul(P,L),U=e.add(U,U),D=e.mul(U,M),w=e.sub(w,D),A=e.mul(U,R),A=e.add(A,A),A=e.add(A,A),new _(w,g,A)}add(b){S(b);let{X:y,Y:E,Z:v}=this,{X:P,Y:L,Z:w}=b,g=e.ZERO,A=e.ZERO,D=e.ZERO,R=r.a,U=e.mul(r.b,zn),M=e.mul(y,P),W=e.mul(E,L),Y=e.mul(v,w),Ct=e.add(y,E),$=e.add(P,L);Ct=e.mul(Ct,$),$=e.add(M,W),Ct=e.sub(Ct,$),$=e.add(y,v);let it=e.add(P,w);return $=e.mul($,it),it=e.add(M,Y),$=e.sub($,it),it=e.add(E,v),g=e.add(L,w),it=e.mul(it,g),g=e.add(W,Y),it=e.sub(it,g),D=e.mul(R,$),g=e.mul(U,Y),D=e.add(g,D),g=e.sub(W,D),D=e.add(W,D),A=e.mul(g,D),W=e.add(M,M),W=e.add(W,M),Y=e.mul(R,Y),$=e.mul(U,$),W=e.add(W,Y),Y=e.sub(M,Y),Y=e.mul(R,Y),$=e.add($,Y),M=e.mul(W,$),A=e.add(A,M),M=e.mul(it,$),g=e.mul(Ct,g),g=e.sub(g,M),M=e.mul(Ct,W),D=e.mul(it,D),D=e.add(D,M),new _(g,A,D)}subtract(b){return this.add(b.negate())}is0(){return this.equals(_.ZERO)}multiply(b){let{endo:y}=t;if(!n.isValidNot0(b))throw new Error("invalid scalar: out of range");let E,v,P=L=>k.cached(this,L,w=>ae(_,w));if(y){let{k1neg:L,k1:w,k2neg:g,k2:A}=C(b),{p:D,f:R}=P(w),{p:U,f:M}=P(A);v=R.add(M),E=N(y.beta,D,U,L,g)}else{let{p:L,f:w}=P(b);E=L,v=w}return ae(_,[E,v])[0]}multiplyUnsafe(b){let{endo:y}=t,E=this;if(!n.isValid(b))throw new Error("invalid scalar: out of range");if(b===le||E.is0())return _.ZERO;if(b===lr)return E;if(k.hasCache(this))return this.multiply(b);if(y){let{k1neg:v,k1:P,k2neg:L,k2:w}=C(b),{p1:g,p2:A}=Na(_,E,P,w);return N(y.beta,g,A,v,L)}else return k.unsafe(E,b)}multiplyAndAddUnsafe(b,y,E){let v=this.multiplyUnsafe(y).add(b.multiplyUnsafe(E));return v.is0()?void 0:v}toAffine(b){return I(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return o===lr?!0:b?b(_,this):k.unsafe(this,s).is0()}clearCofactor(){let{clearCofactor:b}=t;return o===lr?this:b?b(_,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(b=!0){return ne("isCompressed",b),this.assertValidity(),d(_,this,b)}toRawBytes(b=!0){return this.toBytes(b)}toHex(b=!0){return Ot(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}_.BASE=new _(r.Gx,r.Gy,e.ONE),_.ZERO=new _(e.ZERO,e.ONE,e.ZERO),_.Fp=e,_.Fn=n;let K=n.BITS,k=new or(_,t.endo?Math.ceil(K/2):K);return _}function cc(r){return Uint8Array.of(r?2:3)}function Xl(r,t,e={}){_n(t),ve(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=e.randomBytes||Mr,o=e.hmac||((w,...g)=>$s(t,w,St(...g))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,u=os(a),d={secret:i.BYTES,public:1+s.BYTES,publicUncompressed:1+2*s.BYTES,signature:2*i.BYTES,seed:u};function l(w){let g=a>>lr;return w>g}function f(w){return l(w)?i.neg(w):w}function h(w,g){if(!i.isValidNot0(g))throw new Error(`invalid signature ${w}: out of range 1..CURVE.n`)}class p{constructor(g,A,D){h("r",g),h("s",A),this.r=g,this.s=A,D!=null&&(this.recovery=D),Object.freeze(this)}static fromBytes(g,A="compact"){if(A==="compact"){let D=i.BYTES;et(g,D*2);let R=g.subarray(0,D),U=g.subarray(D,D*2);return new p(i.fromBytes(R),i.fromBytes(U))}if(A==="der"){et(g);let{r:D,s:R}=fe.toSig(g);return new p(D,R)}throw new Error("invalid format")}static fromHex(g,A){return this.fromBytes(Le(g),A)}addRecoveryBit(g){return new p(this.r,this.s,g)}recoverPublicKey(g){let A=s.ORDER,{r:D,s:R,recovery:U}=this;if(U==null||![0,1,2,3].includes(U))throw new Error("recovery id invalid");if(a*ac<A&&U>1)throw new Error("recovery id is ambiguous for h>1 curve");let W=U===2||U===3?D+a:D;if(!s.isValid(W))throw new Error("recovery id 2 or 3 invalid");let Y=s.toBytes(W),Ct=r.fromHex(St(cc((U&1)===0),Y)),$=i.inv(W),it=K(Z("msgHash",g)),Dt=i.create(-it*$),pe=i.create(R*$),Ce=r.BASE.multiplyUnsafe(Dt).add(Ct.multiplyUnsafe(pe));if(Ce.is0())throw new Error("point at infinify");return Ce.assertValidity(),Ce}hasHighS(){return l(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,i.neg(this.s),this.recovery):this}toBytes(g="compact"){if(g==="compact")return St(i.toBytes(this.r),i.toBytes(this.s));if(g==="der")return Le(fe.hexFromSig(this));throw new Error("invalid format")}toHex(g){return Ot(this.toBytes(g))}assertValidity(){}static fromCompact(g){return p.fromBytes(Z("sig",g),"compact")}static fromDER(g){return p.fromBytes(Z("sig",g),"der")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Ot(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Ot(this.toBytes("compact"))}}function m(w){try{return!!fr(i,w)}catch{return!1}}function x(w,g){try{let A=w.length;return g===!0&&A!==d.public||g===!1&&A!==d.publicUncompressed?!1:!!r.fromBytes(w)}catch{return!1}}function S(w=n(u)){return ss(w,a)}let C={isValidSecretKey:m,isValidPublicKey:x,randomSecretKey:S,isValidPrivateKey:m,randomPrivateKey:S,normPrivateKeyToScalar:w=>fr(i,w),precompute(w=8,g=r.BASE){return g.precompute(w,!1)}};function I(w,g=!0){return r.BASE.multiply(fr(i,w)).toBytes(g)}function B(w){if(typeof w=="bigint")return!1;if(w instanceof r)return!0;if(i.allowedLengths||d.secret===d.public)return;let g=Z("key",w).length;return g===d.public||g===d.publicUncompressed}function N(w,g,A=!0){if(B(w)===!0)throw new Error("first arg must be private key");if(B(g)===!1)throw new Error("second arg must be public key");let D=fr(i,w);return r.fromHex(g).multiply(D).toBytes(A)}let _=e.bits2int||function(w){if(w.length>8192)throw new Error("input is too large");let g=er(w),A=w.length*8-c;return A>0?g>>BigInt(A):g},K=e.bits2int_modN||function(w){return i.create(_(w))},k=Se(c);function T(w){return Ee("num < 2^"+c,w,le,k),i.toBytes(w)}function b(w,g,A=y){if(["recovered","canonical"].some(Dt=>Dt in A))throw new Error("sign() legacy options not supported");let{lowS:D,prehash:R,extraEntropy:U}=A;D==null&&(D=!0),w=Z("msgHash",w),ic(A),R&&(w=Z("prehashed msgHash",t(w)));let M=K(w),W=fr(i,g),Y=[T(W),T(M)];if(U!=null&&U!==!1){let Dt=U===!0?n(d.secret):U;Y.push(Z("extraEntropy",Dt))}let Ct=St(...Y),$=M;function it(Dt){let pe=_(Dt);if(!i.isValidNot0(pe))return;let Ce=i.inv(pe),_r=r.BASE.multiply(pe).toAffine(),De=i.create(_r.x);if(De===le)return;let Cr=i.create(Ce*i.create($+De*W));if(Cr===le)return;let Ii=(_r.x===De?0:2)|Number(_r.y&lr),_i=Cr;return D&&l(Cr)&&(_i=f(Cr),Ii^=1),new p(De,_i,Ii)}return{seed:Ct,k2sig:it}}let y={lowS:e.lowS,prehash:!1},E={lowS:e.lowS,prehash:!1};function v(w,g,A=y){let{seed:D,k2sig:R}=b(w,g,A);return ga(t.outputLen,i.BYTES,o)(D,R)}r.BASE.precompute(8);function P(w,g,A,D=E){let R=w;g=Z("msgHash",g),A=Z("publicKey",A),ic(D);let{lowS:U,prehash:M,format:W}=D;if("strict"in D)throw new Error("options.strict was renamed to lowS");let Y,Ct;if(W===void 0){let $=typeof R=="string"||Oe(R),it=!$&&R!==null&&typeof R=="object"&&typeof R.r=="bigint"&&typeof R.s=="bigint";if(!$&&!it)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(it)Y=new p(R.r,R.s);else if($){try{Y=p.fromDER(R)}catch(Dt){if(!(Dt instanceof fe.Err))throw Dt}if(!Y)try{Y=p.fromCompact(R)}catch{return!1}}}else if(W==="compact"||W==="der"){if(typeof R!="string"&&!Oe(R))throw new Error('"der" / "compact" format expects Uint8Array signature');Y=p.fromBytes(Z("sig",R),W)}else if(W==="js"){if(!(R instanceof p))throw new Error('"js" format expects Signature instance');Y=R}else throw new Error('format must be "compact", "der" or "js"');if(!Y)return!1;try{if(Ct=r.fromHex(A),U&&Y.hasHighS())return!1;M&&(g=t(g));let{r:$,s:it}=Y,Dt=K(g),pe=i.inv(it),Ce=i.create(Dt*pe),_r=i.create($*pe),De=r.BASE.multiplyUnsafe(Ce).add(Ct.multiplyUnsafe(_r));return De.is0()?!1:i.create(De.x)===$}catch{return!1}}function L(w){let g=C.randomSecretKey(w);return{secretKey:g,publicKey:I(g)}}return Object.freeze({keygen:L,getPublicKey:I,sign:v,verify:P,getSharedSecret:N,utils:C,Point:r,Signature:p,info:{type:"weierstrass",lengths:d,publicKeyHasPrefix:!0}})}function Ql(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=r.allowedPrivateKeyLengths?Array.from(new Set(r.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=Bt(t.n,{BITS:r.nBitLength,allowedLengths:n,modOnDecode:r.wrapPrivateKey}),s={Fp:e,Fn:o,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:s}}function Jl(r){let{CURVE:t,curveOpts:e}=Ql(r),n={hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,hash:r.hash,ecdsaOpts:n}}function td(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function uc(r){let{CURVE:t,curveOpts:e,hash:n,ecdsaOpts:o}=Jl(r),s=jl(t,e),i=Xl(s,n,o);return td(r,i)}function fc(r,t){let e=n=>uc({...r,hash:n});return{...e(t),create:e}}var Ws={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ed={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var lc=BigInt(2);function rd(r){let t=Ws.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,d=u*u*r%t,l=X(d,e,t)*d%t,f=X(l,e,t)*d%t,h=X(f,lc,t)*u%t,p=X(h,o,t)*h%t,m=X(p,s,t)*p%t,x=X(m,a,t)*m%t,S=X(x,c,t)*x%t,C=X(S,a,t)*m%t,I=X(C,e,t)*d%t,B=X(I,i,t)*p%t,N=X(B,n,t)*u%t,_=X(N,lc,t);if(!Ys.eql(Ys.sqr(_),r))throw new Error("Cannot find square root");return _}var Ys=Bt(Ws.p,void 0,void 0,{sqrt:rd}),dr=fc({...Ws,Fp:Ys,lowS:!0,endo:ed},Tn);function dc(r,t,e,n){let o=Lr.digest(e instanceof Uint8Array?e:e.subarray());if(Kn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),dr.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new Zr(String(s))});try{return n?.signal?.throwIfAborted(),dr.verify(t,o.digest,r)}catch(s){throw new Zr(String(s))}}var Gn=class{type="secp256k1";raw;_key;constructor(t){this._key=pc(t),this.raw=hc(this._key)}toMultihash(){return Ut.digest(zt(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,e,n){return dc(this._key,e,t,n)}};function js(r){return new Gn(r)}function hc(r){return dr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function pc(r){try{return dr.ProjectivePoint.fromHex(r),r}catch(t){throw new Ze(String(t))}}function hr(r,t){let{Type:e,Data:n}=Zt.decode(r),o=n??new Uint8Array;switch(e){case ot.RSA:return qs(o,t);case ot.Ed25519:return ys(o);case ot.secp256k1:return js(o);case ot.ECDSA:return Zo(o);default:throw new Be}}function mc(r){let{Type:t,Data:e}=Zt.decode(r.digest),n=e??new Uint8Array;switch(t){case ot.Ed25519:return ys(n);case ot.secp256k1:return js(n);case ot.ECDSA:return Zo(n);default:throw new Be}}function zt(r){return Zt.encode({Type:ot[r.type],Data:r.raw})}var Jr;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={publicKey:dt(0),payloadType:dt(0),payload:dt(0),signature:dt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.publicKey=e.bytes();break}case 2:{s.payloadType=e.bytes();break}case 3:{s.payload=e.bytes();break}case 5:{s.signature=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Vt(e,r.codec()),r.decode=(e,n)=>Mt(e,r.codec(),n)})(Jr||(Jr={}));var $n=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Yt=class r{static createFromProtobuf=t=>{let e=Jr.decode(t),n=hr(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e,n)=>{if(e==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=yc(o,s,i),c=await e.sign(a.subarray(),n);return new r({publicKey:e.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,e,n)=>{let o=r.createFromProtobuf(t);if(!await o.validate(e,n))throw new $n("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:s}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Jr.encode({publicKey:zt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:ut(this.marshal(),t.marshal())}async validate(t,e){let n=yc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,e)}},yc=(r,t,e)=>{let n=V(r),o=ar(n.byteLength),s=ar(t.length),i=ar(e.length);return new nt(o,n,s,t,i,e)};var bc=Symbol.for("nodejs.util.inspect.custom"),nd=114,tn=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[xo]=!0;toString(){return this.string==null&&(this.string=J.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return st.createV1(nd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ut(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ut(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[bc](){return`PeerId(${this.toString()})`}},en=class extends tn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},rn=class extends tn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},nn=class extends tn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},od=2336,on=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ut.digest(V(this.url))}[bc](){return`PeerId(${this.url})`}[xo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return st.createV1(od,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=F(t)),t.toString()===this.toString())}};var sd=114,gc=2336;function xc(r){if(r.type==="Ed25519")return new rn({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new nn({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new en({multihash:r.toCID().multihash,publicKey:r});throw new Be}function Xs(r){if(ad(r))return new en({multihash:r});if(id(r))try{let t=mc(r);if(t.type==="Ed25519")return new rn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new nn({multihash:r,publicKey:t})}catch{let e=F(r.digest);return new on(new URL(e))}throw new xn("Supplied PeerID Multihash is invalid")}function Zn(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==sd&&r.code!==gc)throw new gn("Supplied PeerID CID is invalid");if(r.code===gc){let t=F(r.multihash.digest);return new on(new URL(t))}return Xs(r.multihash)}function id(r){return r.code===Ut.code}function ad(r){return r.code===Lr.code}function wc(r,t){let e=(n,o)=>n.toString().localeCompare(o.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,o)=>t[o].equals(n)))}var pt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},de=class extends Error{static name="ValidationError";name="ValidationError"},sn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Yn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Wn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let d=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let f=Number.parseInt(l,t);if(!Number.isNaN(f))return f});if(d===void 0)break;if(s*=t,s+=d,s>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ec=45,cd=15,pr=new Wn;function jn(r){if(!(r.length>cd))return pr.new(r).parseWith(()=>pr.readIPv4Addr())}function Xn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ec))return pr.new(r).parseWith(()=>pr.readIPv6Addr())}function mr(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Ec)return;let e=pr.new(r).parseWith(()=>pr.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function yr(r){return!!jn(r)}function Qn(r){return!!Xn(r)}function Js(r){return t=>F(t,r)}function ti(r){return t=>V(t,r)}function br(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function He(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Sc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=V(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=He(n);return Qt([e,o],e.length+o.length)}function vc(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=ye.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=He(n);return Qt([e,o],e.length+o.length)}function ei(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=F(t,"base32"),o=br(e);return`${n}:${o}`}var ri=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new pt("Invalid byte value in IP address");t[n]=o}),t},Ac=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=yr(e[n]),i;s&&(i=ri(e[n]),e[n]=F(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,F(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new pt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ic=function(r){if(r.byteLength!==4)throw new pt("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},_c=function(r){if(r.byteLength!==16)throw new pt("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new pt(`Invalid IPv6 address "${e}"`)}};function Cc(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new pt(`Invalid IPv6 address "${r}"`)}}var Qs=Object.values(Rr).map(r=>r.decoder),ud=function(){let r=Qs[0].or(Qs[1]);return Qs.slice(2).forEach(t=>r=r.or(t)),r}();function Dc(r){return ud.decode(r)}function Bc(r){return t=>r.encoder.encode(t)}function fd(r){if(parseInt(r).toString()!==r)throw new de("Value must be an integer")}function ld(r){if(r<0)throw new de("Value must be a positive integer, or zero")}function dd(r){return t=>{if(t>r)throw new de(`Value must be smaller than or equal to ${r}`)}}function hd(...r){return t=>{for(let e of r)e(t)}}var an=hd(fd,ld,dd(65535));var lt=-1,ni=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new Yn(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},It=new ni,Dd=[{code:4,name:"ip4",size:32,valueToBytes:ri,bytesToValue:Ic,validate:r=>{if(!yr(r))throw new de(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:He,bytesToValue:br,validate:an},{code:273,name:"udp",size:16,valueToBytes:He,bytesToValue:br,validate:an},{code:33,name:"dccp",size:16,valueToBytes:He,bytesToValue:br,validate:an},{code:41,name:"ip6",size:128,valueToBytes:Ac,bytesToValue:_c,stringToValue:Cc,validate:r=>{if(!Qn(r))throw new de(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:lt},{code:43,name:"ipcidr",size:8,bytesToValue:Js("base10"),valueToBytes:ti("base10")},{code:53,name:"dns",size:lt,resolvable:!0},{code:54,name:"dns4",size:lt,resolvable:!0},{code:55,name:"dns6",size:lt,resolvable:!0},{code:56,name:"dnsaddr",size:lt,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:He,bytesToValue:br,validate:an},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:lt,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:lt,bytesToValue:Js("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?ti("base58btc")(r):st.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ei,valueToBytes:Sc},{code:445,name:"onion3",size:296,bytesToValue:ei,valueToBytes:vc},{code:446,name:"garlic64",size:lt},{code:447,name:"garlic32",size:lt},{code:448,name:"tls"},{code:449,name:"sni",size:lt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:lt,bytesToValue:Bc(Ro),valueToBytes:Dc},{code:480,name:"http"},{code:481,name:"http-path",size:lt,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:lt}];Dd.forEach(r=>{It.addProtocol(r)});function Tc(r){let t=[],e=0;for(;e<r.length;){let n=Yr(r,e),o=It.getProtocol(n),s=vt(n),i=Bd(o,r,e+s),a=0;i>0&&o.size===lt&&(a=vt(i));let c=s+a+i,u={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let d=e+s+a,l=r.subarray(d,d+i);u.value=o.bytesToValue?.(l)??F(l)}t.push(u),e+=c}return t}function Pc(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=It.getProtocol(n.code),s=vt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===lt&&(c=vt(a)));let u=new Uint8Array(s+c+a),d=0;ir(n.code,u,d),d+=s,i!=null&&(o.size===lt&&(ir(a,u,d),d+=c),u.set(i,d)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return Qt(e,t)}function Oc(r){if(r.charAt(0)!=="/")throw new pt('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=It.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new pt(`Component ${o} was missing value`);e="value"}else if(e==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new pt(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new pt("Incomplete multiaddr");return t}function Lc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=It.getProtocol(t.code);if(e==null)throw new pt(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Bd(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Yr(t,e)}var Td=Symbol.for("nodejs.util.inspect.custom"),hi=Symbol.for("@multiformats/multiaddr"),Pd=[53,54,55,56],di=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function Od(r){if(r==null&&(r="/"),Nc(r))return r.getComponents();if(r instanceof Uint8Array)return Tc(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Oc(r);if(Array.isArray(r))return r;throw new pt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ro=class r{[hi]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Od(t),e.validate!==!1&&Ld(this)}get bytes(){return this.#r==null&&(this.#r=Pc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Lc(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="";for(let{code:a,name:c,value:u}of this.#t)a===42&&(s=`%${u??""}`),Pd.includes(a)&&(e="tcp",o=443,n=`${u??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(e=c==="tcp"?"tcp":"udp",o=parseInt(u??"")),(a===4||a===41)&&(e="tcp",n=`${u??""}${s}`,t=a===41?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:e})=>{let n=It.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:e})=>{if(e==null)return[t];let n=It.getProtocol(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??V(e)),o})}stringTuples(){return this.#t.map(({code:t,value:e})=>e==null?[t]:[t,e])}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new sn(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?F(J.decode(`z${n}`),"base58btc"):F(st.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(It.getProtocol(t.code).path)return t.value??null;return null}equals(t){return ut(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Rc.get(e.name);if(n==null)throw new di(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>jt(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[Td](){return`Multiaddr(${this.toString()})`}};function Ld(r){r.getComponents().forEach(t=>{let e=It.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function Uc(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function Kc(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function pi(r){switch(r.length){case ze:return r.join(".");case Ge:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function kc(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function Mc(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var ze=4,Ge=16,Cg=parseInt("0xFFFF",16),Rd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function dn(r,t){t.length===Ge&&r.length===ze&&Uc(t,0,11)&&(t=t.slice(12)),t.length===ze&&r.length===Ge&&Kc(r,Rd,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=r[o]&t[o];return n}function Vc(r,t){if(typeof t=="string"&&(t=mr(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function mi(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=ze,o=jn(t);if(o==null&&(n=Ge,o=Xn(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=yi(s,8*n);return{network:dn(o,i),mask:i}}function yi(r,t){if(t!==8*ze&&t!==8*Ge)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var vr=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=mi(t));else{let n=mr(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=mr(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=yi(o,8*n.length);this.network=dn(n,this.mask)}}contains(t){return Vc({network:this.network,mask:this.mask},t)}toString(){let t=kc(this.mask),e=t!==-1?String(t):Mc(this.mask);return pi(this.network)+"/"+e}};function Fc(r,t){return new vr(r).contains(t)}var Rc=new Map;function Nc(r){return!!r?.[hi]}function jt(r){return new ro(r)}function no(r){let t=It.getProtocol(r);return{code:t.code,size:t.size??0,name:t.name,resolvable:!!t.resolvable,path:!!t.path}}var Hc="libp2p-peer-record",qc=Uint8Array.from([3,1]);var hn;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=Ft((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:dt(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let d=s.uint32();switch(d>>>3){case 1:{c.multiaddr=s.bytes();break}default:{s.skipType(d&7);break}}}return c})),o),n.encode=s=>Vt(s,n.codec()),n.decode=(s,i)=>Mt(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=Ft((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),r.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:dt(0),seq:0n,addresses:[]},a=o==null?n.len:n.pos+o;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new Fe('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),e),r.encode=n=>Vt(n,r.codec()),r.decode=(n,o)=>Mt(n,r.codec(),o)})(hn||(hn={}));var Ht=class r{static createFromProtobuf=t=>{let e=hn.decode(t),n=Xs(Pr(e.peerId)),o=(e.addresses??[]).map(i=>jt(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Hc;static CODEC=qc;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:o}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=hn.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof r)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!wc(this.multiaddrs,t.multiaddrs))}};function zc(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}function Nd(r){return r[Symbol.asyncIterator]!=null}function Ud(r){if(Nd(r))return(async()=>{for await(let t of r);})();for(let t of r);}var Gc=Ud;function qt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var oo=globalThis.CustomEvent??Event;async function*bi(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered??!1,o=new EventTarget,s=[],i=qt(),a=qt(),c=!1,u,d=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of r){if(s.length===e&&(i=qt(),await i.promise),d)break;let m={done:!1};s.push(m),p().then(x=>{m.done=!0,m.ok=!0,m.value=x,o.dispatchEvent(new oo("task-complete"))},x=>{m.done=!0,m.err=x,o.dispatchEvent(new oo("task-complete"))})}c=!0,o.dispatchEvent(new oo("task-complete"))}catch(p){u=p,o.dispatchEvent(new oo("task-complete"))}});function l(){return n?s[0]?.done:!!s.find(p=>p.done)}function*f(){for(;s.length>0&&s[0].done;){let p=s[0];if(s.shift(),p.ok)yield p.value;else throw d=!0,i.resolve(),p.err;i.resolve()}}function*h(){for(;l();)for(let p=0;p<s.length;p++)if(s[p].done){let m=s[p];if(s.splice(p,1),p--,m.ok)yield m.value;else throw d=!0,i.resolve(),m.err;i.resolve()}}for(;;){if(l()||(a=qt(),await a.promise),u!=null||(n?yield*f():yield*h(),u!=null))throw u;if(c&&s.length===0)break}}var so=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function pn(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new so(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new so(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var gi=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=qt(),this.haveNext=qt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=qt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=qt(),await pn(this.readNext.promise,e?.signal,e)}};function $c(){return new gi}var io=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Zc(r,t){let e=$c();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new nt;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:c,value:u}=await pn(n.next(),i?.signal);return c===!0?null:u}for(;o.byteLength<i.bytes;){let{value:c,done:u}=await pn(n.next(),i?.signal);if(u===!0)throw new io("unexpected end of input");o.append(c)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var ao=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},co=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},uo=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Yc(r,t={}){let e=Zc(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=vt(t.maxDataLength));let n=t?.lengthDecoder??Yr,o=t?.lengthEncoder??ar;return{read:async i=>{let a=-1,c=new nt;for(;;){c.append(await e.read({...i,bytes:1}));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new ao("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new uo("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new co("message length too long");return e.read({...i,bytes:a})},write:async(i,a)=>{await e.write(new nt(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new nt(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function Ar(r,t){let e=Yc(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(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:()=>e.unwrap()};return n}var Wc="0.1.0";var jc="id/push",Xc="1.0.0",Qc="1.0.0";var _e;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.protocolVersion!=null&&(n.uint32(42),n.string(e.protocolVersion)),e.agentVersion!=null&&(n.uint32(50),n.string(e.agentVersion)),e.publicKey!=null&&(n.uint32(10),n.bytes(e.publicKey)),e.listenAddrs!=null)for(let s of e.listenAddrs)n.uint32(18),n.bytes(s);if(e.observedAddr!=null&&(n.uint32(34),n.bytes(e.observedAddr)),e.protocols!=null)for(let s of e.protocols)n.uint32(26),n.string(s);e.signedPeerRecord!=null&&(n.uint32(66),n.bytes(e.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={listenAddrs:[],protocols:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 5:{s.protocolVersion=e.string();break}case 6:{s.agentVersion=e.string();break}case 1:{s.publicKey=e.bytes();break}case 2:{if(o.limits?.listenAddrs!=null&&s.listenAddrs.length===o.limits.listenAddrs)throw new Fe('Decode error - map field "listenAddrs" had too many elements');s.listenAddrs.push(e.bytes());break}case 4:{s.observedAddr=e.bytes();break}case 3:{if(o.limits?.protocols!=null&&s.protocols.length===o.limits.protocols)throw new Fe('Decode error - map field "protocols" had too many elements');s.protocols.push(e.string());break}case 8:{s.signedPeerRecord=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Vt(e,r.codec()),r.decode=(e,n)=>Mt(e,r.codec(),n)})(_e||(_e={}));var _t={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Jc(r){if(r!=null&&r.length>0)try{return jt(r)}catch{}}function Md(r,t){return t??r.userAgent}async function fo(r,t,e,n,o){if(e("received identify from %p",n.remotePeer),o==null)throw new Rt("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(c=>({isCertified:!1,multiaddr:jt(c)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let c=hr(o.publicKey);if(!xc(c).equals(n.remotePeer))throw new Rt("public key did not match remote PeerId");s.publicKey=c}let i;if(o.signedPeerRecord!=null){e.trace("received signedPeerRecord from %p",n.remotePeer);let c=o.signedPeerRecord,u=await Yt.openAndCertify(c,Ht.DOMAIN),d=Ht.createFromProtobuf(u.payload),l=Zn(u.publicKey.toCID());if(!d.peerId.equals(l))throw new Rt("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(d.peerId))throw new Rt("signing key does not match remote PeerId");let f;try{f=await r.get(d.peerId)}catch(h){if(h.name!=="NotFoundError")throw h}if(f!=null&&(s.metadata=f.metadata,f.peerRecordEnvelope!=null)){let h=Yt.createFromProtobuf(f.peerRecordEnvelope),p=Ht.createFromProtobuf(h.payload);p.seqNumber>=d.seqNumber&&(e("sequence number was lower or equal to existing sequence number - stored: %d received: %d",p.seqNumber,d.seqNumber),d=p,c=f.peerRecordEnvelope)}s.peerRecordEnvelope=c,s.addresses=d.multiaddrs.map(h=>({isCertified:!0,multiaddr:h})),i={seq:d.seqNumber,addresses:d.multiaddrs}}else e("%p did not send a signed peer record",n.remotePeer);if(e.trace("patching %p with",n.remotePeer,s),await r.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let c={};o.agentVersion!=null&&(c.AgentVersion=V(o.agentVersion)),o.protocolVersion!=null&&(c.ProtocolVersion=V(o.protocolVersion)),e.trace("merging %p metadata",n.remotePeer,c),await r.merge(n.remotePeer,{metadata:c})}let a={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(c=>jt(c)),observedAddr:o.observedAddr==null?void 0:jt(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:a}),a}var Ir=class{host;protocol;started;timeout;peerId;privateKey;peerStore;registrar;addressManager;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;events;runOnLimitedConnection;log;constructor(t,e){this.protocol=e.protocol,this.started=!1,this.peerId=t.peerId,this.privateKey=t.privateKey,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.events=t.events,this.log=e.log,this.timeout=e.timeout??_t.timeout,this.maxInboundStreams=e.maxInboundStreams??_t.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??_t.maxOutboundStreams,this.maxMessageSize=e.maxMessageSize??_t.maxMessageSize,this.maxObservedAddresses=e.maxObservedAddresses??_t.maxObservedAddresses,this.runOnLimitedConnection=e.runOnLimitedConnection??_t.runOnLimitedConnection,this.host={protocolVersion:`${e.protocolPrefix??_t.protocolPrefix}/${Wc}`,agentVersion:Md(t.nodeInfo,e.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:V(this.host.agentVersion),ProtocolVersion:V(this.host.protocolVersion)}}),await this.registrar.handle(this.protocol,t=>{this.handleProtocol(t).catch(e=>{this.log.error(e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.registrar.unhandle(this.protocol),this.started=!1}};var lo=class extends Ir{connectionManager;concurrency;_push;constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??_t.protocolPrefix}/${jc}/${Qc}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=e.concurrency??_t.concurrency,this._push=zc(this.sendPushMessage.bind(this),e.debounce??1e3),(e.runOnSelfUpdate??_t.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[En]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let t=this.addressManager.getAddresses().map(d=>d.decapsulateCode(no("p2p").code)),e=new Ht({peerId:this.peerId,multiaddrs:t}),n=await Yt.seal(e,this.privateKey),o=this.registrar.getProtocols(),s=await this.peerStore.get(this.peerId),i=F(s.metadata.get("AgentVersion")??V(this.host.agentVersion)),a=F(s.metadata.get("ProtocolVersion")??V(this.host.protocolVersion)),c=this;async function*u(){for(let d of c.connectionManager.getConnections()){let l=await c.peerStore.get(d.remotePeer),f=d.log.newScope("identify-push");l.protocols.includes(c.protocol)&&(yield async()=>{let h,p=AbortSignal.timeout(c.timeout);try{h=await d.newStream(c.protocol,{signal:p,runOnLimitedConnection:c.runOnLimitedConnection}),await Ar(h,{maxDataLength:c.maxMessageSize}).pb(_e).write({listenAddrs:t.map(x=>x.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:p}),await h.close({signal:p})}catch(m){f.error("could not push identify update to peer",m),h?.abort(m)}})}}await Gc(bi(u(),{concurrency:this.concurrency}))}catch(t){this.log.error("error pushing updates to peers - %e",t)}}async handleProtocol(t){let{connection:e,stream:n}=t,o=e.log.newScope("identify-push");try{if(this.peerId.equals(e.remotePeer))throw new Error("received push from ourselves?");let s={signal:AbortSignal.timeout(this.timeout)},a=await Ar(n,{maxDataLength:this.maxMessageSize}).pb(_e).read(s);await n.close(s),await fo(this.peerStore,this.events,o,e,a)}catch(s){o.error("received invalid message",s),n.abort(s);return}o.trace("handled push from %p",e.remotePeer)}};function tu(r){try{for(let{code:t,value:e}of r.getComponents())if(e!=null&&t===41)return Fc("2000::/3",e)}catch{}return!1}var ru=wu(eu(),1),Fd=["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"],Hd=Fd.map(r=>new ru.Netmask(r));function xi(r){for(let t of Hd)if(t.contains(r))return!0;return!1}function qd(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function zd(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return xi(o)}function Gd(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function $d(r){let t=r.split(":"),e=t[t.length-1];return xi(e)}function Zd(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function nu(r){if(yr(r))return xi(r);if(qd(r))return zd(r);if(Gd(r))return $d(r);if(Qn(r))return Zd(r)}function ou(r){try{for(let{code:t}of r.getComponents())if(t!==42)return t===4||t===41}catch{}return!1}function su(r){try{if(!ou(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:nu(t)??!1}catch{}return!0}var Q=r=>({match:t=>{let e=t[0];return e==null||e.code!==r||e.value!=null?!1:t.slice(1)}}),O=(r,t)=>({match:e=>{let n=e[0];return n?.code!==r||n.value==null||t!=null&&n.value!==t?!1:e.slice(1)}}),H=r=>({match:t=>{let e=r.match(t);return e===!1?t:e}}),bt=(...r)=>({match:t=>{let e;for(let n of r){let o=n.match(t);o!==!1&&(e==null||o.length<e.length)&&(e=o)}return e??!1}}),G=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t}});function j(...r){function t(o){if(o==null)return!1;let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function e(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:r,matches:e,exactMatch:n}}var Yd=O(421),Cw=j(Yd),po=O(54),mo=O(55),yo=O(56),Ei=O(53),Dw=j(po,H(O(421))),Bw=j(mo,H(O(421))),Tw=j(yo,H(O(421))),Pw=j(bt(Ei,yo,po,mo),H(O(421))),iu=G(O(4),H(O(43))),au=G(H(O(42)),O(41),H(O(43))),Si=bt(iu,au),$e=bt(Si,Ei,po,mo,yo),cu=j(bt(Si,G(bt(Ei,yo,po,mo),H(O(421))))),Ow=j(iu),Lw=j(au),Rw=j(Si),vi=G($e,O(6)),yn=G($e,O(273)),uu=j(G(vi,H(O(421)))),Nw=j(yn),Ai=G(yn,Q(460),H(O(421))),bo=G(yn,Q(461),H(O(421))),Wd=bt(Ai,bo),Uw=j(Ai),Kw=j(bo),wi=bt($e,vi,yn,Ai,bo),fu=bt(G(wi,Q(477),H(O(421)))),kw=j(fu),lu=bt(G(wi,Q(478),H(O(421))),G(wi,Q(448),H(O(449)),Q(477),H(O(421)))),Mw=j(lu),du=G(yn,Q(280),H(O(466)),H(O(466)),H(O(421))),Vw=j(du),hu=G(bo,Q(465),H(O(466)),H(O(466)),H(O(421))),Fw=j(hu),ho=bt(fu,lu,G(vi,H(O(421))),G(Wd,H(O(421))),G($e,H(O(421))),du,hu,O(421)),Hw=j(ho),jd=G(ho,Q(290),O(421)),qw=j(jd),Xd=bt(G(ho,Q(290),Q(281),H(O(421))),G(ho,Q(281),H(O(421))),G(Q(281),H(O(421)))),zw=j(Xd),Qd=bt(G($e,O(6),Q(480),H(O(421))),G($e,Q(480),H(O(421)))),Gw=j(Qd),Jd=G($e,bt(G(O(6,"443"),Q(480)),G(O(6),Q(443)),G(O(6),Q(448),Q(480)),G(Q(448),Q(480)),Q(448),Q(443)),H(O(421))),$w=j(Jd),th=bt(G(O(777),H(O(421)))),Zw=j(th),eh=bt(G(O(400),H(O(421)))),Yw=j(eh);var go=class extends Ir{constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??_t.protocolPrefix}/${"id"}/${Xc}`,log:t.logger.forComponent("libp2p:identify")}),(e.runOnConnectionOpen??_t.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(s=>{s.name!==wn.name&&this.log.error("error during identify trigged by connection:open",s)})})}[En]=["@libp2p/identify"];async _identify(t,e={}){let n;if(e.signal==null){let o=AbortSignal.timeout(this.timeout);e={...e,signal:o}}try{n=await t.newStream(this.protocol,{...e,runOnLimitedConnection:this.runOnLimitedConnection});let s=await Ar(n,{maxDataLength:this.maxMessageSize}).pb(_e).read(e);return await n.close(e),s}catch(o){throw n?.abort(o),o}}async identify(t,e={}){let n=await this._identify(t,e),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Rt("Public key was missing from identify message");let a=hr(o),c=Zn(a.toCID()),u=t.log.newScope("identify");if(!t.remotePeer.equals(c))throw new Rt("Identified peer does not match the expected peer");if(this.peerId.equals(c))throw new Rt("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i,u),u("completed for peer %p and protocols %o",c,s),fo(this.peerStore,this.events,u,t,n)}maybeAddObservedAddress(t,e){let n=Jc(t);if(n==null)return;if(e.trace("our observed address was %a",n),su(n)){this.log.trace("our observed address was private");return}let o=n.getComponents();if((o[0].code===41||o[0].code===42&&o[1].code===41)&&!tu(n)){e.trace("our observed address was IPv6 but not a global unicast address");return}uu.exactMatch(n)||(e.trace("storing the observed address"),this.addressManager.addObservedAddr(n))}async handleProtocol(t){let{connection:e,stream:n}=t,o=e.log.newScope("identify"),s=AbortSignal.timeout(this.timeout);try{let i=await this.peerStore.get(this.peerId),a=this.addressManager.getAddresses().map(l=>l.decapsulateCode(no("p2p").code)),c=i.peerRecordEnvelope;if(a.length>0&&c==null){let l=new Ht({peerId:this.peerId,multiaddrs:a});c=(await Yt.seal(l,this.privateKey)).marshal().subarray()}let u=e.remoteAddr.bytes;cu.matches(e.remoteAddr)||(u=void 0),await Ar(n).pb(_e).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:zt(this.privateKey.publicKey),listenAddrs:a.map(l=>l.bytes),signedPeerRecord:c,observedAddr:u,protocols:i.protocols},{signal:s}),await n.close({signal:s})}catch(i){o.error("could not respond to identify request",i),n.abort(i)}}};function nh(r={}){return t=>new go(t,r)}function oh(r={}){return t=>new lo(t,r)}return Eu(sh);})();
2
+ "use strict";var Libp2PIdentify=(()=>{var gu=Object.create;var yn=Object.defineProperty;var xu=Object.getOwnPropertyDescriptor;var wu=Object.getOwnPropertyNames;var Eu=Object.getPrototypeOf,Su=Object.prototype.hasOwnProperty;var vu=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),vt=(e,t)=>{for(var r in t)yn(e,r,{get:t[r],enumerable:!0})},Oi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of wu(t))!Su.call(e,o)&&o!==r&&yn(e,o,{get:()=>t[o],enumerable:!(n=xu(t,o))||n.enumerable});return e};var Au=(e,t,r)=>(r=e!=null?gu(Eu(e)):{},Oi(t||!e||!e.__esModule?yn(r,"default",{value:e,enumerable:!0}):r,e)),Iu=e=>Oi(yn({},"__esModule",{value:!0}),e);var su=vu(hn=>{(function(){var e,t,r,n,o,s,i,c;c=function(a){var u,d,l,f;return u=(a&255<<24)>>>24,d=(a&255<<16)>>>16,l=(a&65280)>>>8,f=a&255,[u,d,l,f].join(".")},i=function(a){var u,d,l,f,p,h;for(u=[],l=f=0;f<=3&&a.length!==0;l=++f){if(l>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}h=t(a),p=h[0],d=h[1],a=a.substring(d),u.push(p)}if(a.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},r=function(a){return a.charCodeAt(0)},n=r("0"),s=r("a"),o=r("A"),t=function(a){var u,d,l,f,p;for(f=0,u=10,d="9",l=0,a.length>1&&a[l]==="0"&&(a[l+1]==="x"||a[l+1]==="X"?(l+=2,u=16):"0"<=a[l+1]&&a[l+1]<="9"&&(l++,u=8,d="7")),p=l;l<a.length;){if("0"<=a[l]&&a[l]<=d)f=f*u+(r(a[l])-n)>>>0;else if(u===16)if("a"<=a[l]&&a[l]<="f")f=f*u+(10+r(a[l])-s)>>>0;else if("A"<=a[l]&&a[l]<="F")f=f*u+(10+r(a[l])-o)>>>0;else break;else break;if(f>4294967295)throw new Error("too large");l++}if(l===p)throw new Error("empty octet");return[f,l]},e=function(){function a(u,d){var l,f,p,h;if(typeof u!="string")throw new Error("Missing `net' parameter");if(d||(h=u.split("/",2),u=h[0],d=h[1]),d||(d=32),typeof d=="string"&&d.indexOf(".")>-1){try{this.maskLong=i(d)}catch(g){throw l=g,new Error("Invalid mask: "+d)}for(f=p=32;p>=0;f=--p)if(this.maskLong===4294967295<<32-f>>>0){this.bitmask=f;break}}else if(d||d===0)this.bitmask=parseInt(d,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(u)&this.maskLong)>>>0}catch(g){throw l=g,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+d);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new a(u)),u instanceof a?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(u){return u==null&&(u=1),new a(c(this.netLong+this.size*u),this.mask)},a.prototype.forEach=function(u){var d,l,f;for(f=i(this.first),l=i(this.last),d=0;f<=l;)u(c(f),f,d),d++,f++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a}(),hn.ip2long=i,hn.long2ip=c,hn.Netmask=e}).call(hn)});var uh={};vt(uh,{identify:()=>ah,identifyPush:()=>ch});var xo=Symbol.for("@libp2p/peer-id");var ct=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},$e=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var bn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},gn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},xn=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},Ut=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var De=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var wn=Symbol.for("@libp2p/service-capabilities"),hh=Symbol.for("@libp2p/service-dependencies");var Ao={};vt(Ao,{base58btc:()=>Q,base58flickr:()=>Ou});var Nh=new Uint8Array(0);function Li(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Qt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ri(e){return new TextEncoder().encode(e)}function Ni(e){return new TextDecoder().decode(e)}function _u(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),d=Math.log(256)/Math.log(c);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var g=0,v=0,x=0,A=h.length;x!==A&&h[x]===0;)x++,g++;for(var E=(A-x)*d+1>>>0,P=new Uint8Array(E);x!==A;){for(var R=h[x],F=0,V=E-1;(R!==0||F<v)&&V!==-1;V--,F++)R+=256*P[V]>>>0,P[V]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");v=F,x++}for(var N=E-v;N!==E&&P[N]===0;)N++;for(var w=a.repeat(g);N<E;++N)w+=e.charAt(P[N]);return w}function f(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var g=0;if(h[g]!==" "){for(var v=0,x=0;h[g]===a;)v++,g++;for(var A=(h.length-g)*u+1>>>0,E=new Uint8Array(A);h[g];){var P=r[h.charCodeAt(g)];if(P===255)return;for(var R=0,F=A-1;(P!==0||R<x)&&F!==-1;F--,R++)P+=c*E[F]>>>0,E[F]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");x=R,g++}if(h[g]!==" "){for(var V=A-x;V!==A&&E[V]===0;)V++;for(var N=new Uint8Array(v+(A-V)),w=v;V!==A;)N[w++]=E[V++];return N}}}function p(h){var g=f(h);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:f,decode:p}}var Cu=_u,Bu=Cu,Ki=Bu;var wo=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Eo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ki(this,t)}},So=class{decoders;constructor(t){this.decoders=t}or(t){return ki(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ki(e,t){return new So({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var vo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new wo(t,r,n),this.decoder=new Eo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ge({name:e,prefix:t,encode:r,decode:n}){return new vo(e,t,r,n)}function ye({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ki(r,e);return Ge({prefix:t,name:e,encode:n,decode:s=>Qt(o(s))})}function Du(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let d=t[e[u]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|d,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Pu(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Tu(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function rt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Tu(n);return Ge({prefix:t,name:e,encode(s){return Pu(s,n,r)},decode(s){return Du(s,o,r,e)}})}var Q=ye({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ou=ye({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Io={};vt(Io,{base32:()=>be,base32hex:()=>Uu,base32hexpad:()=>ku,base32hexpadupper:()=>Mu,base32hexupper:()=>Ku,base32pad:()=>Ru,base32padupper:()=>Nu,base32upper:()=>Lu,base32z:()=>Vu});var be=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Lu=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ru=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Nu=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Uu=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ku=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ku=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Mu=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Vu=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _o={};vt(_o,{base36:()=>_r,base36upper:()=>Fu});var _r=ye({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Fu=ye({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var qu=Fi,Mi=128,Hu=127,zu=~Hu,$u=Math.pow(2,31);function Fi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=$u;)t[r++]=e&255|Mi,e/=128;for(;e&zu;)t[r++]=e&255|Mi,e>>>=7;return t[r]=e|0,Fi.bytes=r-n+1,t}var Gu=Co,Zu=128,Vi=127;function Co(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw Co.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Vi)<<o:(i&Vi)*Math.pow(2,o),o+=7}while(i>=Zu);return Co.bytes=s-n,r}var Yu=Math.pow(2,7),Wu=Math.pow(2,14),ju=Math.pow(2,21),Xu=Math.pow(2,28),Qu=Math.pow(2,35),Ju=Math.pow(2,42),tf=Math.pow(2,49),ef=Math.pow(2,56),rf=Math.pow(2,63),nf=function(e){return e<Yu?1:e<Wu?2:e<ju?3:e<Xu?4:e<Qu?5:e<Ju?6:e<tf?7:e<ef?8:e<rf?9:10},of={encode:qu,decode:Gu,encodingLength:nf},sf=of,Cr=sf;function Br(e,t=0){return[Cr.decode(e,t),Cr.decode.bytes]}function Ze(e,t,r=0){return Cr.encode(e,t,r),t}function Ye(e){return Cr.encodingLength(e)}function Kt(e,t){let r=t.byteLength,n=Ye(e),o=n+Ye(r),s=new Uint8Array(o+r);return Ze(e,s,0),Ze(r,s,n),s.set(t,o),new We(e,r,t,s)}function Dr(e){let t=Qt(e),[r,n]=Br(t),[o,s]=Br(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new We(r,o,i,t)}function qi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Li(e.bytes,r.bytes)}}var We=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Hi(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return cf(r,Bo(e),t??Q.encoder);default:return uf(r,Bo(e),t??be.encoder)}}var zi=new WeakMap;function Bo(e){let t=zi.get(e);if(t==null){let r=new Map;return zi.set(e,r),r}return t}var it=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Pr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ff)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Kt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&qi(t.multihash,n.multihash)}toString(t){return Hi(this,t)}toJSON(){return{"/":Hi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??$i(n,o,s.bytes))}else if(r[lf]===!0){let{version:n,multihash:o,code:s}=r,i=Dr(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Pr)throw new Error(`Version 0 CID must use dag-pb (code: ${Pr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=$i(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Pr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Qt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new We(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,f]=Br(t.subarray(r));return r+=f,l},o=n(),s=Pr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),u=r+a,d=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:d,size:u}}static parse(t,r){let[n,o]=af(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Bo(s).set(n,t),s}};function af(e,t){switch(e[0]){case"Q":{let r=t??Q;return[Q.prefix,r.decode(`${Q.prefix}${e}`)]}case Q.prefix:{let r=t??Q;return[Q.prefix,r.decode(e)]}case be.prefix:{let r=t??be;return[be.prefix,r.decode(e)]}case _r.prefix:{let r=t??_r;return[_r.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function cf(e,t,r){let{prefix:n}=r;if(n!==Q.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function uf(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Pr=112,ff=18;function $i(e,t,r){let n=Ye(e),o=n+Ye(t),s=new Uint8Array(o+r.byteLength);return Ze(e,s,0),Ze(t,s,n),s.set(r,o),s}var lf=Symbol.for("@ipld/js-cid/CID");var Do={};vt(Do,{identity:()=>kt});var Gi=0,df="identity",Zi=Qt;function hf(e){return Kt(Gi,Zi(e))}var kt={code:Gi,name:df,encode:Zi,digest:hf};function ut(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ht(e=0){return new Uint8Array(e)}function At(e=0){return new Uint8Array(e)}function Jt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=At(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Wi=Symbol.for("@achingbrain/uint8arraylist");function Yi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Sn(e){return!!e?.[Wi]}var ot=class e{bufs;length;[Wi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Sn(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Sn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Yi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Yi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Sn(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Jt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Jt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,d=r>c&&r<=a;if(u&&d){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(d){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Sn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,d;for(let l=r;l<=a;l+=d){d=0;for(let f=u;f>=0;f--){let p=this.get(l+f);if(n[f]!==p){d=Math.max(1,f-c[p]);break}}if(d===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=At(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=At(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ut(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Po={};vt(Po,{base10:()=>pf});var pf=ye({prefix:"9",name:"base10",alphabet:"0123456789"});var To={};vt(To,{base16:()=>mf,base16upper:()=>yf});var mf=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),yf=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Oo={};vt(Oo,{base2:()=>bf});var bf=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Lo={};vt(Lo,{base256emoji:()=>Sf});var ji=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}"),gf=ji.reduce((e,t,r)=>(e[r]=t,e),[]),xf=ji.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function wf(e){return e.reduce((t,r)=>(t+=gf[r],t),"")}function Ef(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=xf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Sf=Ge({prefix:"\u{1F680}",name:"base256emoji",encode:wf,decode:Ef});var No={};vt(No,{base64:()=>vf,base64pad:()=>Af,base64url:()=>Ro,base64urlpad:()=>If});var vf=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Af=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ro=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),If=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Uo={};vt(Uo,{base8:()=>_f});var _f=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ko={};vt(Ko,{identity:()=>Cf});var Cf=Ge({prefix:"\0",name:"identity",encode:e=>Ni(e),decode:e=>Ri(e)});var gp=new TextEncoder,xp=new TextDecoder;var Vo={};vt(Vo,{sha256:()=>Tr,sha512:()=>Pf});function Mo({name:e,code:t,encode:r}){return new ko(e,t,r)}var ko=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?Kt(this.code,r):r.then(n=>Kt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Qi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Tr=Mo({name:"sha2-256",code:18,encode:Qi("SHA-256")}),Pf=Mo({name:"sha2-512",code:19,encode:Qi("SHA-512")});var Or={...Ko,...Oo,...Uo,...Po,...To,...Io,..._o,...Ao,...No,...Lo},Tp={...Vo,...Do};function ta(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ji=ta("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Fo=ta("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=At(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Tf={utf8:Ji,"utf-8":Ji,hex:Or.base16,latin1:Fo,ascii:Fo,binary:Fo,...Or},vn=Tf;function k(e,t="utf8"){let r=vn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function M(e,t="utf8"){let r=vn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Of=parseInt("11111",2),qo=parseInt("10000000",2),Lf=parseInt("01111111",2),ea={0:Lr,1:Lr,2:Rf,3:Kf,4:kf,5:Uf,6:Nf,16:Lr,22:Lr,48:Lr};function te(e,t={offset:0}){let r=e[t.offset]&Of;if(t.offset++,ea[r]!=null)return ea[r](e,t);throw new Error("No decoder for tag "+r)}function Rr(e,t){let r=0;if((e[t.offset]&qo)===qo){let n=e[t.offset]&Lf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Lr(e,t){Rr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=te(e,t);if(n===null)break;r.push(n)}return r}function Rf(e,t){let r=Rr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Nf(e,t){let r=Rr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let d=0;for(let l=0;l<a.length;l++)d+=a[l]<<l*7;c+=`.${d}`,a=[]}}return c}function Uf(e,t){return t.offset++,null}function Kf(e,t){let r=Rr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function kf(e,t){let r=Rr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Mf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ot;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Ho(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Mf(e.byteLength);return new ot(Uint8Array.from([t.byteLength|qo]),t)}function It(e){let t=new ot,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ot(Uint8Array.from([2]),Ho(t),t)}function An(e){let t=Uint8Array.from([0]),r=new ot(t,e);return new ot(Uint8Array.from([3]),Ho(r),r)}function ge(e,t=48){let r=new ot;for(let n of e)r.append(n);return new ot(Uint8Array.from([t]),Ho(r),r)}async function ra(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var Vf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ff=Uint8Array.from([6,5,43,129,4,0,34]),qf=Uint8Array.from([6,5,43,129,4,0,35]),Hf={ext:!0,kty:"EC",crv:"P-256"},zf={ext:!0,kty:"EC",crv:"P-384"},$f={ext:!0,kty:"EC",crv:"P-521"},zo=32,$o=48,Go=66;function Zo(e){let t=te(e);return na(t)}function na(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===zo*2+1)return n=M(t.subarray(r,r+zo),"base64url"),o=M(t.subarray(r+zo),"base64url"),new je({...Hf,key_ops:["verify"],x:n,y:o});if(t.byteLength===$o*2+1)return n=M(t.subarray(r,r+$o),"base64url"),o=M(t.subarray(r+$o),"base64url"),new je({...zf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Go*2+1)return n=M(t.subarray(r,r+Go),"base64url"),o=M(t.subarray(r+Go),"base64url"),new je({...$f,key_ops:["verify"],x:n,y:o});throw new ct(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function oa(e){return ge([It(Uint8Array.from([1])),ge([Gf(e.crv)],160),ge([An(new ot(Uint8Array.from([4]),k(e.x??"","base64url"),k(e.y??"","base64url")))],161)]).subarray()}function Gf(e){if(e==="P-256")return Vf;if(e==="P-384")return Ff;if(e==="P-521")return qf;throw new ct(`Invalid curve ${e}`)}var je=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=oa(this.jwk)),this._raw}toMultihash(){return kt.digest(Gt(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}async verify(t,r,n){return ra(this.jwk,r,t,n)}};var Te=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function re(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Nr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function _t(e,...t){if(!re(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function In(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Nr(e.outputLen),Nr(e.blockLen)}function Qe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function ia(e,t){_t(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function ne(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function _n(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Mt(e,t){return e<<32-t|e>>>t}var aa=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Zf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Rt(e){if(_t(e),aa)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Zf[e[r]];return t}var ee={_0:48,_9:57,A:65,F:70,a:97,f:102};function sa(e){if(e>=ee._0&&e<=ee._9)return e-ee._0;if(e>=ee.A&&e<=ee.F)return e-(ee.A-10);if(e>=ee.a&&e<=ee.f)return e-(ee.a-10)}function Oe(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(aa)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=sa(e.charCodeAt(s)),c=sa(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Yo(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Ur(e){return typeof e=="string"&&(e=Yo(e)),_t(e),e}function wt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];_t(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Xe=class{};function Wo(e){let t=n=>e().update(Ur(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Je(e=32){if(Te&&typeof Te.getRandomValues=="function")return Te.getRandomValues(new Uint8Array(e));if(Te&&typeof Te.randomBytes=="function")return Uint8Array.from(Te.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Yf(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+u,c,n)}function ca(e,t,r){return e&t^~e&r}function ua(e,t,r){return e&t^e&r^t&r}var Kr=class extends Xe{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=_n(this.buffer)}update(t){Qe(this),t=Ur(t),_t(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=_n(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Qe(this),ia(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,ne(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;Yf(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=_n(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,d[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},oe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var pt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Cn=BigInt(4294967295),fa=BigInt(32);function Wf(e,t=!1){return t?{h:Number(e&Cn),l:Number(e>>fa&Cn)}:{h:Number(e>>fa&Cn)|0,l:Number(e&Cn)|0}}function la(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Wf(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var jo=(e,t,r)=>e>>>r,Xo=(e,t,r)=>e<<32-r|t>>>r,Le=(e,t,r)=>e>>>r|t<<32-r,Re=(e,t,r)=>e<<32-r|t>>>r,kr=(e,t,r)=>e<<64-r|t>>>r-32,Mr=(e,t,r)=>e>>>r-32|t<<64-r;function Zt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var da=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ha=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,pa=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ma=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ya=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ba=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Xf=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]),xe=new Uint32Array(64),Bn=class extends Kr{constructor(t=32){super(64,t,8,!1),this.A=oe[0]|0,this.B=oe[1]|0,this.C=oe[2]|0,this.D=oe[3]|0,this.E=oe[4]|0,this.F=oe[5]|0,this.G=oe[6]|0,this.H=oe[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)xe[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let f=xe[l-15],p=xe[l-2],h=Mt(f,7)^Mt(f,18)^f>>>3,g=Mt(p,17)^Mt(p,19)^p>>>10;xe[l]=g+xe[l-7]+h+xe[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:d}=this;for(let l=0;l<64;l++){let f=Mt(c,6)^Mt(c,11)^Mt(c,25),p=d+f+ca(c,a,u)+Xf[l]+xe[l]|0,g=(Mt(n,2)^Mt(n,13)^Mt(n,22))+ua(n,o,s)|0;d=u,u=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+g|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,o,s,i,c,a,u,d)}roundClean(){ne(xe)}destroy(){this.set(0,0,0,0,0,0,0,0),ne(this.buffer)}};var ga=la(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Qf=ga[0],Jf=ga[1],we=new Uint32Array(80),Ee=new Uint32Array(80),Qo=class extends Kr{constructor(t=64){super(128,t,16,!1),this.Ah=pt[0]|0,this.Al=pt[1]|0,this.Bh=pt[2]|0,this.Bl=pt[3]|0,this.Ch=pt[4]|0,this.Cl=pt[5]|0,this.Dh=pt[6]|0,this.Dl=pt[7]|0,this.Eh=pt[8]|0,this.El=pt[9]|0,this.Fh=pt[10]|0,this.Fl=pt[11]|0,this.Gh=pt[12]|0,this.Gl=pt[13]|0,this.Hh=pt[14]|0,this.Hl=pt[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:d,Fh:l,Fl:f,Gh:p,Gl:h,Hh:g,Hl:v}=this;return[t,r,n,o,s,i,c,a,u,d,l,f,p,h,g,v]}set(t,r,n,o,s,i,c,a,u,d,l,f,p,h,g,v){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=d|0,this.Fh=l|0,this.Fl=f|0,this.Gh=p|0,this.Gl=h|0,this.Hh=g|0,this.Hl=v|0}process(t,r){for(let E=0;E<16;E++,r+=4)we[E]=t.getUint32(r),Ee[E]=t.getUint32(r+=4);for(let E=16;E<80;E++){let P=we[E-15]|0,R=Ee[E-15]|0,F=Le(P,R,1)^Le(P,R,8)^jo(P,R,7),V=Re(P,R,1)^Re(P,R,8)^Xo(P,R,7),N=we[E-2]|0,w=Ee[E-2]|0,B=Le(N,w,19)^kr(N,w,61)^jo(N,w,6),U=Re(N,w,19)^Mr(N,w,61)^Xo(N,w,6),D=pa(V,U,Ee[E-7],Ee[E-16]),b=ma(D,F,B,we[E-7],we[E-16]);we[E]=b|0,Ee[E]=D|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:d,Eh:l,El:f,Fh:p,Fl:h,Gh:g,Gl:v,Hh:x,Hl:A}=this;for(let E=0;E<80;E++){let P=Le(l,f,14)^Le(l,f,18)^kr(l,f,41),R=Re(l,f,14)^Re(l,f,18)^Mr(l,f,41),F=l&p^~l&g,V=f&h^~f&v,N=ya(A,R,V,Jf[E],Ee[E]),w=ba(N,x,P,F,Qf[E],we[E]),B=N|0,U=Le(n,o,28)^kr(n,o,34)^kr(n,o,39),D=Re(n,o,28)^Mr(n,o,34)^Mr(n,o,39),b=n&s^n&c^s&c,m=o&i^o&a^i&a;x=g|0,A=v|0,g=p|0,v=h|0,p=l|0,h=f|0,{h:l,l:f}=Zt(u|0,d|0,w|0,B|0),u=c|0,d=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let y=da(B,D,m);n=ha(y,w,U,b),o=y|0}({h:n,l:o}=Zt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Zt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Zt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:d}=Zt(this.Dh|0,this.Dl|0,u|0,d|0),{h:l,l:f}=Zt(this.Eh|0,this.El|0,l|0,f|0),{h:p,l:h}=Zt(this.Fh|0,this.Fl|0,p|0,h|0),{h:g,l:v}=Zt(this.Gh|0,this.Gl|0,g|0,v|0),{h:x,l:A}=Zt(this.Hh|0,this.Hl|0,x|0,A|0),this.set(n,o,s,i,c,a,u,d,l,f,p,h,g,v,x,A)}roundClean(){ne(we,Ee)}destroy(){ne(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Dn=Wo(()=>new Bn);var xa=Wo(()=>new Qo);var es=BigInt(0),ts=BigInt(1);function se(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Tt(e,t,r=""){let n=re(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function Vr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function wa(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?es:BigInt("0x"+e)}function tr(e){return wa(Rt(e))}function ie(e){return _t(e),wa(Rt(Uint8Array.from(e).reverse()))}function Pn(e,t){return Oe(e.toString(16).padStart(t*2,"0"))}function rs(e,t){return Pn(e,t).reverse()}function Z(e,t,r){let n;if(typeof t=="string")try{n=Oe(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(re(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function Ea(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function ns(e){return Uint8Array.from(e)}var Jo=e=>typeof e=="bigint"&&es<=e;function Sa(e,t,r){return Jo(e)&&Jo(t)&&Jo(r)&&t<=e&&e<r}function Fr(e,t,r,n){if(!Sa(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Tn(e){let t;for(t=0;e>es;e>>=ts,t+=1);return t}var Se=e=>(ts<<BigInt(e))-ts;function va(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=p=>new Uint8Array(p),o=p=>Uint8Array.of(p),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},u=(...p)=>r(i,s,...p),d=(p=n(0))=>{i=u(o(0),p),s=u(),p.length!==0&&(i=u(o(1),p),s=u())},l=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,h=[];for(;p<t;){s=u();let g=s.slice();h.push(g),p+=s.length}return wt(...h)};return(p,h)=>{a(),d(p);let g;for(;!(g=h(l()));)d();return a(),g}}function ve(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var os=()=>{throw new Error("not implemented")};function er(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var Et=BigInt(0),ft=BigInt(1),Ne=BigInt(2),_a=BigInt(3),Ca=BigInt(4),Ba=BigInt(5),tl=BigInt(7),Da=BigInt(8),el=BigInt(9),Pa=BigInt(16);function nt(e,t){let r=e%t;return r>=Et?r:t+r}function j(e,t,r){let n=e;for(;t-- >Et;)n*=n,n%=r;return n}function Aa(e,t){if(e===Et)throw new Error("invert: expected non-zero number");if(t<=Et)throw new Error("invert: expected positive modulus, got "+t);let r=nt(e,t),n=t,o=Et,s=ft,i=ft,c=Et;for(;r!==Et;){let u=n/r,d=n%r,l=o-i*u,f=s-c*u;n=r,r=d,o=i,s=c,i=l,c=f}if(n!==ft)throw new Error("invert: does not exist");return nt(o,t)}function ss(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ta(e,t){let r=(e.ORDER+ft)/Ca,n=e.pow(t,r);return ss(e,n,t),n}function rl(e,t){let r=(e.ORDER-Ba)/Da,n=e.mul(t,Ne),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Ne),o),c=e.mul(s,e.sub(i,e.ONE));return ss(e,c,t),c}function nl(e){let t=Ot(e),r=Oa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+tl)/Pa;return(c,a)=>{let u=c.pow(a,i),d=c.mul(u,n),l=c.mul(u,o),f=c.mul(u,s),p=c.eql(c.sqr(d),a),h=c.eql(c.sqr(l),a);u=c.cmov(u,d,p),d=c.cmov(f,l,h);let g=c.eql(c.sqr(d),a),v=c.cmov(u,d,g);return ss(c,v,a),v}}function Oa(e){if(e<_a)throw new Error("sqrt is not defined for small field");let t=e-ft,r=0;for(;t%Ne===Et;)t/=Ne,r++;let n=Ne,o=Ot(e);for(;Ia(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ta;let s=o.pow(n,t),i=(t+ft)/Ne;return function(a,u){if(a.is0(u))return u;if(Ia(a,u)!==1)throw new Error("Cannot find square root");let d=r,l=a.mul(a.ONE,s),f=a.pow(u,t),p=a.pow(u,i);for(;!a.eql(f,a.ONE);){if(a.is0(f))return a.ZERO;let h=1,g=a.sqr(f);for(;!a.eql(g,a.ONE);)if(h++,g=a.sqr(g),h===d)throw new Error("Cannot find square root");let v=ft<<BigInt(d-h-1),x=a.pow(l,v);d=h,l=a.sqr(x),f=a.mul(f,l),p=a.mul(p,x)}return p}}function ol(e){return e%Ca===_a?Ta:e%Da===Ba?rl:e%Pa===el?nl(e):Oa(e)}var ae=(e,t)=>(nt(e,t)&ft)===ft,sl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function is(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=sl.reduce((n,o)=>(n[o]="function",n),t);return ve(e,r),e}function il(e,t,r){if(r<Et)throw new Error("invalid exponent, negatives unsupported");if(r===Et)return e.ONE;if(r===ft)return t;let n=e.ONE,o=t;for(;r>Et;)r&ft&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ft;return n}function qr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function Ia(e,t){let r=(e.ORDER-ft)/Ne,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function On(e,t){t!==void 0&&Nr(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Ot(e,t,r=!1,n={}){if(e<=Et)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),c=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:u}=On(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,l=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:u,MASK:Se(a),ZERO:Et,ONE:ft,allowedLengths:c,create:f=>nt(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return Et<=f&&f<e},is0:f=>f===Et,isValidNot0:f=>!l.is0(f)&&l.isValid(f),isOdd:f=>(f&ft)===ft,neg:f=>nt(-f,e),eql:(f,p)=>f===p,sqr:f=>nt(f*f,e),add:(f,p)=>nt(f+p,e),sub:(f,p)=>nt(f-p,e),mul:(f,p)=>nt(f*p,e),pow:(f,p)=>il(l,f,p),div:(f,p)=>nt(f*Aa(p,e),e),sqrN:f=>f*f,addN:(f,p)=>f+p,subN:(f,p)=>f-p,mulN:(f,p)=>f*p,inv:f=>Aa(f,e),sqrt:s||(f=>(d||(d=ol(e)),d(l,f))),toBytes:f=>r?rs(f,u):Pn(f,u),fromBytes:(f,p=!0)=>{if(c){if(!c.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+f.length);let g=new Uint8Array(u);g.set(f,r?0:g.length-f.length),f=g}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let h=r?ie(f):tr(f);if(i&&(h=nt(h,e)),!p&&!l.isValid(h))throw new Error("invalid field element: outside of range 0..ORDER");return h},invertBatch:f=>qr(l,f),cmov:(f,p,h)=>h?p:f});return Object.freeze(l)}function La(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function as(e){let t=La(e);return t+Math.ceil(t/2)}function cs(e,t,r=!1){let n=e.length,o=La(t),s=as(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ie(e):tr(e),c=nt(i,t-ft)+ft;return r?rs(c,o):Pn(c,o)}var rr=BigInt(0),Ue=BigInt(1);function Hr(e,t){let r=t.negate();return e?r:t}function ce(e,t){let r=qr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Ka(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function us(e,t){Ka(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Se(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ra(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=Ue);let u=t*n,d=u+Math.abs(c)-1,l=c===0,f=c<0,p=t%2!==0;return{nextN:a,offset:d,isZero:l,isNeg:f,isNegF:p,offsetF:u}}function al(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function cl(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var fs=new WeakMap,ka=new WeakMap;function ls(e){return ka.get(e)||1}function Na(e){if(e!==rr)throw new Error("invalid wNAF")}var nr=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>rr;)r&Ue&&(n=n.add(o)),o=o.double(),r>>=Ue;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=us(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=us(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:d,isNeg:l,isNegF:f,offsetF:p}=Ra(n,c,i);n=a,d?s=s.add(Hr(f,r[p])):o=o.add(Hr(l,r[u]))}return Na(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=us(t,this.bits);for(let i=0;i<s.windows&&n!==rr;i++){let{nextN:c,offset:a,isZero:u,isNeg:d}=Ra(n,i,s);if(n=c,!u){let l=r[a];o=o.add(d?l.negate():l)}}return Na(n),o}getPrecomputes(t,r,n){let o=fs.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),fs.set(r,o))),o}cached(t,r,n){let o=ls(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=ls(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Ka(r,this.bits),ka.set(t,r),fs.delete(t)}hasCache(t){return ls(t)!==1}};function Ma(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>rr||n>rr;)r&Ue&&(s=s.add(o)),n&Ue&&(i=i.add(o)),o=o.double(),r>>=Ue,n>>=Ue;return{p1:s,p2:i}}function or(e,t,r,n){al(r,e),cl(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Tn(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=Se(a),d=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/a)*a,f=i;for(let p=l;p>=0;p-=a){d.fill(i);for(let g=0;g<s;g++){let v=n[g],x=Number(v>>BigInt(p)&u);d[x]=d[x].add(r[g])}let h=i;for(let g=d.length-1,v=i;g>0;g--)v=v.add(d[g]),h=h.add(v);if(f=f.add(h),p!==0)for(let g=0;g<a;g++)f=f.double()}return f}function Ua(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return is(t),t}else return Ot(e,{isLE:r})}function Ln(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>rr))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Ua(t.p,r.Fp,n),s=Ua(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var Ae=BigInt(0),lt=BigInt(1),ds=BigInt(2),ul=BigInt(8);function fl(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function ll(e,t={}){let r=Ln("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;ve(t,{},{uvRatio:"function"});let c=ds<<BigInt(o.BYTES*8)-lt,a=v=>n.create(v),u=t.uvRatio||((v,x)=>{try{return{isValid:!0,value:n.sqrt(n.div(v,x))}}catch{return{isValid:!1,value:Ae}}});if(!fl(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function d(v,x,A=!1){let E=A?lt:Ae;return Fr("coordinate "+v,x,E,c),x}function l(v){if(!(v instanceof h))throw new Error("ExtendedPoint expected")}let f=er((v,x)=>{let{X:A,Y:E,Z:P}=v,R=v.is0();x==null&&(x=R?ul:n.inv(P));let F=a(A*x),V=a(E*x),N=n.mul(P,x);if(R)return{x:Ae,y:lt};if(N!==lt)throw new Error("invZ was invalid");return{x:F,y:V}}),p=er(v=>{let{a:x,d:A}=s;if(v.is0())throw new Error("bad point: ZERO");let{X:E,Y:P,Z:R,T:F}=v,V=a(E*E),N=a(P*P),w=a(R*R),B=a(w*w),U=a(V*x),D=a(w*a(U+N)),b=a(B+a(A*a(V*N)));if(D!==b)throw new Error("bad point: equation left != right (1)");let m=a(E*P),y=a(R*F);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(x,A,E,P){this.X=d("x",x),this.Y=d("y",A),this.Z=d("z",E,!0),this.T=d("t",P),Object.freeze(this)}static CURVE(){return s}static fromAffine(x){if(x instanceof h)throw new Error("extended point not allowed");let{x:A,y:E}=x||{};return d("x",A),d("y",E),new h(A,E,lt,a(A*E))}static fromBytes(x,A=!1){let E=n.BYTES,{a:P,d:R}=s;x=ns(Tt(x,E,"point")),se(A,"zip215");let F=ns(x),V=x[E-1];F[E-1]=V&-129;let N=ie(F),w=A?c:n.ORDER;Fr("point.y",N,Ae,w);let B=a(N*N),U=a(B-lt),D=a(R*B-P),{isValid:b,value:m}=u(U,D);if(!b)throw new Error("bad point: invalid y coordinate");let y=(m&lt)===lt,S=(V&128)!==0;if(!A&&m===Ae&&S)throw new Error("bad point: x=0 and x_0=1");return S!==y&&(m=a(-m)),h.fromAffine({x:m,y:N})}static fromHex(x,A=!1){return h.fromBytes(Z("point",x),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,A=!0){return g.createCache(this,x),A||this.multiply(ds),this}assertValidity(){p(this)}equals(x){l(x);let{X:A,Y:E,Z:P}=this,{X:R,Y:F,Z:V}=x,N=a(A*V),w=a(R*P),B=a(E*V),U=a(F*P);return N===w&&B===U}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:x}=s,{X:A,Y:E,Z:P}=this,R=a(A*A),F=a(E*E),V=a(ds*a(P*P)),N=a(x*R),w=A+E,B=a(a(w*w)-R-F),U=N+F,D=U-V,b=N-F,m=a(B*D),y=a(U*b),S=a(B*b),I=a(D*U);return new h(m,y,I,S)}add(x){l(x);let{a:A,d:E}=s,{X:P,Y:R,Z:F,T:V}=this,{X:N,Y:w,Z:B,T:U}=x,D=a(P*N),b=a(R*w),m=a(V*E*U),y=a(F*B),S=a((P+R)*(N+w)-D-b),I=y-m,T=y+m,_=a(b-A*D),C=a(S*I),L=a(T*_),K=a(S*_),J=a(I*T);return new h(C,L,J,K)}subtract(x){return this.add(x.negate())}multiply(x){if(!o.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:E}=g.cached(this,x,P=>ce(h,P));return ce(h,[A,E])[0]}multiplyUnsafe(x,A=h.ZERO){if(!o.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===Ae?h.ZERO:this.is0()||x===lt?this:g.unsafe(this,x,E=>ce(h,E),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return g.unsafe(this,s.n).is0()}toAffine(x){return f(this,x)}clearCofactor(){return i===lt?this:this.multiplyUnsafe(i)}toBytes(){let{x,y:A}=this.toAffine(),E=n.toBytes(A);return E[E.length-1]|=x&lt?128:0,E}toHex(){return Rt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(x){return ce(h,x)}static msm(x,A){return or(h,o,x,A)}_setWindowSize(x){this.precompute(x)}toRawBytes(){return this.toBytes()}}h.BASE=new h(s.Gx,s.Gy,lt,a(s.Gx*s.Gy)),h.ZERO=new h(Ae,lt,lt,Ae),h.Fp=n,h.Fn=o;let g=new nr(h,o.BITS);return h.BASE.precompute(8),h}var Rn=class{constructor(t){this.ep=t}static fromBytes(t){os()}static fromHex(t){os()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Rt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function dl(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ve(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||Je,a=r.adjustScalarBytes||(w=>w),u=r.domain||((w,B,U)=>{if(se(U,"phflag"),B.length||U)throw new Error("Contexts/pre-hash are not supported");return w});function d(w){return i.create(ie(w))}function l(w){let B=E.secretKey;w=Z("private key",w,B);let U=Z("hashed private key",t(w),2*B),D=a(U.slice(0,B)),b=U.slice(B,2*B),m=d(D);return{head:D,prefix:b,scalar:m}}function f(w){let{head:B,prefix:U,scalar:D}=l(w),b=o.multiply(D),m=b.toBytes();return{head:B,prefix:U,scalar:D,point:b,pointBytes:m}}function p(w){return f(w).pointBytes}function h(w=Uint8Array.of(),...B){let U=wt(...B);return d(t(u(U,Z("context",w),!!n)))}function g(w,B,U={}){w=Z("message",w),n&&(w=n(w));let{prefix:D,scalar:b,pointBytes:m}=f(B),y=h(U.context,D,w),S=o.multiply(y).toBytes(),I=h(U.context,S,m,w),T=i.create(y+I*b);if(!i.isValid(T))throw new Error("sign failed: invalid s");let _=wt(S,i.toBytes(T));return Tt(_,E.signature,"result")}let v={zip215:!0};function x(w,B,U,D=v){let{context:b,zip215:m}=D,y=E.signature;w=Z("signature",w,y),B=Z("message",B),U=Z("publicKey",U,E.publicKey),m!==void 0&&se(m,"zip215"),n&&(B=n(B));let S=y/2,I=w.subarray(0,S),T=ie(w.subarray(S,y)),_,C,L;try{_=e.fromBytes(U,m),C=e.fromBytes(I,m),L=o.multiplyUnsafe(T)}catch{return!1}if(!m&&_.isSmallOrder())return!1;let K=h(b,C.toBytes(),_.toBytes(),B);return C.add(_.multiplyUnsafe(K)).subtract(L).clearCofactor().is0()}let A=s.BYTES,E={secretKey:A,publicKey:A,signature:2*A,seed:A};function P(w=c(E.seed)){return Tt(w,E.seed,"seed")}function R(w){let B=N.randomSecretKey(w);return{secretKey:B,publicKey:p(B)}}function F(w){return re(w)&&w.length===i.BYTES}function V(w,B){try{return!!e.fromBytes(w,B)}catch{return!1}}let N={getExtendedPublicKey:f,randomSecretKey:P,isValidSecretKey:F,isValidPublicKey:V,toMontgomery(w){let{y:B}=e.fromBytes(w),U=E.publicKey,D=U===32;if(!D&&U!==57)throw new Error("only defined for 25519 and 448");let b=D?s.div(lt+B,lt-B):s.div(B-lt,B+lt);return s.toBytes(b)},toMontgomeryPriv(w){let B=E.secretKey;Tt(w,B);let U=t(w.subarray(0,B));return a(U).subarray(0,B)},randomPrivateKey:P,precompute(w=8,B=e.BASE){return B.precompute(w,!1)}};return Object.freeze({keygen:R,getPublicKey:p,sign:g,verify:x,utils:N,Point:e,lengths:E})}function hl(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=Ot(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function pl(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Va(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=hl(e),s=ll(t,r),i=dl(s,n,o);return pl(e,i)}var ml=BigInt(0),ue=BigInt(1),Fa=BigInt(2),M0=BigInt(3),yl=BigInt(5),bl=BigInt(8),sr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),zr={p:sr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:bl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function gl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=sr,c=e*e%s*e%s,a=j(c,Fa,s)*c%s,u=j(a,ue,s)*e%s,d=j(u,yl,s)*u%s,l=j(d,t,s)*d%s,f=j(l,r,s)*l%s,p=j(f,n,s)*f%s,h=j(p,o,s)*p%s,g=j(h,o,s)*p%s,v=j(g,t,s)*d%s;return{pow_p_5_8:j(v,Fa,s)*e%s,b2:c}}function xl(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var hs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ys(e,t){let r=sr,n=nt(t*t*t,r),o=nt(n*n*t,r),s=gl(e*o).pow_p_5_8,i=nt(e*n*s,r),c=nt(t*i*i,r),a=i,u=nt(i*hs,r),d=c===e,l=c===nt(-e,r),f=c===nt(-e*hs,r);return d&&(i=a),(l||f)&&(i=u),ae(i,r)&&(i=nt(-i,r)),{isValid:d||l,value:i}}var Ie=Ot(zr.p,{isLE:!0}),wl=Ot(zr.n,{isLE:!0}),El={...zr,Fp:Ie,hash:xa,adjustScalarBytes:xl,uvRatio:ys},fe=Va(El);var ps=hs,Sl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),vl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Al=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Il=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),qa=e=>ys(ue,e),_l=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),ms=e=>fe.Point.Fp.create(ie(e)&_l);function Ha(e){let{d:t}=zr,r=sr,n=x=>Ie.create(x),o=n(ps*e*e),s=n((o+ue)*Al),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:u}=ys(s,c),d=n(u*e);ae(d,r)||(d=n(-d)),a||(u=d),a||(i=o);let l=n(i*(o-ue)*Il-c),f=u*u,p=n((u+u)*c),h=n(l*Sl),g=n(ue-f),v=n(ue+f);return new fe.Point(n(p*v),n(g*h),n(h*v),n(p*g))}function Cl(e){_t(e,64);let t=ms(e.subarray(0,32)),r=Ha(t),n=ms(e.subarray(32,64)),o=Ha(n);return new le(r.add(o))}var le=class e extends Rn{constructor(t){super(t)}static fromAffine(t){return new e(fe.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Cl(Z("ristrettoHash",t,64))}static fromBytes(t){_t(t,32);let{a:r,d:n}=zr,o=sr,s=P=>Ie.create(P),i=ms(t);if(!Ea(Ie.toBytes(i),t)||ae(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(ue+r*c),u=s(ue-r*c),d=s(a*a),l=s(u*u),f=s(r*n*d-l),{isValid:p,value:h}=qa(s(f*l)),g=s(h*u),v=s(h*g*f),x=s((i+i)*g);ae(x,o)&&(x=s(-x));let A=s(a*v),E=s(x*A);if(!p||ae(E,o)||A===ml)throw new Error("invalid ristretto255 encoding 2");return new e(new fe.Point(x,A,ue,E))}static fromHex(t){return e.fromBytes(Z("ristrettoHex",t,32))}static msm(t,r){return or(e,fe.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=sr,i=v=>Ie.create(v),c=i(i(n+r)*i(n-r)),a=i(t*r),u=i(a*a),{value:d}=qa(i(c*u)),l=i(d*c),f=i(d*a),p=i(l*f*o),h;if(ae(o*p,s)){let v=i(r*ps),x=i(t*ps);t=v,r=x,h=i(l*vl)}else h=f;ae(t*p,s)&&(r=i(-r));let g=i((n-r)*h);return ae(g,s)&&(g=i(-g)),Ie.toBytes(g)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>Ie.create(u),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};le.BASE=new le(fe.Point.BASE);le.ZERO=new le(fe.Point.ZERO);le.Fp=Ie;le.Fn=wl;var $r=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Nn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var za={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Nn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Nt=za;var Un=32;var bs,Bl=(async()=>{try{return await Nt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Dl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Nt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Nt.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Pl(e,t,r){return fe.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function $a(e,t,r){return bs==null&&(bs=await Bl),bs?Dl(e,t,r):Pl(e,t,r)}function Kn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var kn=class{type="Ed25519";raw;constructor(t){this.raw=gs(t,Un)}toMultihash(){return kt.digest(Gt(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=$a(this.raw,r,t);return Kn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function xs(e){return e=gs(e,Un),new kn(e)}function gs(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new ct(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Ol=Math.pow(2,7),Ll=Math.pow(2,14),Rl=Math.pow(2,21),ws=Math.pow(2,28),Es=Math.pow(2,35),Ss=Math.pow(2,42),vs=Math.pow(2,49),$=128,bt=127;function Ct(e){if(e<Ol)return 1;if(e<Ll)return 2;if(e<Rl)return 3;if(e<ws)return 4;if(e<Es)return 5;if(e<Ss)return 6;if(e<vs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ir(e,t,r=0){switch(Ct(e)){case 8:t[r++]=e&255|$,e/=128;case 7:t[r++]=e&255|$,e/=128;case 6:t[r++]=e&255|$,e/=128;case 5:t[r++]=e&255|$,e/=128;case 4:t[r++]=e&255|$,e>>>=7;case 3:t[r++]=e&255|$,e>>>=7;case 2:t[r++]=e&255|$,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Nl(e,t,r=0){switch(Ct(e)){case 8:t.set(r++,e&255|$),e/=128;case 7:t.set(r++,e&255|$),e/=128;case 6:t.set(r++,e&255|$),e/=128;case 5:t.set(r++,e&255|$),e/=128;case 4:t.set(r++,e&255|$),e>>>=7;case 3:t.set(r++,e&255|$),e>>>=7;case 2:t.set(r++,e&255|$),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function As(e,t){let r=e[t],n=0;if(n+=r&bt,r<$||(r=e[t+1],n+=(r&bt)<<7,r<$)||(r=e[t+2],n+=(r&bt)<<14,r<$)||(r=e[t+3],n+=(r&bt)<<21,r<$)||(r=e[t+4],n+=(r&bt)*ws,r<$)||(r=e[t+5],n+=(r&bt)*Es,r<$)||(r=e[t+6],n+=(r&bt)*Ss,r<$)||(r=e[t+7],n+=(r&bt)*vs,r<$))return n;throw new RangeError("Could not decode varint")}function Ul(e,t){let r=e.get(t),n=0;if(n+=r&bt,r<$||(r=e.get(t+1),n+=(r&bt)<<7,r<$)||(r=e.get(t+2),n+=(r&bt)<<14,r<$)||(r=e.get(t+3),n+=(r&bt)<<21,r<$)||(r=e.get(t+4),n+=(r&bt)*ws,r<$)||(r=e.get(t+5),n+=(r&bt)*Es,r<$)||(r=e.get(t+6),n+=(r&bt)*Ss,r<$)||(r=e.get(t+7),n+=(r&bt)*vs,r<$))return n;throw new RangeError("Could not decode varint")}function ar(e,t,r=0){return t==null&&(t=At(Ct(e))),t instanceof Uint8Array?ir(e,t,r):Nl(e,t,r)}function Gr(e,t=0){return e instanceof Uint8Array?As(e,t):Ul(e,t)}var _s=new Float32Array([-0]),_e=new Uint8Array(_s.buffer);function Za(e,t,r){_s[0]=e,t[r]=_e[0],t[r+1]=_e[1],t[r+2]=_e[2],t[r+3]=_e[3]}function Ya(e,t){return _e[0]=e[t],_e[1]=e[t+1],_e[2]=e[t+2],_e[3]=e[t+3],_s[0]}var Cs=new Float64Array([-0]),gt=new Uint8Array(Cs.buffer);function Wa(e,t,r){Cs[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function ja(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],Cs[0]}var Kl=BigInt(Number.MAX_SAFE_INTEGER),kl=BigInt(Number.MIN_SAFE_INTEGER),Lt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ke;if(t<Kl&&t>kl)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Xa&&(o=0n,++n>Xa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ke;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Ke}},Ke=new Lt(0,0);Ke.toBigInt=function(){return 0n};Ke.zzEncode=Ke.zzDecode=function(){return this};Ke.length=function(){return 1};var Xa=4294967296n;function Qa(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ja(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Bs(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Vt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Mn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Ds=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Vt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Vt(this,4);return Mn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Vt(this,4);return Mn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Vt(this,4);let t=Ya(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Vt(this,4);let t=ja(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Vt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ja(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Vt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Vt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Lt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Vt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Vt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Vt(this,8);let t=Mn(this.buf,this.pos+=4),r=Mn(this.buf,this.pos+=4);return new Lt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=As(this.buf,this.pos);return this.pos+=Ct(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ps(e){return new Ds(e instanceof Uint8Array?e:e.subarray())}function Ft(e,t,r){let n=Ps(e);return t.decode(n,void 0,r)}function Ts(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return At(i);o+i>t&&(n=At(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var ke=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Os(){}var Rs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ml=Ts();function Vl(e){return globalThis.Buffer!=null?At(e):Ml(e)}var Yr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ke(Os,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ke(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ns((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Vn,10,Lt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Lt.fromBigInt(t);return this._push(Vn,r.length(),r)}uint64Number(t){return this._push(ir,Ct(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Lt.fromBigInt(t).zzEncode();return this._push(Vn,r.length(),r)}sint64Number(t){let r=Lt.fromNumber(t).zzEncode();return this._push(Vn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ls,1,t?1:0)}fixed32(t){return this._push(Zr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Lt.fromBigInt(t);return this._push(Zr,4,r.lo)._push(Zr,4,r.hi)}fixed64Number(t){let r=Lt.fromNumber(t);return this._push(Zr,4,r.lo)._push(Zr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Za,4,t)}double(t){return this._push(Wa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ls,1,0):this.uint32(r)._push(ql,r,t)}string(t){let r=Qa(t);return r!==0?this.uint32(r)._push(Bs,r,t):this._push(Ls,1,0)}fork(){return this.states=new Rs(this),this.head=this.tail=new ke(Os,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 ke(Os,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Vl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ls(e,t,r){t[r]=e&255}function Fl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ns=class extends ke{next;constructor(t,r){super(Fl,t,r),this.next=void 0}};function Vn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Zr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function ql(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Yr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Hl,t,e),this},Yr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(zl,t,e),this});function Hl(e,t,r){t.set(e,r)}function zl(e,t,r){e.length<40?Bs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(k(e),r)}function Us(){return new Yr}function qt(e,t){let r=Us();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var cr;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(cr||(cr={}));function Fn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Ks(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return Fn("enum",cr.VARINT,r,n)}function Ht(e,t){return Fn("message",cr.LENGTH_DELIMITED,e,t)}var Me=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var st;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(st||(st={}));var ks;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(ks||(ks={}));(function(e){e.codec=()=>Ks(ks)})(st||(st={}));var Yt;(function(e){let t;e.codec=()=>(t==null&&(t=Ht((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=st.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>qt(r,e.codec()),e.decode=(r,n)=>Ft(r,e.codec(),n)})(Yt||(Yt={}));var Ms;(function(e){let t;e.codec=()=>(t==null&&(t=Ht((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=st.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>qt(r,e.codec()),e.decode=(r,n)=>Ft(r,e.codec(),n)})(Ms||(Ms={}));var jr={};vt(jr,{MAX_RSA_KEY_SIZE:()=>Vs,generateRSAKeyPair:()=>sc,jwkToJWKKeyPair:()=>ic,jwkToPkcs1:()=>Yl,jwkToPkix:()=>zs,jwkToRSAPrivateKey:()=>Ys,pkcs1MessageToJwk:()=>qs,pkcs1MessageToRSAPrivateKey:()=>$s,pkcs1ToJwk:()=>Zl,pkcs1ToRSAPrivateKey:()=>oc,pkixMessageToJwk:()=>Hs,pkixMessageToRSAPublicKey:()=>Zs,pkixToJwk:()=>Wl,pkixToRSAPublicKey:()=>Gs});var qn=Dn;var ur=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=jr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return it.createV1(114,this._multihash)}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,r,n){return nc(this.jwk,r,t,n)}},Wr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=jr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}sign(t,r){return rc(this.jwk,t,r)}};var Vs=8192,Fs=18,$l=1062,Gl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Zl(e){let t=te(e);return qs(t)}function qs(e){return{n:M(e[1],"base64url"),e:M(e[2],"base64url"),d:M(e[3],"base64url"),p:M(e[4],"base64url"),q:M(e[5],"base64url"),dp:M(e[6],"base64url"),dq:M(e[7],"base64url"),qi:M(e[8],"base64url"),kty:"RSA"}}function Yl(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new ct("JWK was missing components");return ge([It(Uint8Array.from([0])),It(k(e.n,"base64url")),It(k(e.e,"base64url")),It(k(e.d,"base64url")),It(k(e.p,"base64url")),It(k(e.q,"base64url")),It(k(e.dp,"base64url")),It(k(e.dq,"base64url")),It(k(e.qi,"base64url"))]).subarray()}function Wl(e){let t=te(e,{offset:0});return Hs(t)}function Hs(e){let t=te(e[1],{offset:0});return{kty:"RSA",n:M(t[0],"base64url"),e:M(t[1],"base64url")}}function zs(e){if(e.n==null||e.e==null)throw new ct("JWK was missing components");return ge([Gl,An(ge([It(k(e.n,"base64url")),It(k(e.e,"base64url"))]))]).subarray()}function oc(e){let t=te(e);return $s(t)}function $s(e){let t=qs(e);return Ys(t)}function Gs(e,t){if(e.byteLength>=$l)throw new $e("Key size is too large");let r=te(e,{offset:0});return Zs(r,e,t)}function Zs(e,t,r){let n=Hs(e);if(r==null){let o=qn(Yt.encode({Type:st.RSA,Data:t}));r=Kt(Fs,o)}return new ur(n,r)}function Ys(e){if(cc(e)>Vs)throw new ct("Key size is too large");let t=ic(e),r=qn(Yt.encode({Type:st.RSA,Data:zs(t.publicKey)})),n=Kt(Fs,r);return new Wr(t.privateKey,new ur(t.publicKey,n))}async function sc(e){if(e>Vs)throw new ct("Key size is too large");let t=await ac(e),r=qn(Yt.encode({Type:st.RSA,Data:zs(t.publicKey)})),n=Kt(Fs,r);return new Wr(t.privateKey,new ur(t.publicKey,n))}function ic(e){if(e==null)throw new ct("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function ac(e,t){let r=await Nt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await jl(r,t);return{privateKey:n[0],publicKey:n[1]}}async function rc(e,t,r){let n=await Nt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Nt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function nc(e,t,r,n){let o=await Nt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Nt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function jl(e,t){if(e.privateKey==null||e.publicKey==null)throw new ct("Private and public key are required");let r=await Promise.all([Nt.get().subtle.exportKey("jwk",e.privateKey),Nt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function cc(e){if(e.kty!=="RSA")throw new ct("invalid key type");if(e.n==null)throw new ct("invalid key modulus");return k(e.n,"base64url").length*8}var Hn=class extends Xe{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,In(t);let n=Ur(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),ne(s)}update(t){return Qe(this),this.iHash.update(t),this}digestInto(t){Qe(this),_t(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ws=(e,t,r)=>new Hn(e,t).update(r).digest();Ws.create=(e,t)=>new Hn(e,t);var uc=(e,t)=>(e+(e>=0?t:-t)/fc)/t;function Xl(e,t,r){let[[n,o],[s,i]]=t,c=uc(i*e,r),a=uc(-o*e,r),u=e-c*n-a*s,d=-c*o-a*i,l=u<he,f=d<he;l&&(u=-u),f&&(d=-d);let p=Se(Math.ceil(Tn(r)/2))+lr;if(u<he||u>=p||d<he||d>=p)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:f,k2:d}}function Xs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function js(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return se(r.lowS,"lowS"),se(r.prehash,"prehash"),r.format!==void 0&&Xs(r.format),r}var Qs=class extends Error{constructor(t=""){super(t)}},de={Err:Qs,_tlv:{encode:(e,t)=>{let{Err:r}=de;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Vr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Vr(o.length/2|128):"";return Vr(e)+s+o+t},decode(e,t){let{Err:r}=de,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of u)i=i<<8|d;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=de;if(e<he)throw new t("integer: negative integers are not allowed");let r=Vr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=de;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return tr(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=de,o=Z("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l:d}=n.decode(2,a);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=de,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},he=BigInt(0),lr=BigInt(1),fc=BigInt(2),zn=BigInt(3),Ql=BigInt(4);function fr(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=Z("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Jl(e,t={}){let r=Ln("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;ve(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=dc(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(D,b,m){let{x:y,y:S}=b.toAffine(),I=n.toBytes(y);if(se(m,"isCompressed"),m){d();let T=!n.isOdd(S);return wt(lc(T),I)}else return wt(Uint8Array.of(4),I,n.toBytes(S))}function f(D){Tt(D,void 0,"Point");let{publicKey:b,publicKeyUncompressed:m}=u,y=D.length,S=D[0],I=D.subarray(1);if(y===b&&(S===2||S===3)){let T=n.fromBytes(I);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let _=g(T),C;try{C=n.sqrt(_)}catch(J){let Y=J instanceof Error?": "+J.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}d();let L=n.isOdd(C);return(S&1)===1!==L&&(C=n.neg(C)),{x:T,y:C}}else if(y===m&&S===4){let T=n.BYTES,_=n.fromBytes(I.subarray(0,T)),C=n.fromBytes(I.subarray(T,T*2));if(!v(_,C))throw new Error("bad point: is not on curve");return{x:_,y:C}}else throw new Error(`bad point: got length ${y}, expected compressed=${b} or uncompressed=${m}`)}let p=t.toBytes||l,h=t.fromBytes||f;function g(D){let b=n.sqr(D),m=n.mul(b,D);return n.add(n.add(m,n.mul(D,s.a)),s.b)}function v(D,b){let m=n.sqr(b),y=g(D);return n.eql(m,y)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(s.a,zn),Ql),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(x,A)))throw new Error("bad curve params: a or b");function E(D,b,m=!1){if(!n.isValid(b)||m&&n.is0(b))throw new Error(`bad point coordinate ${D}`);return b}function P(D){if(!(D instanceof w))throw new Error("ProjectivePoint expected")}function R(D){if(!a||!a.basises)throw new Error("no endo");return Xl(D,a.basises,o.ORDER)}let F=er((D,b)=>{let{X:m,Y:y,Z:S}=D;if(n.eql(S,n.ONE))return{x:m,y};let I=D.is0();b==null&&(b=I?n.ONE:n.inv(S));let T=n.mul(m,b),_=n.mul(y,b),C=n.mul(S,b);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:T,y:_}}),V=er(D=>{if(D.is0()){if(t.allowInfinityPoint&&!n.is0(D.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:m}=D.toAffine();if(!n.isValid(b)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!v(b,m))throw new Error("bad point: equation left != right");if(!D.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function N(D,b,m,y,S){return m=new w(n.mul(m.X,D),m.Y,m.Z),b=Hr(y,b),m=Hr(S,m),b.add(m)}class w{constructor(b,m,y){this.X=E("x",b),this.Y=E("y",m,!0),this.Z=E("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:m,y}=b||{};if(!b||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(b instanceof w)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?w.ZERO:new w(m,y,n.ONE)}static fromBytes(b){let m=w.fromAffine(h(Tt(b,void 0,"point")));return m.assertValidity(),m}static fromHex(b){return w.fromBytes(Z("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return U.createCache(this,b),m||this.multiply(zn),this}assertValidity(){V(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){P(b);let{X:m,Y:y,Z:S}=this,{X:I,Y:T,Z:_}=b,C=n.eql(n.mul(m,_),n.mul(I,S)),L=n.eql(n.mul(y,_),n.mul(T,S));return C&&L}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:m}=s,y=n.mul(m,zn),{X:S,Y:I,Z:T}=this,_=n.ZERO,C=n.ZERO,L=n.ZERO,K=n.mul(S,S),J=n.mul(I,I),Y=n.mul(T,T),H=n.mul(S,I);return H=n.add(H,H),L=n.mul(S,T),L=n.add(L,L),_=n.mul(b,L),C=n.mul(y,Y),C=n.add(_,C),_=n.sub(J,C),C=n.add(J,C),C=n.mul(_,C),_=n.mul(H,_),L=n.mul(y,L),Y=n.mul(b,Y),H=n.sub(K,Y),H=n.mul(b,H),H=n.add(H,L),L=n.add(K,K),K=n.add(L,K),K=n.add(K,Y),K=n.mul(K,H),C=n.add(C,K),Y=n.mul(I,T),Y=n.add(Y,Y),K=n.mul(Y,H),_=n.sub(_,K),L=n.mul(Y,J),L=n.add(L,L),L=n.add(L,L),new w(_,C,L)}add(b){P(b);let{X:m,Y:y,Z:S}=this,{X:I,Y:T,Z:_}=b,C=n.ZERO,L=n.ZERO,K=n.ZERO,J=s.a,Y=n.mul(s.b,zn),H=n.mul(m,I),tt=n.mul(y,T),at=n.mul(S,_),St=n.add(m,y),et=n.add(I,T);St=n.mul(St,et),et=n.add(H,tt),St=n.sub(St,et),et=n.add(m,S);let yt=n.add(I,_);return et=n.mul(et,yt),yt=n.add(H,at),et=n.sub(et,yt),yt=n.add(y,S),C=n.add(T,_),yt=n.mul(yt,C),C=n.add(tt,at),yt=n.sub(yt,C),K=n.mul(J,et),C=n.mul(Y,at),K=n.add(C,K),C=n.sub(tt,K),K=n.add(tt,K),L=n.mul(C,K),tt=n.add(H,H),tt=n.add(tt,H),at=n.mul(J,at),et=n.mul(Y,et),tt=n.add(tt,at),at=n.sub(H,at),at=n.mul(J,at),et=n.add(et,at),H=n.mul(tt,et),L=n.add(L,H),H=n.mul(yt,et),C=n.mul(St,C),C=n.sub(C,H),H=n.mul(St,tt),K=n.mul(yt,K),K=n.add(K,H),new w(C,L,K)}subtract(b){return this.add(b.negate())}is0(){return this.equals(w.ZERO)}multiply(b){let{endo:m}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let y,S,I=T=>U.cached(this,T,_=>ce(w,_));if(m){let{k1neg:T,k1:_,k2neg:C,k2:L}=R(b),{p:K,f:J}=I(_),{p:Y,f:H}=I(L);S=J.add(H),y=N(m.beta,K,Y,T,C)}else{let{p:T,f:_}=I(b);y=T,S=_}return ce(w,[y,S])[0]}multiplyUnsafe(b){let{endo:m}=t,y=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===he||y.is0())return w.ZERO;if(b===lr)return y;if(U.hasCache(this))return this.multiply(b);if(m){let{k1neg:S,k1:I,k2neg:T,k2:_}=R(b),{p1:C,p2:L}=Ma(w,y,I,_);return N(m.beta,C,L,S,T)}else return U.unsafe(y,b)}multiplyAndAddUnsafe(b,m,y){let S=this.multiplyUnsafe(m).add(b.multiplyUnsafe(y));return S.is0()?void 0:S}toAffine(b){return F(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===lr?!0:b?b(w,this):U.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===lr?this:b?b(w,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return se(b,"isCompressed"),this.assertValidity(),p(w,this,b)}toHex(b=!0){return Rt(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return ce(w,b)}static msm(b,m){return or(w,o,b,m)}static fromPrivateKey(b){return w.BASE.multiply(fr(o,b))}}w.BASE=new w(s.Gx,s.Gy,n.ONE),w.ZERO=new w(n.ZERO,n.ONE,n.ZERO),w.Fp=n,w.Fn=o;let B=o.BITS,U=new nr(w,t.endo?Math.ceil(B/2):B);return w.BASE.precompute(8),w}function lc(e){return Uint8Array.of(e?2:3)}function dc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function td(e,t={}){let{Fn:r}=e,n=t.randomBytes||Je,o=Object.assign(dc(e.Fp,r),{seed:as(r.ORDER)});function s(p){try{return!!fr(r,p)}catch{return!1}}function i(p,h){let{publicKey:g,publicKeyUncompressed:v}=o;try{let x=p.length;return h===!0&&x!==g||h===!1&&x!==v?!1:!!e.fromBytes(p)}catch{return!1}}function c(p=n(o.seed)){return cs(Tt(p,o.seed,"seed"),r.ORDER)}function a(p,h=!0){return e.BASE.multiply(fr(r,p)).toBytes(h)}function u(p){let h=c(p);return{secretKey:h,publicKey:a(h)}}function d(p){if(typeof p=="bigint")return!1;if(p instanceof e)return!0;let{secretKey:h,publicKey:g,publicKeyUncompressed:v}=o;if(r.allowedLengths||h===g)return;let x=Z("key",p).length;return x===g||x===v}function l(p,h,g=!0){if(d(p)===!0)throw new Error("first arg must be private key");if(d(h)===!1)throw new Error("second arg must be public key");let v=fr(r,p);return e.fromHex(h).multiply(v).toBytes(g)}return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:p=>fr(r,p),precompute(p=8,h=e.BASE){return h.precompute(p,!1)}},lengths:o})}function ed(e,t,r={}){In(t),ve(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||Je,o=r.hmac||((m,...y)=>Ws(t,m,wt(...y))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:p}=td(e,r),h={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},g="compact";function v(m){let y=c>>lr;return m>y}function x(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function A(m,y){Xs(y);let S=p.signature,I=y==="compact"?S:y==="recovered"?S+1:void 0;return Tt(m,I,`${y} signature`)}class E{constructor(y,S,I){this.r=x("r",y),this.s=x("s",S),I!=null&&(this.recovery=I),Object.freeze(this)}static fromBytes(y,S=g){A(y,S);let I;if(S==="der"){let{r:L,s:K}=de.toSig(Tt(y));return new E(L,K)}S==="recovered"&&(I=y[0],S="compact",y=y.subarray(1));let T=i.BYTES,_=y.subarray(0,T),C=y.subarray(T,T*2);return new E(i.fromBytes(_),i.fromBytes(C),I)}static fromHex(y,S){return this.fromBytes(Oe(y),S)}addRecoveryBit(y){return new E(this.r,this.s,y)}recoverPublicKey(y){let S=s.ORDER,{r:I,s:T,recovery:_}=this;if(_==null||![0,1,2,3].includes(_))throw new Error("recovery id invalid");if(c*fc<S&&_>1)throw new Error("recovery id is ambiguous for h>1 curve");let L=_===2||_===3?I+c:I;if(!s.isValid(L))throw new Error("recovery id 2 or 3 invalid");let K=s.toBytes(L),J=e.fromBytes(wt(lc((_&1)===0),K)),Y=i.inv(L),H=R(Z("msgHash",y)),tt=i.create(-H*Y),at=i.create(T*Y),St=e.BASE.multiplyUnsafe(tt).add(J.multiplyUnsafe(at));if(St.is0())throw new Error("point at infinify");return St.assertValidity(),St}hasHighS(){return v(this.s)}toBytes(y=g){if(Xs(y),y==="der")return Oe(de.hexFromSig(this));let S=i.toBytes(this.r),I=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return wt(Uint8Array.of(this.recovery),S,I)}return wt(S,I)}toHex(y){return Rt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return E.fromBytes(Z("sig",y),"compact")}static fromDER(y){return E.fromBytes(Z("sig",y),"der")}normalizeS(){return this.hasHighS()?new E(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Rt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Rt(this.toBytes("compact"))}}let P=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let S=tr(y),I=y.length*8-a;return I>0?S>>BigInt(I):S},R=r.bits2int_modN||function(y){return i.create(P(y))},F=Se(a);function V(m){return Fr("num < 2^"+a,m,he,F),i.toBytes(m)}function N(m,y){return Tt(m,void 0,"message"),y?Tt(t(m),void 0,"prehashed message"):m}function w(m,y,S){if(["recovered","canonical"].some(tt=>tt in S))throw new Error("sign() legacy options not supported");let{lowS:I,prehash:T,extraEntropy:_}=js(S,h);m=N(m,T);let C=R(m),L=fr(i,y),K=[V(L),V(C)];if(_!=null&&_!==!1){let tt=_===!0?n(p.secretKey):_;K.push(Z("extraEntropy",tt))}let J=wt(...K),Y=C;function H(tt){let at=P(tt);if(!i.isValidNot0(at))return;let St=i.inv(at),et=e.BASE.multiply(at).toAffine(),yt=i.create(et.x);if(yt===he)return;let mn=i.create(St*i.create(Y+yt*L));if(mn===he)return;let Pi=(et.x===yt?0:2)|Number(et.y&lr),Ti=mn;return I&&v(mn)&&(Ti=i.neg(mn),Pi^=1),new E(yt,Ti,Pi)}return{seed:J,k2sig:H}}function B(m,y,S={}){m=Z("message",m);let{seed:I,k2sig:T}=w(m,y,S);return va(t.outputLen,i.BYTES,o)(I,T)}function U(m){let y,S=typeof m=="string"||re(m),I=!S&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!S&&!I)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(I)y=new E(m.r,m.s);else if(S){try{y=E.fromBytes(Z("sig",m),"der")}catch(T){if(!(T instanceof de.Err))throw T}if(!y)try{y=E.fromBytes(Z("sig",m),"compact")}catch{return!1}}return y||!1}function D(m,y,S,I={}){let{lowS:T,prehash:_,format:C}=js(I,h);if(S=Z("publicKey",S),y=N(Z("message",y),_),"strict"in I)throw new Error("options.strict was renamed to lowS");let L=C===void 0?U(m):E.fromBytes(Z("sig",m),C);if(L===!1)return!1;try{let K=e.fromBytes(S);if(T&&L.hasHighS())return!1;let{r:J,s:Y}=L,H=R(y),tt=i.inv(Y),at=i.create(H*tt),St=i.create(J*tt),et=e.BASE.multiplyUnsafe(at).add(K.multiplyUnsafe(St));return et.is0()?!1:i.create(et.x)===J}catch{return!1}}function b(m,y,S={}){let{prehash:I}=js(S,h);return y=N(y,I),E.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:p,Point:e,sign:B,verify:D,recoverPublicKey:b,Signature:E,hash:t})}function rd(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=Ot(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function nd(e){let{CURVE:t,curveOpts:r}=rd(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function od(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,On(r.Fn.ORDER,r.Fn.BITS))})}function hc(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=nd(e),s=Jl(t,r),i=ed(s,n,o);return od(e,i)}function pc(e,t){let r=n=>hc({...e,hash:n});return{...r(t),create:r}}var ti={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},sd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var mc=BigInt(2);function id(e){let t=ti.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,d=u*u*e%t,l=j(d,r,t)*d%t,f=j(l,r,t)*d%t,p=j(f,mc,t)*u%t,h=j(p,o,t)*p%t,g=j(h,s,t)*h%t,v=j(g,c,t)*g%t,x=j(v,a,t)*v%t,A=j(x,c,t)*g%t,E=j(A,r,t)*d%t,P=j(E,i,t)*h%t,R=j(P,n,t)*u%t,F=j(R,mc,t);if(!Js.eql(Js.sqr(F),e))throw new Error("Cannot find square root");return F}var Js=Ot(ti.p,{sqrt:id}),dr=pc({...ti,Fp:Js,lowS:!0,endo:sd},Dn);function yc(e,t,r,n){let o=Tr.digest(r instanceof Uint8Array?r:r.subarray());if(Kn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),dr.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new $r(String(s))});try{return n?.signal?.throwIfAborted(),dr.verify(t,o.digest,e)}catch(s){throw new $r(String(s))}}var $n=class{type="secp256k1";raw;_key;constructor(t){this._key=gc(t),this.raw=bc(this._key)}toMultihash(){return kt.digest(Gt(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,r,n){return yc(this._key,r,t,n)}};function ei(e){return new $n(e)}function bc(e){return dr.ProjectivePoint.fromHex(e).toRawBytes(!0)}function gc(e){try{return dr.ProjectivePoint.fromHex(e),e}catch(t){throw new $e(String(t))}}function hr(e,t){let{Type:r,Data:n}=Yt.decode(e),o=n??new Uint8Array;switch(r){case st.RSA:return Gs(o,t);case st.Ed25519:return xs(o);case st.secp256k1:return ei(o);case st.ECDSA:return Zo(o);default:throw new De}}function xc(e){let{Type:t,Data:r}=Yt.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return xs(n);case st.secp256k1:return ei(n);case st.ECDSA:return Zo(n);default:throw new De}}function Gt(e){return Yt.encode({Type:st[e.type],Data:e.raw})}var Xr;(function(e){let t;e.codec=()=>(t==null&&(t=Ht((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.publicKey!=null&&r.publicKey.byteLength>0&&(n.uint32(10),n.bytes(r.publicKey)),r.payloadType!=null&&r.payloadType.byteLength>0&&(n.uint32(18),n.bytes(r.payloadType)),r.payload!=null&&r.payload.byteLength>0&&(n.uint32(26),n.bytes(r.payload)),r.signature!=null&&r.signature.byteLength>0&&(n.uint32(42),n.bytes(r.signature)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={publicKey:ht(0),payloadType:ht(0),payload:ht(0),signature:ht(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.publicKey=r.bytes();break}case 2:{s.payloadType=r.bytes();break}case 3:{s.payload=r.bytes();break}case 5:{s.signature=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>qt(r,e.codec()),e.decode=(r,n)=>Ft(r,e.codec(),n)})(Xr||(Xr={}));var Gn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Wt=class e{static createFromProtobuf=t=>{let r=Xr.decode(t),n=hr(r.publicKey);return new e({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(t,r,n)=>{if(r==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),c=wc(o,s,i),a=await r.sign(c.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:a})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new Gn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:r,payloadType:n,payload:o,signature:s}=t;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Xr.encode({publicKey:Gt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:ut(this.marshal(),t.marshal())}async validate(t,r){let n=wc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},wc=(e,t,r)=>{let n=k(e),o=ar(n.byteLength),s=ar(t.length),i=ar(r.length);return new ot(o,n,s,t,i,r)};var Ec=Symbol.for("nodejs.util.inspect.custom"),ad=114,Qr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[xo]=!0;toString(){return this.string==null&&(this.string=Q.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return it.createV1(ad,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ut(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ut(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ec](){return`PeerId(${this.toString()})`}},Jr=class extends Qr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},tn=class extends Qr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},en=class extends Qr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},cd=2336,rn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=kt.digest(k(this.url))}[Ec](){return`PeerId(${this.url})`}[xo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return it.createV1(cd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=M(t)),t.toString()===this.toString())}};var ud=114,Sc=2336;function vc(e){if(e.type==="Ed25519")return new tn({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new en({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Jr({multihash:e.toCID().multihash,publicKey:e});throw new De}function ri(e){if(ld(e))return new Jr({multihash:e});if(fd(e))try{let t=xc(e);if(t.type==="Ed25519")return new tn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new en({multihash:e,publicKey:t})}catch{let r=M(e.digest);return new rn(new URL(r))}throw new gn("Supplied PeerID Multihash is invalid")}function Zn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==ud&&e.code!==Sc)throw new bn("Supplied PeerID CID is invalid");if(e.code===Sc){let t=M(e.multihash.digest);return new rn(new URL(t))}return ri(e.multihash)}function fd(e){return e.code===kt.code}function ld(e){return e.code===Tr.code}function Ac(e,t){let r=(n,o)=>n.toString().localeCompare(o.toString());return e.length!==t.length?!1:(t.sort(r),e.sort(r).every((n,o)=>t[o].equals(n)))}var mt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},pe=class extends Error{static name="ValidationError";name="ValidationError"},nn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Yn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Wn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",u=2**(8*o)-1;for(;;){let d=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let f=Number.parseInt(l,t);if(!Number.isNaN(f))return f});if(d===void 0)break;if(s*=t,s+=d,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[c]=t(s.subarray(0,i));return r.set(s.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ic=45,dd=15,pr=new Wn;function jn(e){if(!(e.length>dd))return pr.new(e).parseWith(()=>pr.readIPv4Addr())}function Xn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Ic))return pr.new(e).parseWith(()=>pr.readIPv6Addr())}function mr(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Ic)return;let r=pr.new(e).parseWith(()=>pr.readIPAddr());if(r)return t&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function yr(e){return!!jn(e)}function Qn(e){return!!Xn(e)}function oi(e){return t=>M(t,e)}function si(e){return t=>k(t,e)}function br(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Ve(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function _c(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=k(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ve(n);return Jt([r,o],r.length+o.length)}function Cc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=be.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ve(n);return Jt([r,o],r.length+o.length)}function ii(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=M(t,"base32"),o=br(r);return`${n}:${o}`}var ai=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new mt("Invalid byte value in IP address");t[n]=o}),t},Bc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=yr(r[n]),i;s&&(i=ai(r[n]),r[n]=M(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,M(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new mt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Dc=function(e){if(e.byteLength!==4)throw new mt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Pc=function(e){if(e.byteLength!==16)throw new mt("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new mt(`Invalid IPv6 address "${r}"`)}};function Tc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new mt(`Invalid IPv6 address "${e}"`)}}var ni=Object.values(Or).map(e=>e.decoder),hd=function(){let e=ni[0].or(ni[1]);return ni.slice(2).forEach(t=>e=e.or(t)),e}();function Oc(e){return hd.decode(e)}function Lc(e){return t=>e.encoder.encode(t)}function pd(e){if(parseInt(e).toString()!==e)throw new pe("Value must be an integer")}function md(e){if(e<0)throw new pe("Value must be a positive integer, or zero")}function yd(e){return t=>{if(t>e)throw new pe(`Value must be smaller than or equal to ${e}`)}}function bd(...e){return t=>{for(let r of e)r(t)}}var on=bd(pd,md,yd(65535));var dt=-1,ci=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Yn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Dt=new ci,Od=[{code:4,name:"ip4",size:32,valueToBytes:ai,bytesToValue:Dc,validate:e=>{if(!yr(e))throw new pe(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ve,bytesToValue:br,validate:on},{code:273,name:"udp",size:16,valueToBytes:Ve,bytesToValue:br,validate:on},{code:33,name:"dccp",size:16,valueToBytes:Ve,bytesToValue:br,validate:on},{code:41,name:"ip6",size:128,valueToBytes:Bc,bytesToValue:Pc,stringToValue:Tc,validate:e=>{if(!Qn(e))throw new pe(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:dt},{code:43,name:"ipcidr",size:8,bytesToValue:oi("base10"),valueToBytes:si("base10")},{code:53,name:"dns",size:dt,resolvable:!0},{code:54,name:"dns4",size:dt,resolvable:!0},{code:55,name:"dns6",size:dt,resolvable:!0},{code:56,name:"dnsaddr",size:dt,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:Ve,bytesToValue:br,validate:on},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:dt,path:!0,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:dt,bytesToValue:oi("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?si("base58btc")(e):it.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ii,valueToBytes:_c},{code:445,name:"onion3",size:296,bytesToValue:ii,valueToBytes:Cc},{code:446,name:"garlic64",size:dt},{code:447,name:"garlic32",size:dt},{code:448,name:"tls"},{code:449,name:"sni",size:dt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:dt,bytesToValue:Lc(Ro),valueToBytes:Oc},{code:480,name:"http"},{code:481,name:"http-path",size:dt,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:dt}];Od.forEach(e=>{Dt.addProtocol(e)});function Rc(e){let t=[],r=0;for(;r<e.length;){let n=Gr(e,r),o=Dt.getProtocol(n),s=Ct(n),i=Ld(o,e,r+s),c=0;i>0&&o.size===dt&&(c=Ct(i));let a=s+c+i,u={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(i>0){let d=r+s+c,l=e.subarray(d,d+i);u.value=o.bytesToValue?.(l)??M(l)}t.push(u),r+=a}return t}function Nc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Dt.getProtocol(n.code),s=Ct(n.code),i,c=0,a=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??k(n.value),c=i.byteLength,o.size===dt&&(a=Ct(c)));let u=new Uint8Array(s+a+c),d=0;ir(n.code,u,d),d+=s,i!=null&&(o.size===dt&&(ir(c,u,d),d+=a),u.set(i,d)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Jt(r,t)}function Uc(e){if(e.charAt(0)!=="/")throw new mt('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let c=s===e.length-1;if(i==="/"||c){let a=Dt.getProtocol(o);if(r==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",r="protocol";continue}else if(c)throw new mt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new mt(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new mt("Incomplete multiaddr");return t}function Kc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Dt.getProtocol(t.code);if(r==null)throw new mt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Ld(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Gr(t,r)}var Rd=Symbol.for("nodejs.util.inspect.custom"),gi=Symbol.for("@multiformats/multiaddr"),Nd=[53,54,55,56],bi=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function Ud(e){if(e==null&&(e="/"),Mc(e))return e.getComponents();if(e instanceof Uint8Array)return Rc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Uc(e);if(Array.isArray(e))return e;throw new mt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ro=class e{[gi]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Ud(t),r.validate!==!1&&Kd(this)}get bytes(){return this.#r==null&&(this.#r=Nc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Kc(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,r,n,o,s="";for(let{code:c,name:a,value:u}of this.#t)c===42&&(s=`%${u??""}`),Nd.includes(c)&&(r="tcp",o=443,n=`${u??""}${s}`,t=c===55?6:4),(c===6||c===273)&&(r=a==="tcp"?"tcp":"udp",o=parseInt(u??"")),(c===4||c===41)&&(r="tcp",n=`${u??""}${s}`,t=c===41?6:4);if(t==null||r==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:r,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:r})=>{let n=Dt.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:r})=>{if(r==null)return[t];let n=Dt.getProtocol(t),o=[t];return r!=null&&o.push(n.valueToBytes?.(r)??k(r)),o})}stringTuples(){return this.#t.map(({code:t,value:r})=>r==null?[t]:[t,r])}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new nn(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let r=t.pop();if(r?.[1]!=null){let n=r[1];return n[0]==="Q"||n[0]==="1"?M(Q.decode(`z${n}`),"base58btc"):M(it.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(Dt.getProtocol(t.code).path)return t.value??null;return null}equals(t){return ut(this.bytes,t.bytes)}async resolve(t){let r=this.protos().find(s=>s.resolvable);if(r==null)return[this];let n=kc.get(r.name);if(n==null)throw new bi(`no available resolver for ${r.name}`);return(await n(this,t)).map(s=>Xt(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[Rd](){return`Multiaddr(${this.toString()})`}};function Kd(e){e.getComponents().forEach(t=>{let r=Dt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Vc(e,t,r){let n=0;for(let o of e)if(!(n<t)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Fc(e,t,r,n){let o=0;for(let s of e)if(!(o<r)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function xi(e){switch(e.length){case qe:return e.join(".");case He:{let t=[];for(let r=0;r<e.length;r++)r%2===0&&t.push(e[r].toString(16).padStart(2,"0")+e[r+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function qc(e){let t=0;for(let[r,n]of e.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<e.length;o++)if(e[o]!=0)return-1;break}return t}function Hc(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var qe=4,He=16,Tg=parseInt("0xFFFF",16),kd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function fn(e,t){t.length===He&&e.length===qe&&Vc(t,0,11)&&(t=t.slice(12)),t.length===qe&&e.length===He&&Fc(e,kd,0,11)&&(e=e.slice(12));let r=e.length;if(r!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=e[o]&t[o];return n}function zc(e,t){if(typeof t=="string"&&(t=mr(t)),t==null)throw new Error("Invalid ip");if(t.length!==e.network.length)return!1;for(let r=0;r<t.length;r++)if((e.network[r]&e.mask[r])!==(t[r]&e.mask[r]))return!1;return!0}function wi(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=qe,o=jn(t);if(o==null&&(n=He,o=Xn(t),o==null))throw new Error("Failed to parse given CIDR: "+e);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+e);let i=Ei(s,8*n);return{network:fn(o,i),mask:i}}function Ei(e,t){if(t!==8*qe&&t!==8*He)throw new Error("Invalid CIDR mask");if(e<0||e>t)throw new Error("Invalid CIDR mask");let r=t/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(e>=8){n[o]=255,e-=8;continue}n[o]=255-(255>>e),e=0}return n}var vr=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=wi(t));else{let n=mr(t);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=mr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Ei(o,8*n.length);this.network=fn(n,this.mask)}}contains(t){return zc({network:this.network,mask:this.mask},t)}toString(){let t=qc(this.mask),r=t!==-1?String(t):Hc(this.mask);return xi(this.network)+"/"+r}};function $c(e,t){return new vr(e).contains(t)}var kc=new Map;function Mc(e){return!!e?.[gi]}function Xt(e){return new ro(e)}function no(e){let t=Dt.getProtocol(e);return{code:t.code,size:t.size??0,name:t.name,resolvable:!!t.resolvable,path:!!t.path}}var Gc="libp2p-peer-record",Zc=Uint8Array.from([3,1]);var ln;(function(e){let t;(function(n){let o;n.codec=()=>(o==null&&(o=Ht((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={multiaddr:ht(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let d=s.uint32();switch(d>>>3){case 1:{a.multiaddr=s.bytes();break}default:{s.skipType(d&7);break}}}return a})),o),n.encode=s=>qt(s,n.codec()),n.decode=(s,i)=>Ft(s,n.codec(),i)})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=Ht((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),e.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:ht(0),seq:0n,addresses:[]},c=o==null?n.len:n.pos+o;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new Me('Decode error - map field "addresses" had too many elements');i.addresses.push(e.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(a&7);break}}}return i})),r),e.encode=n=>qt(n,e.codec()),e.decode=(n,o)=>Ft(n,e.codec(),o)})(ln||(ln={}));var zt=class e{static createFromProtobuf=t=>{let r=ln.decode(t),n=ri(Dr(r.peerId)),o=(r.addresses??[]).map(i=>Xt(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Gc;static CODEC=Zc;peerId;multiaddrs;seqNumber;domain=e.DOMAIN;codec=e.CODEC;marshaled;constructor(t){let{peerId:r,multiaddrs:n,seqNumber:o}=t;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=ln.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof e)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!Ac(this.multiaddrs,t.multiaddrs))}};function Yc(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}function Md(e){return e[Symbol.asyncIterator]!=null}function Vd(e){if(Md(e))return(async()=>{for await(let t of e);})();for(let t of e);}var Wc=Vd;function $t(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var oo=globalThis.CustomEvent??Event;async function*Si(e,t={}){let r=t.concurrency??1/0;r<1&&(r=1/0);let n=t.ordered??!1,o=new EventTarget,s=[],i=$t(),c=$t(),a=!1,u,d=!1;o.addEventListener("task-complete",()=>{c.resolve()}),Promise.resolve().then(async()=>{try{for await(let h of e){if(s.length===r&&(i=$t(),await i.promise),d)break;let g={done:!1};s.push(g),h().then(v=>{g.done=!0,g.ok=!0,g.value=v,o.dispatchEvent(new oo("task-complete"))},v=>{g.done=!0,g.err=v,o.dispatchEvent(new oo("task-complete"))})}a=!0,o.dispatchEvent(new oo("task-complete"))}catch(h){u=h,o.dispatchEvent(new oo("task-complete"))}});function l(){return n?s[0]?.done:!!s.find(h=>h.done)}function*f(){for(;s.length>0&&s[0].done;){let h=s[0];if(s.shift(),h.ok)yield h.value;else throw d=!0,i.resolve(),h.err;i.resolve()}}function*p(){for(;l();)for(let h=0;h<s.length;h++)if(s[h].done){let g=s[h];if(s.splice(h,1),h--,g.ok)yield g.value;else throw d=!0,i.resolve(),g.err;i.resolve()}}for(;;){if(l()||(c=$t(),await c.promise),u!=null||(n?yield*f():yield*p(),u!=null))throw u;if(a&&s.length===0)break}}var so=class extends Error{type;code;constructor(t,r,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function dn(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new so(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new so(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([e,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var vi=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=$t(),this.haveNext=$t()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=$t(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,r){await this._push(t,r)}async end(t,r){t!=null?await this.throw(t):await this._push(void 0,r)}async _push(t,r){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=$t(),await dn(this.readNext.promise,r?.signal,r)}};function jc(){return new vi}var io=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Xc(e,t){let r=jc();e.sink(r).catch(async i=>{await r.end(i)}),e.sink=async i=>{for await(let c of i)await r.push(c);await r.end()};let n=e.source;e.source[Symbol.iterator]!=null?n=e.source[Symbol.iterator]():e.source[Symbol.asyncIterator]!=null&&(n=e.source[Symbol.asyncIterator]());let o=new ot;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:a,value:u}=await dn(n.next(),i?.signal);return a===!0?null:u}for(;o.byteLength<i.bytes;){let{value:a,done:u}=await dn(n.next(),i?.signal);if(u===!0)throw new io("unexpected end of input");o.append(a)}let c=o.sublist(0,i.bytes);return o.consume(i.bytes),c},write:async(i,c)=>{c?.signal?.throwIfAborted(),i instanceof Uint8Array?await r.push(i,c):await r.push(i.subarray(),c)},unwrap:()=>{if(o.byteLength>0){let i=e.source;e.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return e}}}var ao=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},co=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},uo=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Qc(e,t={}){let r=Xc(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ct(t.maxDataLength));let n=t?.lengthDecoder??Gr,o=t?.lengthEncoder??ar;return{read:async i=>{let c=-1,a=new ot;for(;;){a.append(await r.read({...i,bytes:1}));try{c=n(a)}catch(u){if(u instanceof RangeError)continue;throw u}if(c<0)throw new ao("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new uo("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new co("message length too long");return r.read({...i,bytes:c})},write:async(i,c)=>{await r.write(new ot(o(i.byteLength),i),c)},writeV:async(i,c)=>{let a=new ot(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(a,c)},unwrap:()=>r.unwrap()}}function Ar(e,t){let r=Qc(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var Jc="0.1.0";var tu="id/push",eu="1.0.0",ru="1.0.0";var Be;(function(e){let t;e.codec=()=>(t==null&&(t=Ht((r,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),r.protocolVersion!=null&&(n.uint32(42),n.string(r.protocolVersion)),r.agentVersion!=null&&(n.uint32(50),n.string(r.agentVersion)),r.publicKey!=null&&(n.uint32(10),n.bytes(r.publicKey)),r.listenAddrs!=null)for(let s of r.listenAddrs)n.uint32(18),n.bytes(s);if(r.observedAddr!=null&&(n.uint32(34),n.bytes(r.observedAddr)),r.protocols!=null)for(let s of r.protocols)n.uint32(26),n.string(s);r.signedPeerRecord!=null&&(n.uint32(66),n.bytes(r.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={listenAddrs:[],protocols:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 5:{s.protocolVersion=r.string();break}case 6:{s.agentVersion=r.string();break}case 1:{s.publicKey=r.bytes();break}case 2:{if(o.limits?.listenAddrs!=null&&s.listenAddrs.length===o.limits.listenAddrs)throw new Me('Decode error - map field "listenAddrs" had too many elements');s.listenAddrs.push(r.bytes());break}case 4:{s.observedAddr=r.bytes();break}case 3:{if(o.limits?.protocols!=null&&s.protocols.length===o.limits.protocols)throw new Me('Decode error - map field "protocols" had too many elements');s.protocols.push(r.string());break}case 8:{s.signedPeerRecord=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>qt(r,e.codec()),e.decode=(r,n)=>Ft(r,e.codec(),n)})(Be||(Be={}));var Pt={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function nu(e){if(e!=null&&e.length>0)try{return Xt(e)}catch{}}function Hd(e,t){return t??e.userAgent}async function fo(e,t,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Ut("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(a=>({isCertified:!1,multiaddr:Xt(a)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let a=hr(o.publicKey);if(!vc(a).equals(n.remotePeer))throw new Ut("public key did not match remote PeerId");s.publicKey=a}let i;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let a=o.signedPeerRecord,u=await Wt.openAndCertify(a,zt.DOMAIN),d=zt.createFromProtobuf(u.payload),l=Zn(u.publicKey.toCID());if(!d.peerId.equals(l))throw new Ut("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(d.peerId))throw new Ut("signing key does not match remote PeerId");let f;try{f=await e.get(d.peerId)}catch(p){if(p.name!=="NotFoundError")throw p}if(f!=null&&(s.metadata=f.metadata,f.peerRecordEnvelope!=null)){let p=Wt.createFromProtobuf(f.peerRecordEnvelope),h=zt.createFromProtobuf(p.payload);h.seqNumber>=d.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",h.seqNumber,d.seqNumber),d=h,a=f.peerRecordEnvelope)}s.peerRecordEnvelope=a,s.addresses=d.multiaddrs.map(p=>({isCertified:!0,multiaddr:p})),i={seq:d.seqNumber,addresses:d.multiaddrs}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,s),await e.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let a={};o.agentVersion!=null&&(a.AgentVersion=k(o.agentVersion)),o.protocolVersion!=null&&(a.ProtocolVersion=k(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,a),await e.merge(n.remotePeer,{metadata:a})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(a=>Xt(a)),observedAddr:o.observedAddr==null?void 0:Xt(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:c}),c}var Ir=class{host;protocol;started;timeout;peerId;privateKey;peerStore;registrar;addressManager;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;events;runOnLimitedConnection;log;constructor(t,r){this.protocol=r.protocol,this.started=!1,this.peerId=t.peerId,this.privateKey=t.privateKey,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.events=t.events,this.log=r.log,this.timeout=r.timeout??Pt.timeout,this.maxInboundStreams=r.maxInboundStreams??Pt.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Pt.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Pt.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Pt.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Pt.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Pt.protocolPrefix}/${Jc}`,agentVersion:Hd(t.nodeInfo,r.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:k(this.host.agentVersion),ProtocolVersion:k(this.host.protocolVersion)}}),await this.registrar.handle(this.protocol,t=>{this.handleProtocol(t).catch(r=>{this.log.error(r)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.registrar.unhandle(this.protocol),this.started=!1}};var lo=class extends Ir{connectionManager;concurrency;_push;constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??Pt.protocolPrefix}/${tu}/${ru}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=r.concurrency??Pt.concurrency,this._push=Yc(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Pt.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[wn]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let t=this.addressManager.getAddresses().map(d=>d.decapsulateCode(no("p2p").code)),r=new zt({peerId:this.peerId,multiaddrs:t}),n=await Wt.seal(r,this.privateKey),o=this.registrar.getProtocols(),s=await this.peerStore.get(this.peerId),i=M(s.metadata.get("AgentVersion")??k(this.host.agentVersion)),c=M(s.metadata.get("ProtocolVersion")??k(this.host.protocolVersion)),a=this;async function*u(){for(let d of a.connectionManager.getConnections()){let l=await a.peerStore.get(d.remotePeer),f=d.log.newScope("identify-push");l.protocols.includes(a.protocol)&&(yield async()=>{let p,h=AbortSignal.timeout(a.timeout);try{p=await d.newStream(a.protocol,{signal:h,runOnLimitedConnection:a.runOnLimitedConnection}),await Ar(p,{maxDataLength:a.maxMessageSize}).pb(Be).write({listenAddrs:t.map(v=>v.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:c},{signal:h}),await p.close({signal:h})}catch(g){f.error("could not push identify update to peer",g),p?.abort(g)}})}}await Wc(Si(u(),{concurrency:this.concurrency}))}catch(t){this.log.error("error pushing updates to peers - %e",t)}}async handleProtocol(t){let{connection:r,stream:n}=t,o=r.log.newScope("identify-push");try{if(this.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let s={signal:AbortSignal.timeout(this.timeout)},c=await Ar(n,{maxDataLength:this.maxMessageSize}).pb(Be).read(s);await n.close(s),await fo(this.peerStore,this.events,o,r,c)}catch(s){o.error("received invalid message",s),n.abort(s);return}o.trace("handled push from %p",r.remotePeer)}};function ou(e){try{for(let{code:t,value:r}of e.getComponents())if(r!=null&&t===41)return $c("2000::/3",r)}catch{}return!1}var iu=Au(su(),1),$d=["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"],Gd=$d.map(e=>new iu.Netmask(e));function Ai(e){for(let t of Gd)if(t.contains(e))return!0;return!1}function Zd(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function Yd(e){let t=e.split(":");if(t.length<2)return!1;let r=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return Ai(o)}function Wd(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function jd(e){let t=e.split(":"),r=t[t.length-1];return Ai(r)}function Xd(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}function au(e){if(yr(e))return Ai(e);if(Zd(e))return Yd(e);if(Wd(e))return jd(e);if(Qn(e))return Xd(e)}function cu(e){try{for(let{code:t}of e.getComponents())if(t!==42)return t===4||t===41}catch{}return!1}function uu(e){try{if(!cu(e))return!1;let[[,t]]=e.stringTuples();return t==null?!1:au(t)??!1}catch{}return!0}var X=e=>({match:t=>{let r=t[0];return r==null||r.code!==e||r.value!=null?!1:t.slice(1)}}),O=(e,t)=>({match:r=>{let n=r[0];return n?.code!==e||n.value==null||t!=null&&n.value!==t?!1:r.slice(1)}}),q=e=>({match:t=>{let r=e.match(t);return r===!1?t:r}}),xt=(...e)=>({match:t=>{let r;for(let n of e){let o=n.match(t);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),G=(...e)=>({match:t=>{for(let r of e){let n=r.match(t);if(n===!1)return!1;t=n}return t}});function W(...e){function t(o){if(o==null)return!1;let s=o.getComponents();for(let i of e){let c=i.match(s);if(c===!1)return!1;s=c}return s}function r(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:e,matches:r,exactMatch:n}}var Qd=O(421),Tw=W(Qd),po=O(54),mo=O(55),yo=O(56),_i=O(53),Ow=W(po,q(O(421))),Lw=W(mo,q(O(421))),Rw=W(yo,q(O(421))),Nw=W(xt(_i,yo,po,mo),q(O(421))),fu=G(O(4),q(O(43))),lu=G(q(O(42)),O(41),q(O(43))),Ci=xt(fu,lu),ze=xt(Ci,_i,po,mo,yo),du=W(xt(Ci,G(xt(_i,yo,po,mo),q(O(421))))),Uw=W(fu),Kw=W(lu),kw=W(Ci),Bi=G(ze,O(6)),pn=G(ze,O(273)),hu=W(G(Bi,q(O(421)))),Mw=W(pn),Di=G(pn,X(460),q(O(421))),bo=G(pn,X(461),q(O(421))),Jd=xt(Di,bo),Vw=W(Di),Fw=W(bo),Ii=xt(ze,Bi,pn,Di,bo),pu=xt(G(Ii,X(477),q(O(421)))),qw=W(pu),mu=xt(G(Ii,X(478),q(O(421))),G(Ii,X(448),q(O(449)),X(477),q(O(421)))),Hw=W(mu),yu=G(pn,X(280),q(O(466)),q(O(466)),q(O(421))),zw=W(yu),bu=G(bo,X(465),q(O(466)),q(O(466)),q(O(421))),$w=W(bu),ho=xt(pu,mu,G(Bi,q(O(421))),G(Jd,q(O(421))),G(ze,q(O(421))),yu,bu,O(421)),Gw=W(ho),th=G(ho,X(290),O(421)),Zw=W(th),eh=xt(G(ho,X(290),X(281),q(O(421))),G(ho,X(281),q(O(421))),G(X(281),q(O(421)))),Yw=W(eh),rh=xt(G(ze,O(6),X(480),q(O(421))),G(ze,X(480),q(O(421)))),Ww=W(rh),nh=G(ze,xt(G(O(6,"443"),X(480)),G(O(6),X(443)),G(O(6),X(448),X(480)),G(X(448),X(480)),X(448),X(443)),q(O(421))),jw=W(nh),oh=xt(G(O(777),q(O(421)))),Xw=W(oh),sh=xt(G(O(400),q(O(421)))),Qw=W(sh);var go=class extends Ir{constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??Pt.protocolPrefix}/${"id"}/${eu}`,log:t.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Pt.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(s=>{s.name!==xn.name&&this.log.error("error during identify trigged by connection:open",s)})})}[wn]=["@libp2p/identify"];async _identify(t,r={}){let n;if(r.signal==null){let o=AbortSignal.timeout(this.timeout);r={...r,signal:o}}try{n=await t.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection});let s=await Ar(n,{maxDataLength:this.maxMessageSize}).pb(Be).read(r);return await n.close(r),s}catch(o){throw n?.abort(o),o}}async identify(t,r={}){let n=await this._identify(t,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Ut("Public key was missing from identify message");let c=hr(o),a=Zn(c.toCID()),u=t.log.newScope("identify");if(!t.remotePeer.equals(a))throw new Ut("Identified peer does not match the expected peer");if(this.peerId.equals(a))throw new Ut("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i,u),u("completed for peer %p and protocols %o",a,s),fo(this.peerStore,this.events,u,t,n)}maybeAddObservedAddress(t,r){let n=nu(t);if(n==null)return;if(r.trace("our observed address was %a",n),uu(n)){this.log.trace("our observed address was private");return}let o=n.getComponents();if((o[0].code===41||o[0].code===42&&o[1].code===41)&&!ou(n)){r.trace("our observed address was IPv6 but not a global unicast address");return}hu.exactMatch(n)||(r.trace("storing the observed address"),this.addressManager.addObservedAddr(n))}async handleProtocol(t){let{connection:r,stream:n}=t,o=r.log.newScope("identify"),s=AbortSignal.timeout(this.timeout);try{let i=await this.peerStore.get(this.peerId),c=this.addressManager.getAddresses().map(l=>l.decapsulateCode(no("p2p").code)),a=i.peerRecordEnvelope;if(c.length>0&&a==null){let l=new zt({peerId:this.peerId,multiaddrs:c});a=(await Wt.seal(l,this.privateKey)).marshal().subarray()}let u=r.remoteAddr.bytes;du.matches(r.remoteAddr)||(u=void 0),await Ar(n).pb(Be).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Gt(this.privateKey.publicKey),listenAddrs:c.map(l=>l.bytes),signedPeerRecord:a,observedAddr:u,protocols:i.protocols},{signal:s}),await n.close({signal:s})}catch(i){o.error("could not respond to identify request",i),n.abort(i)}}};function ah(e={}){return t=>new go(t,e)}function ch(e={}){return t=>new lo(t,e)}return Iu(uh);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: