@libp2p/floodsub 11.0.11 → 11.0.12

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.Libp2PFloodsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PFloodsub=(()=>{var ha=Object.create;var mr=Object.defineProperty;var da=Object.getOwnPropertyDescriptor;var pa=Object.getOwnPropertyNames;var ma=Object.getPrototypeOf,ba=Object.prototype.hasOwnProperty;var ya=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),dt=(r,t)=>{for(var e in t)mr(r,e,{get:t[e],enumerable:!0})},ri=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of pa(t))!ba.call(r,s)&&s!==e&&mr(r,s,{get:()=>t[s],enumerable:!(n=da(t,s))||n.enumerable});return r};var ga=(r,t,e)=>(e=r!=null?ha(ma(r)):{},ri(t||!r||!r.__esModule?mr(e,"default",{value:r,enumerable:!0}):e,r)),wa=r=>ri(mr({},"__esModule",{value:!0}),r);var na=ya((wm,Gs)=>{"use strict";var sf=Object.prototype.hasOwnProperty,ht="~";function fr(){}Object.create&&(fr.prototype=Object.create(null),new fr().__proto__||(ht=!1));function of(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function ra(r,t,e,n,s){if(typeof e!="function")throw new TypeError("The listener must be a function");var i=new of(e,n||r,s),o=ht?ht+t:t;return r._events[o]?r._events[o].fn?r._events[o]=[r._events[o],i]:r._events[o].push(i):(r._events[o]=i,r._eventsCount++),r}function zr(r,t){--r._eventsCount===0?r._events=new fr:delete r._events[t]}function ft(){this._events=new fr,this._eventsCount=0}ft.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)sf.call(e,n)&&t.push(ht?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};ft.prototype.listeners=function(t){var e=ht?ht+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,i=n.length,o=new Array(i);s<i;s++)o[s]=n[s].fn;return o};ft.prototype.listenerCount=function(t){var e=ht?ht+t:t,n=this._events[e];return n?n.fn?1:n.length:0};ft.prototype.emit=function(t,e,n,s,i,o){var a=ht?ht+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,l,u;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,s),!0;case 5:return c.fn.call(c.context,e,n,s,i),!0;case 6:return c.fn.call(c.context,e,n,s,i,o),!0}for(u=1,l=new Array(f-1);u<f;u++)l[u-1]=arguments[u];c.fn.apply(c.context,l)}else{var y=c.length,d;for(u=0;u<y;u++)switch(c[u].once&&this.removeListener(t,c[u].fn,void 0,!0),f){case 1:c[u].fn.call(c[u].context);break;case 2:c[u].fn.call(c[u].context,e);break;case 3:c[u].fn.call(c[u].context,e,n);break;case 4:c[u].fn.call(c[u].context,e,n,s);break;default:if(!l)for(d=1,l=new Array(f-1);d<f;d++)l[d-1]=arguments[d];c[u].fn.apply(c[u].context,l)}}return!0};ft.prototype.on=function(t,e,n){return ra(this,t,e,n,!1)};ft.prototype.once=function(t,e,n){return ra(this,t,e,n,!0)};ft.prototype.removeListener=function(t,e,n,s){var i=ht?ht+t:t;if(!this._events[i])return this;if(!e)return zr(this,i),this;var o=this._events[i];if(o.fn)o.fn===e&&(!s||o.once)&&(!n||o.context===n)&&zr(this,i);else{for(var a=0,c=[],f=o.length;a<f;a++)(o[a].fn!==e||s&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[i]=c.length===1?c[0]:c:zr(this,i)}return this};ft.prototype.removeAllListeners=function(t){var e;return t?(e=ht?ht+t:t,this._events[e]&&zr(this,e)):(this._events=new fr,this._eventsCount=0),this};ft.prototype.off=ft.prototype.removeListener;ft.prototype.addListener=ft.prototype.on;ft.prefixed=ht;ft.EventEmitter=ft;typeof Gs<"u"&&(Gs.exports=ft)});var mf={};dt(mf,{StrictNoSign:()=>hf,StrictSign:()=>lf,TopicValidatorResult:()=>Ke,floodsub:()=>pf,isPubSub:()=>df,protocol:()=>Qs,pubSubSymbol:()=>Ue});var Ue=Symbol.for("@libp2p/pubsub");var z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ye=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var br=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var J=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var yr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var re=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var tn=Symbol.for("@libp2p/peer-id");var ge=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let s=this.#t.get(t);s!=null&&(s=s.filter(({callback:i})=>i!==e),this.#t.set(t,s))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:s})=>!s),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var ni=Symbol.for("@libp2p/service-capabilities"),si=Symbol.for("@libp2p/service-dependencies");var on={};dt(on,{base58btc:()=>Y,base58flickr:()=>Ba});var Zf=new Uint8Array(0);function ii(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 kt(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 oi(r){return new TextEncoder().encode(r)}function ai(r){return new TextDecoder().decode(r)}function xa(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 s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=s}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function u(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 I=0,S=0,g=0,A=p.length;g!==A&&p[g]===0;)g++,I++;for(var w=(A-g)*l+1>>>0,B=new Uint8Array(w);g!==A;){for(var P=p[g],U=0,M=w-1;(P!==0||U<S)&&M!==-1;M--,U++)P+=256*B[M]>>>0,B[M]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");S=U,g++}for(var E=w-S;E!==w&&B[E]===0;)E++;for(var x=c.repeat(I);E<w;++E)x+=r.charAt(B[E]);return x}function y(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var I=0;if(p[I]!==" "){for(var S=0,g=0;p[I]===c;)S++,I++;for(var A=(p.length-I)*f+1>>>0,w=new Uint8Array(A);p[I];){var B=e[p.charCodeAt(I)];if(B===255)return;for(var P=0,U=A-1;(B!==0||P<g)&&U!==-1;U--,P++)B+=a*w[U]>>>0,w[U]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");g=P,I++}if(p[I]!==" "){for(var M=A-g;M!==A&&w[M]===0;)M++;for(var E=new Uint8Array(S+(A-M)),x=S;M!==A;)E[x++]=w[M++];return E}}}function d(p){var I=y(p);if(I)return I;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:y,decode:d}}var Ea=xa,va=Ea,ui=va;var en=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")}},rn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let s=e.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 fi(this,t)}},nn=class{decoders;constructor(t){this.decoders=t}or(t){return fi(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 fi(r,t){return new nn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var sn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new en(t,e,n),this.decoder=new rn(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function we({name:r,prefix:t,encode:e,decode:n}){return new sn(r,t,e,n)}function zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=ui(e,r);return we({prefix:t,name:r,encode:n,decode:i=>kt(s(i))})}function Sa(r,t,e,n){let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),o=0,a=0,c=0;for(let f=0;f<s;++f){let l=t[r[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,o+=e,o>=8&&(o-=8,i[c++]=255&a>>o)}if(o>=e||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function Aa(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>e;)o-=e,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<e-o]),n)for(;(i.length*e&7)!==0;)i+="=";return i}function Ia(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function W({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let s=Ia(n);return we({prefix:t,name:r,encode(i){return Aa(i,n,e)},decode(i){return Sa(i,s,e,r)}})}var Y=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ba=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var an={};dt(an,{base32:()=>xe,base32hex:()=>Da,base32hexpad:()=>ka,base32hexpadupper:()=>Pa,base32hexupper:()=>Ra,base32pad:()=>_a,base32padupper:()=>Ta,base32upper:()=>La,base32z:()=>Ca});var xe=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),La=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),_a=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ta=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Da=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ra=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ka=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Pa=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ca=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var cn={};dt(cn,{base36:()=>Me,base36upper:()=>Na});var Me=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Na=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ka=di,li=128,Ua=127,Ma=~Ua,Oa=Math.pow(2,31);function di(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Oa;)t[e++]=r&255|li,r/=128;for(;r&Ma;)t[e++]=r&255|li,r>>>=7;return t[e]=r|0,di.bytes=e-n+1,t}var qa=un,Va=128,hi=127;function un(r,n){var e=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw un.bytes=0,new RangeError("Could not decode varint");o=r[i++],e+=s<28?(o&hi)<<s:(o&hi)*Math.pow(2,s),s+=7}while(o>=Va);return un.bytes=i-n,e}var Ha=Math.pow(2,7),Fa=Math.pow(2,14),za=Math.pow(2,21),$a=Math.pow(2,28),Za=Math.pow(2,35),Ya=Math.pow(2,42),Ga=Math.pow(2,49),Xa=Math.pow(2,56),ja=Math.pow(2,63),Wa=function(r){return r<Ha?1:r<Fa?2:r<za?3:r<$a?4:r<Za?5:r<Ya?6:r<Ga?7:r<Xa?8:r<ja?9:10},Ja={encode:Ka,decode:qa,encodingLength:Wa},Qa=Ja,Oe=Qa;function qe(r,t=0){return[Oe.decode(r,t),Oe.decode.bytes]}function Ee(r,t,e=0){return Oe.encode(r,t,e),t}function ve(r){return Oe.encodingLength(r)}function _t(r,t){let e=t.byteLength,n=ve(r),s=n+ve(e),i=new Uint8Array(s+e);return Ee(r,i,0),Ee(e,i,n),i.set(t,s),new Se(r,e,t,i)}function $t(r){let t=kt(r),[e,n]=qe(t),[s,i]=qe(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new Se(e,s,o,t)}function pi(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ii(r.bytes,e.bytes)}}var Se=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function mi(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return ec(e,fn(r),t??Y.encoder);default:return rc(e,fn(r),t??xe.encoder)}}var bi=new WeakMap;function fn(r){let t=bi.get(r);if(t==null){let e=new Map;return bi.set(r,e),e}return t}var at=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}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!==Ve)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==nc)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=_t(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&&pi(t.multihash,n.multihash)}toString(t){return mi(this,t)}toJSON(){return{"/":mi(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:s,multihash:i,bytes:o}=e;return new r(n,s,i,o??yi(n,s,i.bytes))}else if(e[sc]===!0){let{version:n,multihash:s,code:i}=e,o=$t(s);return r.create(n,i,o)}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!==Ve)throw new Error(`Version 0 CID must use dag-pb (code: ${Ve}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=yi(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ve,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,s=kt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=s.subarray(e.multihashSize-e.digestSize),o=new Se(e.multihashCode,e.digestSize,i,s);return[e.version===0?r.createV0(o):r.createV1(e.codec,o),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,y]=qe(t.subarray(e));return e+=y,u},s=n(),i=Ve;if(s===18?(s=0,e=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=e,a=n(),c=n(),f=e+c,l=f-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:f}}static parse(t,e){let[n,s]=tc(t,e),i=r.decode(s);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return fn(i).set(n,t),i}};function tc(r,t){switch(r[0]){case"Q":{let e=t??Y;return[Y.prefix,e.decode(`${Y.prefix}${r}`)]}case Y.prefix:{let e=t??Y;return[Y.prefix,e.decode(r)]}case xe.prefix:{let e=t??xe;return[xe.prefix,e.decode(r)]}case Me.prefix:{let e=t??Me;return[Me.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 ec(r,t,e){let{prefix:n}=e;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return s}function rc(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let i=e.encode(r);return t.set(n,i),i}else return s}var Ve=112,nc=18;function yi(r,t,e){let n=ve(r),s=n+ve(t),i=new Uint8Array(s+e.byteLength);return Ee(r,i,0),Ee(t,i,n),i.set(e,s),i}var sc=Symbol.for("@ipld/js-cid/CID");var ln={};dt(ln,{identity:()=>At});var gi=0,ic="identity",wi=kt;function oc(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return _t(gi,wi(r))}var At={code:gi,name:ic,encode:wi,digest:oc};function pt(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 Pt(r=0){return new Uint8Array(r)}function mt(r=0){return new Uint8Array(r)}function ne(r,t){t==null&&(t=r.reduce((s,i)=>s+i.length,0));let e=mt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}var Ei=Symbol.for("@achingbrain/uint8arraylist");function xi(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function wr(r){return!!r?.[Ei]}var et=class r{bufs;length;[Ei]=!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(wr(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(wr(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=xi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=xi(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(wr(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:s}=this._subList(t,e);return ne(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:ne(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),i=new r;return i.length=s,i.bufs=[...n],i}_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=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,t>=c)continue;let f=t>=a&&t<c,l=e>a&&e<=c;if(f&&l){if(t===a&&e===c){n.push(o);break}let u=t-a;n.push(o.subarray(u,u+(e-t)));break}if(f){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(l){if(e===c){n.push(o);break}n.push(o.subarray(0,e-a));break}n.push(o)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!wr(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 s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let u=0;u<i;u++)o[u]=-1;for(let u=0;u<s;u++)o[n[u]]=u;let a=o,c=this.byteLength-n.byteLength,f=n.byteLength-1,l;for(let u=e;u<=c;u+=l){l=0;for(let y=f;y>=0;y--){let d=this.get(u+y);if(n[y]!==d){l=Math.max(1,y-a[d]);break}}if(l===0)return u}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=mt(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 s=Pt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,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 s=Pt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,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 s=Pt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,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=mt(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 s=Pt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,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 s=Pt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,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 s=Pt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,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 s=Pt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,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 s=Pt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,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(!pt(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((s,i)=>s+i.byteLength,0)),n.length=e,n}};var hn={};dt(hn,{base10:()=>ac});var ac=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var dn={};dt(dn,{base16:()=>cc,base16upper:()=>uc});var cc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),uc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var pn={};dt(pn,{base2:()=>fc});var fc=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var mn={};dt(mn,{base256emoji:()=>mc});var vi=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}"),lc=vi.reduce((r,t,e)=>(r[e]=t,r),[]),hc=vi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function dc(r){return r.reduce((t,e)=>(t+=lc[e],t),"")}function pc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=hc[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var mc=we({prefix:"\u{1F680}",name:"base256emoji",encode:dc,decode:pc});var bn={};dt(bn,{base64:()=>bc,base64pad:()=>yc,base64url:()=>gc,base64urlpad:()=>wc});var bc=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),yc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),gc=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wc=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var yn={};dt(yn,{base8:()=>xc});var xc=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var gn={};dt(gn,{identity:()=>Ec});var Ec=we({prefix:"\0",name:"identity",encode:r=>ai(r),decode:r=>oi(r)});var Tl=new TextEncoder,Dl=new TextDecoder;var En={};dt(En,{sha256:()=>se,sha512:()=>Ic});var Ac=20;function xn({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:s}){return new wn(r,t,e,n,s)}var wn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,s,i){this.name=t,this.code=e,this.encode=n,this.minDigestLength=s??Ac,this.maxDigestLength=i}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Si(n,this.code,e?.truncate):n.then(s=>Si(s,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Si(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return _t(t,r)}function Ii(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var se=xn({name:"sha2-256",code:18,encode:Ii("SHA-256")}),Ic=xn({name:"sha2-512",code:19,encode:Ii("SHA-512")});var vn={...gn,...pn,...yn,...hn,...dn,...an,...cn,...on,...bn,...mn},Hl={...En,...ln};function Li(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Bi=Li("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Sn=Li("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=mt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Bc={utf8:Bi,"utf-8":Bi,hex:vn.base16,latin1:Sn,ascii:Sn,binary:Sn,...vn},xr=Bc;function F(r,t="utf8"){let e=xr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function H(r,t="utf8"){let e=xr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Lc=parseInt("11111",2),An=parseInt("10000000",2),_c=parseInt("01111111",2),_i={0:He,1:He,2:Tc,3:kc,4:Pc,5:Rc,6:Dc,16:He,22:He,48:He};function Ct(r,t={offset:0}){let e=r[t.offset]&Lc;if(t.offset++,_i[e]!=null)return _i[e](r,t);throw new Error("No decoder for tag "+e)}function Fe(r,t){let e=0;if((r[t.offset]&An)===An){let n=r[t.offset]&_c,s="0x";t.offset++;for(let i=0;i<n;i++,t.offset++)s+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(s,16)}else e=r[t.offset],t.offset++;return e}function He(r,t){Fe(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Ct(r,t);if(n===null)break;e.push(n)}return e}function Tc(r,t){let e=Fe(r,t),n=t.offset,s=t.offset+e,i=[];for(let o=n;o<s;o++)o===n&&r[o]===0||i.push(r[o]);return t.offset+=e,Uint8Array.from(i)}function Dc(r,t){let e=Fe(r,t),n=t.offset+e,s=r[t.offset];t.offset++;let i=0,o=0;s<40?(i=0,o=s):s<80?(i=1,o=s-40):(i=2,o=s-80);let a=`${i}.${o}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let l=0;for(let u=0;u<c.length;u++)l+=c[u]<<u*7;a+=`.${l}`,c=[]}}return a}function Rc(r,t){return t.offset++,null}function kc(r,t){let e=Fe(r,t),n=r[t.offset];t.offset++;let s=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 s}function Pc(r,t){let e=Fe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Cc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new et;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function In(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Cc(r.byteLength);return new et(Uint8Array.from([t.byteLength|An]),t)}function bt(r){let t=new et,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new et(Uint8Array.from([2]),In(t),t)}function Er(r){let t=Uint8Array.from([0]),e=new et(t,r);return new et(Uint8Array.from([3]),In(e),e)}function Yt(r,t=48){let e=new et;for(let n of r)e.append(n);return new et(Uint8Array.from([t]),In(e),e)}async function Ti(r,t,e,n){let s=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,t,e.subarray());return n?.signal?.throwIfAborted(),i}var Nc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Kc=Uint8Array.from([6,5,43,129,4,0,34]),Uc=Uint8Array.from([6,5,43,129,4,0,35]),Mc={ext:!0,kty:"EC",crv:"P-256"},Oc={ext:!0,kty:"EC",crv:"P-384"},qc={ext:!0,kty:"EC",crv:"P-521"},Bn=32,Ln=48,_n=66;function Tn(r){let t=Ct(r);return Di(t)}function Di(r){let t=r[1][1][0],e=1,n,s;if(t.byteLength===Bn*2+1)return n=H(t.subarray(e,e+Bn),"base64url"),s=H(t.subarray(e+Bn),"base64url"),new Ae({...Mc,key_ops:["verify"],x:n,y:s});if(t.byteLength===Ln*2+1)return n=H(t.subarray(e,e+Ln),"base64url"),s=H(t.subarray(e+Ln),"base64url"),new Ae({...Oc,key_ops:["verify"],x:n,y:s});if(t.byteLength===_n*2+1)return n=H(t.subarray(e,e+_n),"base64url"),s=H(t.subarray(e+_n),"base64url"),new Ae({...qc,key_ops:["verify"],x:n,y:s});throw new z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ri(r){return Yt([bt(Uint8Array.from([1])),Yt([Vc(r.crv)],160),Yt([Er(new et(Uint8Array.from([4]),F(r.x??"","base64url"),F(r.y??"","base64url")))],161)]).subarray()}function Vc(r){if(r==="P-256")return Nc;if(r==="P-384")return Kc;if(r==="P-521")return Uc;throw new z(`Invalid curve ${r}`)}var Ae=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ri(this.jwk)),this._raw}toMultihash(){return At.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}async verify(t,e,n){return Ti(this.jwk,e,t,n)}};function ie(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Tt(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function K(r,t,e=""){let n=ie(r),s=r?.length,i=t!==void 0;if(!n||i&&s!==t){let o=e&&`"${e}" `,a=i?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof r}`;throw new Error(o+"expected Uint8Array"+a+", got "+c)}return r}function vr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Tt(r.outputLen),Tt(r.blockLen)}function Ie(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 Pi(r,t){K(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function Ut(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Sr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function It(r,t){return r<<32-t|r>>>t}var Ci=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Hc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Mt(r){if(K(r),Ci)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Hc[r[e]];return t}var Kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ki(r){if(r>=Kt._0&&r<=Kt._9)return r-Kt._0;if(r>=Kt.A&&r<=Kt.F)return r-(Kt.A-10);if(r>=Kt.a&&r<=Kt.f)return r-(Kt.a-10)}function Ot(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Ci)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 s=0,i=0;s<e;s++,i+=2){let o=ki(r.charCodeAt(i)),a=ki(r.charCodeAt(i+1));if(o===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function yt(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];K(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let i=r[n];e.set(i,s),s+=i.length}return e}function Dn(r,t={}){let e=(s,i)=>r(i).update(s).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=s=>r(s),Object.assign(e,t),Object.freeze(e)}function Gt(r=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(r))}var Rn=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function Ni(r,t,e){return r&t^~r&e}function Ki(r,t,e){return r&t^r&e^t&e}var ze=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,s){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Sr(this.buffer)}update(t){Ie(this),K(t);let{view:e,buffer:n,blockLen:s}=this,i=t.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=Sr(t);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ie(this),Pi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;e[o++]=128,Ut(this.buffer.subarray(o)),this.padOffset>s-o&&(this.process(n,0),o=0);for(let u=o;u<s;u++)e[u]=0;n.setBigUint64(s-8,BigInt(this.length*8),i),this.process(n,0);let a=Sr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)a.setUint32(4*u,l[u],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return t.destroyed=o,t.finished=i,t.length=s,t.pos=a,s%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},qt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var it=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ar=BigInt(4294967295),Ui=BigInt(32);function Fc(r,t=!1){return t?{h:Number(r&Ar),l:Number(r>>Ui&Ar)}:{h:Number(r>>Ui&Ar)|0,l:Number(r&Ar)|0}}function Mi(r,t=!1){let e=r.length,n=new Uint32Array(e),s=new Uint32Array(e);for(let i=0;i<e;i++){let{h:o,l:a}=Fc(r[i],t);[n[i],s[i]]=[o,a]}return[n,s]}var kn=(r,t,e)=>r>>>e,Pn=(r,t,e)=>r<<32-e|t>>>e,oe=(r,t,e)=>r>>>e|t<<32-e,ae=(r,t,e)=>r<<32-e|t>>>e,$e=(r,t,e)=>r<<64-e|t>>>e-32,Ze=(r,t,e)=>r>>>e-32|t<<64-e;function Dt(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var Oi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),qi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Vi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Hi=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,Fi=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),zi=(r,t,e,n,s,i)=>t+e+n+s+i+(r/2**32|0)|0;var $c=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]),Xt=new Uint32Array(64),Cn=class extends ze{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[t,e,n,s,i,o,a,c]}set(t,e,n,s,i,o,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(t,e){for(let u=0;u<16;u++,e+=4)Xt[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let y=Xt[u-15],d=Xt[u-2],p=It(y,7)^It(y,18)^y>>>3,I=It(d,17)^It(d,19)^d>>>10;Xt[u]=I+Xt[u-7]+p+Xt[u-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:f,H:l}=this;for(let u=0;u<64;u++){let y=It(a,6)^It(a,11)^It(a,25),d=l+y+Ni(a,c,f)+$c[u]+Xt[u]|0,I=(It(n,2)^It(n,13)^It(n,22))+Ki(n,s,i)|0;l=f,f=c,c=a,a=o+d|0,o=i,i=s,s=n,n=d+I|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,l=l+this.H|0,this.set(n,s,i,o,a,c,f,l)}roundClean(){Ut(Xt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}},Nn=class extends Cn{A=qt[0]|0;B=qt[1]|0;C=qt[2]|0;D=qt[3]|0;E=qt[4]|0;F=qt[5]|0;G=qt[6]|0;H=qt[7]|0;constructor(){super(32)}};var $i=Mi(["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))),Zc=$i[0],Yc=$i[1],jt=new Uint32Array(80),Wt=new Uint32Array(80),Kn=class extends ze{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:f,El:l,Fh:u,Fl:y,Gh:d,Gl:p,Hh:I,Hl:S}=this;return[t,e,n,s,i,o,a,c,f,l,u,y,d,p,I,S]}set(t,e,n,s,i,o,a,c,f,l,u,y,d,p,I,S){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=u|0,this.Fl=y|0,this.Gh=d|0,this.Gl=p|0,this.Hh=I|0,this.Hl=S|0}process(t,e){for(let w=0;w<16;w++,e+=4)jt[w]=t.getUint32(e),Wt[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let B=jt[w-15]|0,P=Wt[w-15]|0,U=oe(B,P,1)^oe(B,P,8)^kn(B,P,7),M=ae(B,P,1)^ae(B,P,8)^Pn(B,P,7),E=jt[w-2]|0,x=Wt[w-2]|0,C=oe(E,x,19)^$e(E,x,61)^kn(E,x,6),O=ae(E,x,19)^Ze(E,x,61)^Pn(E,x,6),D=Vi(M,O,Wt[w-7],Wt[w-16]),m=Hi(D,U,C,jt[w-7],jt[w-16]);jt[w]=m|0,Wt[w]=D|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:f,Dl:l,Eh:u,El:y,Fh:d,Fl:p,Gh:I,Gl:S,Hh:g,Hl:A}=this;for(let w=0;w<80;w++){let B=oe(u,y,14)^oe(u,y,18)^$e(u,y,41),P=ae(u,y,14)^ae(u,y,18)^Ze(u,y,41),U=u&d^~u&I,M=y&p^~y&S,E=Fi(A,P,M,Yc[w],Wt[w]),x=zi(E,g,B,U,Zc[w],jt[w]),C=E|0,O=oe(n,s,28)^$e(n,s,34)^$e(n,s,39),D=ae(n,s,28)^Ze(n,s,34)^Ze(n,s,39),m=n&i^n&a^i&a,b=s&o^s&c^o&c;g=I|0,A=S|0,I=d|0,S=p|0,d=u|0,p=y|0,{h:u,l:y}=Dt(f|0,l|0,x|0,C|0),f=a|0,l=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let h=Oi(C,D,b);n=qi(h,x,O,m),s=h|0}({h:n,l:s}=Dt(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=Dt(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=Dt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=Dt(this.Dh|0,this.Dl|0,f|0,l|0),{h:u,l:y}=Dt(this.Eh|0,this.El|0,u|0,y|0),{h:d,l:p}=Dt(this.Fh|0,this.Fl|0,d|0,p|0),{h:I,l:S}=Dt(this.Gh|0,this.Gl|0,I|0,S|0),{h:g,l:A}=Dt(this.Hh|0,this.Hl|0,g|0,A|0),this.set(n,s,i,o,a,c,f,l,u,y,d,p,I,S,g,A)}roundClean(){Ut(jt,Wt)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Un=class extends Kn{Ah=it[0]|0;Al=it[1]|0;Bh=it[2]|0;Bl=it[3]|0;Ch=it[4]|0;Cl=it[5]|0;Dh=it[6]|0;Dl=it[7]|0;Eh=it[8]|0;El=it[9]|0;Fh=it[10]|0;Fl=it[11]|0;Gh=it[12]|0;Gl=it[13]|0;Hh=it[14]|0;Hl=it[15]|0;constructor(){super(64)}};var Be=Dn(()=>new Nn,Rn(1));var Zi=Dn(()=>new Un,Rn(3));var On=BigInt(0),Mn=BigInt(1);function Vt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function Yi(r){if(typeof r=="bigint"){if(!Ir(r))throw new Error("positive bigint expected, got "+r)}else Tt(r);return r}function Ye(r){let t=Yi(r).toString(16);return t.length&1?"0"+t:t}function Gi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?On:BigInt("0x"+r)}function Le(r){return Gi(Mt(r))}function ce(r){return Gi(Mt(Lr(K(r)).reverse()))}function Br(r,t){Tt(t),r=Yi(r);let e=Ot(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function qn(r,t){return Br(r,t).reverse()}function Lr(r){return Uint8Array.from(r)}var Ir=r=>typeof r=="bigint"&&On<=r;function Gc(r,t,e){return Ir(r)&&Ir(t)&&Ir(e)&&t<=r&&r<e}function Ge(r,t,e,n){if(!Gc(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Vn(r){let t;for(t=0;r>On;r>>=Mn,t+=1);return t}var Xe=r=>(Mn<<BigInt(r))-Mn;function Xi(r,t,e){if(Tt(r,"hashLen"),Tt(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=S=>new Uint8Array(S),s=Uint8Array.of(),i=Uint8Array.of(0),o=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),l=0,u=()=>{c.fill(1),f.fill(0),l=0},y=(...S)=>e(f,yt(c,...S)),d=(S=s)=>{f=y(i,S),c=y(),S.length!==0&&(f=y(o,S),c=y())},p=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let S=0,g=[];for(;S<t;){c=y();let A=c.slice();g.push(A),S+=c.length}return yt(...g)};return(S,g)=>{u(),d(S);let A;for(;!(A=g(p()));)d();return u(),A}}function Jt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(i,o,a){let c=r[i];if(a&&c===void 0)return;let f=typeof c;if(f!==o||c===null)throw new Error(`param "${i}" is invalid: expected ${o}, got ${f}`)}let s=(i,o)=>Object.entries(i).forEach(([a,c])=>n(a,c,o));s(t,!1),s(e,!0)}function _e(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let i=r(e,...n);return t.set(e,i),i}}var lt=BigInt(0),rt=BigInt(1),ue=BigInt(2),Ji=BigInt(3),Qi=BigInt(4),to=BigInt(5),Xc=BigInt(7),eo=BigInt(8),jc=BigInt(9),ro=BigInt(16);function Q(r,t){let e=r%t;return e>=lt?e:t+e}function Z(r,t,e){let n=r;for(;t-- >lt;)n*=n,n%=e;return n}function ji(r,t){if(r===lt)throw new Error("invert: expected non-zero number");if(t<=lt)throw new Error("invert: expected positive modulus, got "+t);let e=Q(r,t),n=t,s=lt,i=rt,o=rt,a=lt;for(;e!==lt;){let f=n/e,l=n%e,u=s-o*f,y=i-a*f;n=e,e=l,s=o,i=a,o=u,a=y}if(n!==rt)throw new Error("invert: does not exist");return Q(s,t)}function Fn(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function no(r,t){let e=(r.ORDER+rt)/Qi,n=r.pow(t,e);return Fn(r,n,t),n}function Wc(r,t){let e=(r.ORDER-to)/eo,n=r.mul(t,ue),s=r.pow(n,e),i=r.mul(t,s),o=r.mul(r.mul(i,ue),s),a=r.mul(i,r.sub(o,r.ONE));return Fn(r,a,t),a}function Jc(r){let t=Te(r),e=so(r),n=e(t,t.neg(t.ONE)),s=e(t,n),i=e(t,t.neg(n)),o=(r+Xc)/ro;return(a,c)=>{let f=a.pow(c,o),l=a.mul(f,n),u=a.mul(f,s),y=a.mul(f,i),d=a.eql(a.sqr(l),c),p=a.eql(a.sqr(u),c);f=a.cmov(f,l,d),l=a.cmov(y,u,p);let I=a.eql(a.sqr(l),c),S=a.cmov(f,l,I);return Fn(a,S,c),S}}function so(r){if(r<Ji)throw new Error("sqrt is not defined for small field");let t=r-rt,e=0;for(;t%ue===lt;)t/=ue,e++;let n=ue,s=Te(r);for(;Wi(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return no;let i=s.pow(n,t),o=(t+rt)/ue;return function(c,f){if(c.is0(f))return f;if(Wi(c,f)!==1)throw new Error("Cannot find square root");let l=e,u=c.mul(c.ONE,i),y=c.pow(f,t),d=c.pow(f,o);for(;!c.eql(y,c.ONE);){if(c.is0(y))return c.ZERO;let p=1,I=c.sqr(y);for(;!c.eql(I,c.ONE);)if(p++,I=c.sqr(I),p===l)throw new Error("Cannot find square root");let S=rt<<BigInt(l-p-1),g=c.pow(u,S);l=p,u=c.sqr(g),y=c.mul(y,u),d=c.mul(d,g)}return d}}function Qc(r){return r%Qi===Ji?no:r%eo===to?Wc:r%ro===jc?Jc(r):so(r)}var io=(r,t)=>(Q(r,t)&rt)===rt,tu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function zn(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=tu.reduce((n,s)=>(n[s]="function",n),t);return Jt(r,e),r}function eu(r,t,e){if(e<lt)throw new Error("invalid exponent, negatives unsupported");if(e===lt)return r.ONE;if(e===rt)return t;let n=r.ONE,s=t;for(;e>lt;)e&rt&&(n=r.mul(n,s)),s=r.sqr(s),e>>=rt;return n}function je(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),s=t.reduce((o,a,c)=>r.is0(a)?o:(n[c]=o,r.mul(o,a)),r.ONE),i=r.inv(s);return t.reduceRight((o,a,c)=>r.is0(a)?o:(n[c]=r.mul(o,n[c]),r.mul(o,a)),i),n}function Wi(r,t){let e=(r.ORDER-rt)/ue,n=r.pow(t,e),s=r.eql(n,r.ONE),i=r.eql(n,r.ZERO),o=r.eql(n,r.neg(r.ONE));if(!s&&!i&&!o)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function ru(r,t){t!==void 0&&Tt(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var Hn=class{ORDER;BITS;BYTES;isLE;ZERO=lt;ONE=rt;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=lt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:s,nByteLength:i}=ru(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return Q(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return lt<=t&&t<this.ORDER}is0(t){return t===lt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&rt)===rt}neg(t){return Q(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Q(t*t,this.ORDER)}add(t,e){return Q(t+e,this.ORDER)}sub(t,e){return Q(t-e,this.ORDER)}mul(t,e){return Q(t*e,this.ORDER)}pow(t,e){return eu(this,t,e)}div(t,e){return Q(t*ji(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return ji(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Qc(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?qn(t,this.BYTES):Br(t,this.BYTES)}fromBytes(t,e=!1){K(t);let{_lengths:n,BYTES:s,isLE:i,ORDER:o,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(s);f.set(t,i?0:f.length-t.length),t=f}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=i?ce(t):Le(t);if(a&&(c=Q(c,o)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return je(this,t)}cmov(t,e,n){return n?e:t}};function Te(r,t={}){return new Hn(r,t)}function oo(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 $n(r){let t=oo(r);return t+Math.ceil(t/2)}function Zn(r,t,e=!1){K(r);let n=r.length,s=oo(t),i=$n(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=e?ce(r):Le(r),a=Q(o,t-rt)+rt;return e?qn(a,s):Br(a,s)}var De=BigInt(0),fe=BigInt(1);function We(r,t){let e=t.negate();return r?e:t}function le(r,t){let e=je(r.Fp,t.map(n=>n.Z));return t.map((n,s)=>r.fromAffine(n.toAffine(e[s])))}function fo(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Yn(r,t){fo(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),s=2**r,i=Xe(r),o=BigInt(r);return{windows:e,windowSize:n,mask:i,maxNumber:s,shiftBy:o}}function ao(r,t,e){let{windowSize:n,mask:s,maxNumber:i,shiftBy:o}=e,a=Number(r&s),c=r>>o;a>n&&(a-=i,c+=fe);let f=t*n,l=f+Math.abs(a)-1,u=a===0,y=a<0,d=t%2!==0;return{nextN:c,offset:l,isZero:u,isNeg:y,isNegF:d,offsetF:f}}var Gn=new WeakMap,lo=new WeakMap;function Xn(r){return lo.get(r)||1}function co(r){if(r!==De)throw new Error("invalid wNAF")}var Re=class{BASE;ZERO;Fn;bits;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 s=t;for(;e>De;)e&fe&&(n=n.add(s)),s=s.double(),e>>=fe;return n}precomputeWindow(t,e){let{windows:n,windowSize:s}=Yn(e,this.bits),i=[],o=t,a=o;for(let c=0;c<n;c++){a=o,i.push(a);for(let f=1;f<s;f++)a=a.add(o),i.push(a);o=a.double()}return i}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,i=this.BASE,o=Yn(t,this.bits);for(let a=0;a<o.windows;a++){let{nextN:c,offset:f,isZero:l,isNeg:u,isNegF:y,offsetF:d}=ao(n,a,o);n=c,l?i=i.add(We(y,e[d])):s=s.add(We(u,e[f]))}return co(n),{p:s,f:i}}wNAFUnsafe(t,e,n,s=this.ZERO){let i=Yn(t,this.bits);for(let o=0;o<i.windows&&n!==De;o++){let{nextN:a,offset:c,isZero:f,isNeg:l}=ao(n,o,i);if(n=a,!f){let u=e[c];s=s.add(l?u.negate():u)}}return co(n),s}getPrecomputes(t,e,n){let s=Gn.get(e);return s||(s=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(s=n(s)),Gn.set(e,s))),s}cached(t,e,n){let s=Xn(t);return this.wNAF(s,this.getPrecomputes(s,t,n),e)}unsafe(t,e,n,s){let i=Xn(t);return i===1?this._unsafeLadder(t,e,s):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),e,s)}createCache(t,e){fo(e,this.bits),lo.set(t,e),Gn.delete(t)}hasCache(t){return Xn(t)!==1}};function ho(r,t,e,n){let s=t,i=r.ZERO,o=r.ZERO;for(;e>De||n>De;)e&fe&&(i=i.add(s)),n&fe&&(o=o.add(s)),s=s.double(),e>>=fe,n>>=fe;return{p1:i,p2:o}}function uo(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return zn(t),t}else return Te(r,{isLE:e})}function _r(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>De))throw new Error(`CURVE.${c} must be positive bigint`)}let s=uo(t.p,e.Fp,n),i=uo(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:i}}function Tr(r,t){return function(n){let s=r(n);return{secretKey:s,publicKey:t(s)}}}var Qt=BigInt(0),nt=BigInt(1),jn=BigInt(2),nu=BigInt(8);function su(r,t,e,n){let s=r.sqr(e),i=r.sqr(n),o=r.add(r.mul(t.a,s),i),a=r.add(r.ONE,r.mul(t.d,r.mul(s,i)));return r.eql(o,a)}function po(r,t={}){let e=_r("edwards",r,t,t.FpFnLE),{Fp:n,Fn:s}=e,i=e.CURVE,{h:o}=i;Jt(t,{},{uvRatio:"function"});let a=jn<<BigInt(s.BYTES*8)-nt,c=S=>n.create(S),f=t.uvRatio||((S,g)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,g))}}catch{return{isValid:!1,value:Qt}}});if(!su(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(S,g,A=!1){let w=A?nt:Qt;return Ge("coordinate "+S,g,w,a),g}function u(S){if(!(S instanceof p))throw new Error("EdwardsPoint expected")}let y=_e((S,g)=>{let{X:A,Y:w,Z:B}=S,P=S.is0();g==null&&(g=P?nu:n.inv(B));let U=c(A*g),M=c(w*g),E=n.mul(B,g);if(P)return{x:Qt,y:nt};if(E!==nt)throw new Error("invZ was invalid");return{x:U,y:M}}),d=_e(S=>{let{a:g,d:A}=i;if(S.is0())throw new Error("bad point: ZERO");let{X:w,Y:B,Z:P,T:U}=S,M=c(w*w),E=c(B*B),x=c(P*P),C=c(x*x),O=c(M*g),D=c(x*c(O+E)),m=c(C+c(A*c(M*E)));if(D!==m)throw new Error("bad point: equation left != right (1)");let b=c(w*B),h=c(P*U);if(b!==h)throw new Error("bad point: equation left != right (2)");return!0});class p{static BASE=new p(i.Gx,i.Gy,nt,c(i.Gx*i.Gy));static ZERO=new p(Qt,nt,nt,Qt);static Fp=n;static Fn=s;X;Y;Z;T;constructor(g,A,w,B){this.X=l("x",g),this.Y=l("y",A),this.Z=l("z",w,!0),this.T=l("t",B),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof p)throw new Error("extended point not allowed");let{x:A,y:w}=g||{};return l("x",A),l("y",w),new p(A,w,nt,c(A*w))}static fromBytes(g,A=!1){let w=n.BYTES,{a:B,d:P}=i;g=Lr(K(g,w,"point")),Vt(A,"zip215");let U=Lr(g),M=g[w-1];U[w-1]=M&-129;let E=ce(U),x=A?a:n.ORDER;Ge("point.y",E,Qt,x);let C=c(E*E),O=c(C-nt),D=c(P*C-B),{isValid:m,value:b}=f(O,D);if(!m)throw new Error("bad point: invalid y coordinate");let h=(b&nt)===nt,v=(M&128)!==0;if(!A&&b===Qt&&v)throw new Error("bad point: x=0 and x_0=1");return v!==h&&(b=c(-b)),p.fromAffine({x:b,y:E})}static fromHex(g,A=!1){return p.fromBytes(Ot(g),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,A=!0){return I.createCache(this,g),A||this.multiply(jn),this}assertValidity(){d(this)}equals(g){u(g);let{X:A,Y:w,Z:B}=this,{X:P,Y:U,Z:M}=g,E=c(A*M),x=c(P*B),C=c(w*M),O=c(U*B);return E===x&&C===O}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:g}=i,{X:A,Y:w,Z:B}=this,P=c(A*A),U=c(w*w),M=c(jn*c(B*B)),E=c(g*P),x=A+w,C=c(c(x*x)-P-U),O=E+U,D=O-M,m=E-U,b=c(C*D),h=c(O*m),v=c(C*m),L=c(D*O);return new p(b,h,L,v)}add(g){u(g);let{a:A,d:w}=i,{X:B,Y:P,Z:U,T:M}=this,{X:E,Y:x,Z:C,T:O}=g,D=c(B*E),m=c(P*x),b=c(M*w*O),h=c(U*C),v=c((B+P)*(E+x)-D-m),L=h-b,T=h+b,R=c(m-A*D),_=c(v*L),k=c(T*R),N=c(v*R),G=c(L*T);return new p(_,k,G,N)}subtract(g){return this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=I.cached(this,g,B=>le(p,B));return le(p,[A,w])[0]}multiplyUnsafe(g,A=p.ZERO){if(!s.isValid(g))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return g===Qt?p.ZERO:this.is0()||g===nt?this:I.unsafe(this,g,w=>le(p,w),A)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return I.unsafe(this,i.n).is0()}toAffine(g){return y(this,g)}clearCofactor(){return o===nt?this:this.multiplyUnsafe(o)}toBytes(){let{x:g,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=g&nt?128:0,w}toHex(){return Mt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let I=new Re(p,s.BITS);return p.BASE.precompute(8),p}function mo(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');Jt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:s,Fp:i,Fn:o}=r,a=e.randomBytes||Gt,c=e.adjustScalarBytes||(E=>E),f=e.domain||((E,x,C)=>{if(Vt(C,"phflag"),x.length||C)throw new Error("Contexts/pre-hash are not supported");return E});function l(E){return o.create(ce(E))}function u(E){let x=w.secretKey;K(E,w.secretKey,"secretKey");let C=K(t(E),2*x,"hashedSecretKey"),O=c(C.slice(0,x)),D=C.slice(x,2*x),m=l(O);return{head:O,prefix:D,scalar:m}}function y(E){let{head:x,prefix:C,scalar:O}=u(E),D=s.multiply(O),m=D.toBytes();return{head:x,prefix:C,scalar:O,point:D,pointBytes:m}}function d(E){return y(E).pointBytes}function p(E=Uint8Array.of(),...x){let C=yt(...x);return l(t(f(C,K(E,void 0,"context"),!!n)))}function I(E,x,C={}){E=K(E,void 0,"message"),n&&(E=n(E));let{prefix:O,scalar:D,pointBytes:m}=y(x),b=p(C.context,O,E),h=s.multiply(b).toBytes(),v=p(C.context,h,m,E),L=o.create(b+v*D);if(!o.isValid(L))throw new Error("sign failed: invalid s");let T=yt(h,o.toBytes(L));return K(T,w.signature,"result")}let S={zip215:!0};function g(E,x,C,O=S){let{context:D,zip215:m}=O,b=w.signature;E=K(E,b,"signature"),x=K(x,void 0,"message"),C=K(C,w.publicKey,"publicKey"),m!==void 0&&Vt(m,"zip215"),n&&(x=n(x));let h=b/2,v=E.subarray(0,h),L=ce(E.subarray(h,b)),T,R,_;try{T=r.fromBytes(C,m),R=r.fromBytes(v,m),_=s.multiplyUnsafe(L)}catch{return!1}if(!m&&T.isSmallOrder())return!1;let k=p(D,R.toBytes(),T.toBytes(),x);return R.add(T.multiplyUnsafe(k)).subtract(_).clearCofactor().is0()}let A=i.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function B(E=a(w.seed)){return K(E,w.seed,"seed")}function P(E){return ie(E)&&E.length===o.BYTES}function U(E,x){try{return!!r.fromBytes(E,x)}catch{return!1}}let M={getExtendedPublicKey:y,randomSecretKey:B,isValidSecretKey:P,isValidPublicKey:U,toMontgomery(E){let{y:x}=r.fromBytes(E),C=w.publicKey,O=C===32;if(!O&&C!==57)throw new Error("only defined for 25519 and 448");let D=O?i.div(nt+x,nt-x):i.div(x-nt,x+nt);return i.toBytes(D)},toMontgomerySecret(E){let x=w.secretKey;K(E,x);let C=t(E.subarray(0,x));return c(C).subarray(0,x)}};return Object.freeze({keygen:Tr(B,d),getPublicKey:d,sign:I,verify:g,utils:M,Point:r,lengths:w})}var iu=BigInt(1),bo=BigInt(2);var ou=BigInt(5),au=BigInt(8),Wn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),cu={p:Wn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:au,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function uu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),i=Wn,a=r*r%i*r%i,c=Z(a,bo,i)*a%i,f=Z(c,iu,i)*r%i,l=Z(f,ou,i)*f%i,u=Z(l,t,i)*l%i,y=Z(u,e,i)*u%i,d=Z(y,n,i)*y%i,p=Z(d,s,i)*d%i,I=Z(p,s,i)*d%i,S=Z(I,t,i)*l%i;return{pow_p_5_8:Z(S,bo,i)*r%i,b2:a}}function fu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var yo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function lu(r,t){let e=Wn,n=Q(t*t*t,e),s=Q(n*n*t,e),i=uu(r*s).pow_p_5_8,o=Q(r*n*i,e),a=Q(t*o*o,e),c=o,f=Q(o*yo,e),l=a===r,u=a===Q(-r,e),y=a===Q(-r*yo,e);return l&&(o=c),(u||y)&&(o=f),io(o,e)&&(o=Q(-o,e)),{isValid:l||u,value:o}}var hu=po(cu,{uvRatio:lu});function du(r){return mo(hu,Zi,Object.assign({adjustScalarBytes:fu},r))}var go=du({});var Je=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Dr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var wo={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Dr("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 vt=wo;var Rr=32;var Jn,pu=(async()=>{try{return await vt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function mu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await vt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await vt.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 bu(r,t,e){return go.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function xo(r,t,e){return Jn==null&&(Jn=await pu),Jn?mu(r,t,e):bu(r,t,e)}function kr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Pr=class{type="Ed25519";raw;constructor(t){this.raw=Qn(t,Rr)}toMultihash(){return At.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let s=xo(this.raw,e,t);return kr(s)?s.then(i=>(n?.signal?.throwIfAborted(),i)):s}};function ts(r){return r=Qn(r,Rr),new Pr(r)}function Qn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new z(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var gu=Math.pow(2,7),wu=Math.pow(2,14),xu=Math.pow(2,21),es=Math.pow(2,28),rs=Math.pow(2,35),ns=Math.pow(2,42),ss=Math.pow(2,49),V=128,ct=127;function Ht(r){if(r<gu)return 1;if(r<wu)return 2;if(r<xu)return 3;if(r<es)return 4;if(r<rs)return 5;if(r<ns)return 6;if(r<ss)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function is(r,t,e=0){switch(Ht(r)){case 8:t[e++]=r&255|V,r/=128;case 7:t[e++]=r&255|V,r/=128;case 6:t[e++]=r&255|V,r/=128;case 5:t[e++]=r&255|V,r/=128;case 4:t[e++]=r&255|V,r>>>=7;case 3:t[e++]=r&255|V,r>>>=7;case 2:t[e++]=r&255|V,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Eu(r,t,e=0){switch(Ht(r)){case 8:t.set(e++,r&255|V),r/=128;case 7:t.set(e++,r&255|V),r/=128;case 6:t.set(e++,r&255|V),r/=128;case 5:t.set(e++,r&255|V),r/=128;case 4:t.set(e++,r&255|V),r>>>=7;case 3:t.set(e++,r&255|V),r>>>=7;case 2:t.set(e++,r&255|V),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function os(r,t){let e=r[t],n=0;if(n+=e&ct,e<V||(e=r[t+1],n+=(e&ct)<<7,e<V)||(e=r[t+2],n+=(e&ct)<<14,e<V)||(e=r[t+3],n+=(e&ct)<<21,e<V)||(e=r[t+4],n+=(e&ct)*es,e<V)||(e=r[t+5],n+=(e&ct)*rs,e<V)||(e=r[t+6],n+=(e&ct)*ns,e<V)||(e=r[t+7],n+=(e&ct)*ss,e<V))return n;throw new RangeError("Could not decode varint")}function vu(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<V||(e=r.get(t+1),n+=(e&ct)<<7,e<V)||(e=r.get(t+2),n+=(e&ct)<<14,e<V)||(e=r.get(t+3),n+=(e&ct)<<21,e<V)||(e=r.get(t+4),n+=(e&ct)*es,e<V)||(e=r.get(t+5),n+=(e&ct)*rs,e<V)||(e=r.get(t+6),n+=(e&ct)*ns,e<V)||(e=r.get(t+7),n+=(e&ct)*ss,e<V))return n;throw new RangeError("Could not decode varint")}function vo(r,t,e=0){return t==null&&(t=mt(Ht(r))),t instanceof Uint8Array?is(r,t,e):Eu(r,t,e)}function So(r,t=0){return r instanceof Uint8Array?os(r,t):vu(r,t)}var as=new Float32Array([-0]),te=new Uint8Array(as.buffer);function Ao(r,t,e){as[0]=r,t[e]=te[0],t[e+1]=te[1],t[e+2]=te[2],t[e+3]=te[3]}function Io(r,t){return te[0]=r[t],te[1]=r[t+1],te[2]=r[t+2],te[3]=r[t+3],as[0]}var cs=new Float64Array([-0]),ut=new Uint8Array(cs.buffer);function Bo(r,t,e){cs[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function Lo(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],cs[0]}var Au=BigInt(Number.MAX_SAFE_INTEGER),Iu=BigInt(Number.MIN_SAFE_INTEGER),Et=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 he;if(t<Au&&t>Iu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>_o&&(s=0n,++n>_o&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return he;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}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):he}},he=new Et(0,0);he.toBigInt=function(){return 0n};he.zzEncode=he.zzDecode=function(){return this};he.length=function(){return 1};var _o=4294967296n;function To(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 Do(r,t,e){if(e-t<1)return"";let s,i=[],o=0,a;for(;t<e;)a=r[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(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,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function us(r,t,e){let n=e,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function Bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Cr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var fs=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,Bt(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 Bt(this,4);return Cr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Cr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=Io(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=Lo(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 Bt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Do(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(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 Et(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 Bt(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 Bt(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 Bt(this,8);let t=Cr(this.buf,this.pos+=4),e=Cr(this.buf,this.pos+=4);return new Et(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=os(this.buf,this.pos);return this.pos+=Ht(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 ls(r){return new fs(r instanceof Uint8Array?r:r.subarray())}function gt(r,t,e){let n=ls(r);return t.decode(n,void 0,e)}function hs(r){let t=r??8192,e=t>>>1,n,s=t;return function(o){if(o<1||o>e)return mt(o);s+o>t&&(n=mt(t),s=0);let a=n.subarray(s,s+=o);return(s&7)!==0&&(s=(s|7)+1),a}}var de=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function ds(){}var ms=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Bu=hs();function Lu(r){return globalThis.Buffer!=null?mt(r):Bu(r)}var tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(ds,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new de(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new bs((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(Nr,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Et.fromBigInt(t);return this._push(Nr,e.length(),e)}uint64Number(t){return this._push(is,Ht(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=Et.fromBigInt(t).zzEncode();return this._push(Nr,e.length(),e)}sint64Number(t){let e=Et.fromNumber(t).zzEncode();return this._push(Nr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ps,1,t?1:0)}fixed32(t){return this._push(Qe,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Et.fromBigInt(t);return this._push(Qe,4,e.lo)._push(Qe,4,e.hi)}fixed64Number(t){let e=Et.fromNumber(t);return this._push(Qe,4,e.lo)._push(Qe,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(Ao,4,t)}double(t){return this._push(Bo,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ps,1,0):this.uint32(e)._push(Tu,e,t)}string(t){let e=To(t);return e!==0?this.uint32(e)._push(us,e,t):this._push(ps,1,0)}fork(){return this.states=new ms(this),this.head=this.tail=new de(ds,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new de(ds,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=Lu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ps(r,t,e){t[e]=r&255}function _u(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var bs=class extends de{next;constructor(t,e){super(_u,t,e),this.next=void 0}};function Nr(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 Qe(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 Tu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(tr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Du,t,r),this},tr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ru,t,r),this});function Du(r,t,e){t.set(r,e)}function Ru(r,t,e){r.length<40?us(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(F(r),e)}function ys(){return new tr}function wt(r,t){let e=ys();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ke;(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"})(ke||(ke={}));function Kr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function gs(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,o){let a=t(i);o.int32(a)},n=function(i){let o=i.int32();return t(o)};return Kr("enum",ke.VARINT,e,n)}function xt(r,t){return Kr("message",ke.LENGTH_DELIMITED,r,t)}var St=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var ws;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ws||(ws={}));(function(r){r.codec=()=>gs(ws)})(tt||(tt={}));var Rt;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.Type=tt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Rt||(Rt={}));var xs;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.Type=tt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(xs||(xs={}));function Ur(r){if(isNaN(r)||r<=0)throw new z("random bytes length must be a Number bigger than 0");return Gt(r)}var rr={};dt(rr,{MAX_RSA_KEY_SIZE:()=>Es,generateRSAKeyPair:()=>Ko,jwkToJWKKeyPair:()=>Uo,jwkToPkcs1:()=>Nu,jwkToPkix:()=>Is,jwkToRSAPrivateKey:()=>Ts,pkcs1MessageToJwk:()=>Ss,pkcs1MessageToRSAPrivateKey:()=>Bs,pkcs1ToJwk:()=>Cu,pkcs1ToRSAPrivateKey:()=>No,pkixMessageToJwk:()=>As,pkixMessageToRSAPublicKey:()=>_s,pkixToJwk:()=>Ku,pkixToRSAPublicKey:()=>Ls});var Pe=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e,n){return Co(this.jwk,e,t,n)}},er=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=rr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}sign(t,e){return Po(this.jwk,t,e)}};var Es=8192,vs=18,ku=1062,Pu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Cu(r){let t=Ct(r);return Ss(t)}function Ss(r){return{n:H(r[1],"base64url"),e:H(r[2],"base64url"),d:H(r[3],"base64url"),p:H(r[4],"base64url"),q:H(r[5],"base64url"),dp:H(r[6],"base64url"),dq:H(r[7],"base64url"),qi:H(r[8],"base64url"),kty:"RSA"}}function Nu(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 z("JWK was missing components");return Yt([bt(Uint8Array.from([0])),bt(F(r.n,"base64url")),bt(F(r.e,"base64url")),bt(F(r.d,"base64url")),bt(F(r.p,"base64url")),bt(F(r.q,"base64url")),bt(F(r.dp,"base64url")),bt(F(r.dq,"base64url")),bt(F(r.qi,"base64url"))]).subarray()}function Ku(r){let t=Ct(r,{offset:0});return As(t)}function As(r){let t=Ct(r[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function Is(r){if(r.n==null||r.e==null)throw new z("JWK was missing components");return Yt([Pu,Er(Yt([bt(F(r.n,"base64url")),bt(F(r.e,"base64url"))]))]).subarray()}function No(r){let t=Ct(r);return Bs(t)}function Bs(r){let t=Ss(r);return Ts(t)}function Ls(r,t){if(r.byteLength>=ku)throw new ye("Key size is too large");let e=Ct(r,{offset:0});return _s(e,r,t)}function _s(r,t,e){let n=As(r);if(e==null){let s=Be(Rt.encode({Type:tt.RSA,Data:t}));e=_t(vs,s)}return new Pe(n,e)}function Ts(r){if(Oo(r)>Es)throw new z("Key size is too large");let t=Uo(r),e=Be(Rt.encode({Type:tt.RSA,Data:Is(t.publicKey)})),n=_t(vs,e);return new er(t.privateKey,new Pe(t.publicKey,n))}async function Ko(r){if(r>Es)throw new z("Key size is too large");let t=await Mo(r),e=Be(Rt.encode({Type:tt.RSA,Data:Is(t.publicKey)})),n=_t(vs,e);return new er(t.privateKey,new Pe(t.publicKey,n))}function Uo(r){if(r==null)throw new z("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Mo(r,t){let e=await vt.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 Uu(e,t);return{privateKey:n[0],publicKey:n[1]}}async function Po(r,t,e){let n=await vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let s=await vt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function Co(r,t,e,n){let s=await vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await vt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),i}async function Uu(r,t){if(r.privateKey==null||r.publicKey==null)throw new z("Private and public key are required");let e=await Promise.all([vt.get().subtle.exportKey("jwk",r.privateKey),vt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Oo(r){if(r.kty!=="RSA")throw new z("invalid key type");if(r.n==null)throw new z("invalid key modulus");return F(r.n,"base64url").length*8}var Mr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(vr(t),K(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(e.length>n?t.create().update(e).digest():e);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),Ut(s)}update(t){return Ie(this),this.iHash.update(t),this}digestInto(t){Ie(this),K(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=i,t.blockLen=o,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()}},Ds=(r,t,e)=>new Mr(r,t).update(e).digest();Ds.create=(r,t)=>new Mr(r,t);var qo=(r,t)=>(r+(r>=0?t:-t)/Vo)/t;function Mu(r,t,e){let[[n,s],[i,o]]=t,a=qo(o*r,e),c=qo(-s*r,e),f=r-a*n-c*i,l=-a*s-c*o,u=f<Ft,y=l<Ft;u&&(f=-f),y&&(l=-l);let d=Xe(Math.ceil(Vn(e)/2))+Ce;if(f<Ft||f>=d||l<Ft||l>=d)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:u,k1:f,k2neg:y,k2:l}}function ks(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Rs(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Vt(e.lowS,"lowS"),Vt(e.prehash,"prehash"),e.format!==void 0&&ks(e.format),e}var Ps=class extends Error{constructor(t=""){super(t)}},ee={Err:Ps,_tlv:{encode:(r,t)=>{let{Err:e}=ee;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,s=Ye(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let i=n>127?Ye(s.length/2|128):"";return Ye(r)+i+s+t},decode(r,t){let{Err:e}=ee,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 s=t[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&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 f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of f)o=o<<8|l;if(n+=c,o<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+o);if(a.length!==o)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(r){let{Err:t}=ee;if(r<Ft)throw new t("integer: negative integers are not allowed");let e=Ye(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}=ee;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 Le(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=ee,s=K(r,void 0,"signature"),{v:i,l:o}=n.decode(48,s);if(o.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l}=n.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=ee,n=t.encode(2,e.encode(r.r)),s=t.encode(2,e.encode(r.s)),i=n+s;return t.encode(48,i)}},Ft=BigInt(0),Ce=BigInt(1),Vo=BigInt(2),Or=BigInt(3),Ou=BigInt(4);function Ho(r,t={}){let e=_r("weierstrass",r,t),{Fp:n,Fn:s}=e,i=e.CURVE,{h:o,n:a}=i;Jt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=zo(n,s);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(D,m,b){let{x:h,y:v}=m.toAffine(),L=n.toBytes(h);if(Vt(b,"isCompressed"),b){l();let T=!n.isOdd(v);return yt(Fo(T),L)}else return yt(Uint8Array.of(4),L,n.toBytes(v))}function y(D){K(D,void 0,"Point");let{publicKey:m,publicKeyUncompressed:b}=f,h=D.length,v=D[0],L=D.subarray(1);if(h===m&&(v===2||v===3)){let T=n.fromBytes(L);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let R=I(T),_;try{_=n.sqrt(R)}catch(G){let $=G instanceof Error?": "+G.message:"";throw new Error("bad point: is not on curve, sqrt error"+$)}l();let k=n.isOdd(_);return(v&1)===1!==k&&(_=n.neg(_)),{x:T,y:_}}else if(h===b&&v===4){let T=n.BYTES,R=n.fromBytes(L.subarray(0,T)),_=n.fromBytes(L.subarray(T,T*2));if(!S(R,_))throw new Error("bad point: is not on curve");return{x:R,y:_}}else throw new Error(`bad point: got length ${h}, expected compressed=${m} or uncompressed=${b}`)}let d=t.toBytes||u,p=t.fromBytes||y;function I(D){let m=n.sqr(D),b=n.mul(m,D);return n.add(n.add(b,n.mul(D,i.a)),i.b)}function S(D,m){let b=n.sqr(m),h=I(D);return n.eql(b,h)}if(!S(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(i.a,Or),Ou),A=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(g,A)))throw new Error("bad curve params: a or b");function w(D,m,b=!1){if(!n.isValid(m)||b&&n.is0(m))throw new Error(`bad point coordinate ${D}`);return m}function B(D){if(!(D instanceof x))throw new Error("Weierstrass Point expected")}function P(D){if(!c||!c.basises)throw new Error("no endo");return Mu(D,c.basises,s.ORDER)}let U=_e((D,m)=>{let{X:b,Y:h,Z:v}=D;if(n.eql(v,n.ONE))return{x:b,y:h};let L=D.is0();m==null&&(m=L?n.ONE:n.inv(v));let T=n.mul(b,m),R=n.mul(h,m),_=n.mul(v,m);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:T,y:R}}),M=_e(D=>{if(D.is0()){if(t.allowInfinityPoint&&!n.is0(D.Y))return;throw new Error("bad point: ZERO")}let{x:m,y:b}=D.toAffine();if(!n.isValid(m)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!S(m,b))throw new Error("bad point: equation left != right");if(!D.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function E(D,m,b,h,v){return b=new x(n.mul(b.X,D),b.Y,b.Z),m=We(h,m),b=We(v,b),m.add(b)}class x{static BASE=new x(i.Gx,i.Gy,n.ONE);static ZERO=new x(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(m,b,h){this.X=w("x",m),this.Y=w("y",b,!0),this.Z=w("z",h),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){let{x:b,y:h}=m||{};if(!m||!n.isValid(b)||!n.isValid(h))throw new Error("invalid affine point");if(m instanceof x)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(h)?x.ZERO:new x(b,h,n.ONE)}static fromBytes(m){let b=x.fromAffine(p(K(m,void 0,"point")));return b.assertValidity(),b}static fromHex(m){return x.fromBytes(Ot(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,b=!0){return O.createCache(this,m),b||this.multiply(Or),this}assertValidity(){M(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){B(m);let{X:b,Y:h,Z:v}=this,{X:L,Y:T,Z:R}=m,_=n.eql(n.mul(b,R),n.mul(L,v)),k=n.eql(n.mul(h,R),n.mul(T,v));return _&&k}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b}=i,h=n.mul(b,Or),{X:v,Y:L,Z:T}=this,R=n.ZERO,_=n.ZERO,k=n.ZERO,N=n.mul(v,v),G=n.mul(L,L),$=n.mul(T,T),q=n.mul(v,L);return q=n.add(q,q),k=n.mul(v,T),k=n.add(k,k),R=n.mul(m,k),_=n.mul(h,$),_=n.add(R,_),R=n.sub(G,_),_=n.add(G,_),_=n.mul(R,_),R=n.mul(q,R),k=n.mul(h,k),$=n.mul(m,$),q=n.sub(N,$),q=n.mul(m,q),q=n.add(q,k),k=n.add(N,N),N=n.add(k,N),N=n.add(N,$),N=n.mul(N,q),_=n.add(_,N),$=n.mul(L,T),$=n.add($,$),N=n.mul($,q),R=n.sub(R,N),k=n.mul($,G),k=n.add(k,k),k=n.add(k,k),new x(R,_,k)}add(m){B(m);let{X:b,Y:h,Z:v}=this,{X:L,Y:T,Z:R}=m,_=n.ZERO,k=n.ZERO,N=n.ZERO,G=i.a,$=n.mul(i.b,Or),q=n.mul(b,L),X=n.mul(h,T),st=n.mul(v,R),Lt=n.add(b,h),j=n.add(L,T);Lt=n.mul(Lt,j),j=n.add(q,X),Lt=n.sub(Lt,j),j=n.add(b,v);let ot=n.add(L,R);return j=n.mul(j,ot),ot=n.add(q,st),j=n.sub(j,ot),ot=n.add(h,v),_=n.add(T,R),ot=n.mul(ot,_),_=n.add(X,st),ot=n.sub(ot,_),N=n.mul(G,j),_=n.mul($,st),N=n.add(_,N),_=n.sub(X,N),N=n.add(X,N),k=n.mul(_,N),X=n.add(q,q),X=n.add(X,q),st=n.mul(G,st),j=n.mul($,j),X=n.add(X,st),st=n.sub(q,st),st=n.mul(G,st),j=n.add(j,st),q=n.mul(X,j),k=n.add(k,q),q=n.mul(ot,j),_=n.mul(Lt,_),_=n.sub(_,q),q=n.mul(Lt,X),N=n.mul(ot,N),N=n.add(N,q),new x(_,k,N)}subtract(m){return this.add(m.negate())}is0(){return this.equals(x.ZERO)}multiply(m){let{endo:b}=t;if(!s.isValidNot0(m))throw new Error("invalid scalar: out of range");let h,v,L=T=>O.cached(this,T,R=>le(x,R));if(b){let{k1neg:T,k1:R,k2neg:_,k2:k}=P(m),{p:N,f:G}=L(R),{p:$,f:q}=L(k);v=G.add(q),h=E(b.beta,N,$,T,_)}else{let{p:T,f:R}=L(m);h=T,v=R}return le(x,[h,v])[0]}multiplyUnsafe(m){let{endo:b}=t,h=this;if(!s.isValid(m))throw new Error("invalid scalar: out of range");if(m===Ft||h.is0())return x.ZERO;if(m===Ce)return h;if(O.hasCache(this))return this.multiply(m);if(b){let{k1neg:v,k1:L,k2neg:T,k2:R}=P(m),{p1:_,p2:k}=ho(x,h,L,R);return E(b.beta,_,k,v,T)}else return O.unsafe(h,m)}toAffine(m){return U(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return o===Ce?!0:m?m(x,this):O.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return o===Ce?this:m?m(x,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(m=!0){return Vt(m,"isCompressed"),this.assertValidity(),d(x,this,m)}toHex(m=!0){return Mt(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let C=s.BITS,O=new Re(x,t.endo?Math.ceil(C/2):C);return x.BASE.precompute(8),x}function Fo(r){return Uint8Array.of(r?2:3)}function zo(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function qu(r,t={}){let{Fn:e}=r,n=t.randomBytes||Gt,s=Object.assign(zo(r.Fp,e),{seed:$n(e.ORDER)});function i(d){try{let p=e.fromBytes(d);return e.isValidNot0(p)}catch{return!1}}function o(d,p){let{publicKey:I,publicKeyUncompressed:S}=s;try{let g=d.length;return p===!0&&g!==I||p===!1&&g!==S?!1:!!r.fromBytes(d)}catch{return!1}}function a(d=n(s.seed)){return Zn(K(d,s.seed,"seed"),e.ORDER)}function c(d,p=!0){return r.BASE.multiply(e.fromBytes(d)).toBytes(p)}function f(d){let{secretKey:p,publicKey:I,publicKeyUncompressed:S}=s;if(!ie(d)||"_lengths"in e&&e._lengths||p===I)return;let g=K(d,void 0,"key").length;return g===I||g===S}function l(d,p,I=!0){if(f(d)===!0)throw new Error("first arg must be private key");if(f(p)===!1)throw new Error("second arg must be public key");let S=e.fromBytes(d);return r.fromBytes(p).multiply(S).toBytes(I)}let u={isValidSecretKey:i,isValidPublicKey:o,randomSecretKey:a},y=Tr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:y,Point:r,utils:u,lengths:s})}function $o(r,t,e={}){vr(t),Jt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||Gt,s=e.hmac||((b,h)=>Ds(t,b,h)),{Fp:i,Fn:o}=r,{ORDER:a,BITS:c}=o,{keygen:f,getPublicKey:l,getSharedSecret:u,utils:y,lengths:d}=qu(r,e),p={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},I=a*Vo<i.ORDER;function S(b){let h=a>>Ce;return b>h}function g(b,h){if(!o.isValidNot0(h))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return h}function A(){if(I)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(b,h){ks(h);let v=d.signature,L=h==="compact"?v:h==="recovered"?v+1:void 0;return K(b,L)}class B{r;s;recovery;constructor(h,v,L){if(this.r=g("r",h),this.s=g("s",v),L!=null){if(A(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(h,v=p.format){w(h,v);let L;if(v==="der"){let{r:k,s:N}=ee.toSig(K(h));return new B(k,N)}v==="recovered"&&(L=h[0],v="compact",h=h.subarray(1));let T=d.signature/2,R=h.subarray(0,T),_=h.subarray(T,T*2);return new B(o.fromBytes(R),o.fromBytes(_),L)}static fromHex(h,v){return this.fromBytes(Ot(h),v)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new B(this.r,this.s,h)}recoverPublicKey(h){let{r:v,s:L}=this,T=this.assertRecovery(),R=T===2||T===3?v+a:v;if(!i.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let _=i.toBytes(R),k=r.fromBytes(yt(Fo((T&1)===0),_)),N=o.inv(R),G=U(K(h,void 0,"msgHash")),$=o.create(-G*N),q=o.create(L*N),X=r.BASE.multiplyUnsafe($).add(k.multiplyUnsafe(q));if(X.is0())throw new Error("invalid recovery: point at infinify");return X.assertValidity(),X}hasHighS(){return S(this.s)}toBytes(h=p.format){if(ks(h),h==="der")return Ot(ee.hexFromSig(this));let{r:v,s:L}=this,T=o.toBytes(v),R=o.toBytes(L);return h==="recovered"?(A(),yt(Uint8Array.of(this.assertRecovery()),T,R)):yt(T,R)}toHex(h){return Mt(this.toBytes(h))}}let P=e.bits2int||function(h){if(h.length>8192)throw new Error("input is too large");let v=Le(h),L=h.length*8-c;return L>0?v>>BigInt(L):v},U=e.bits2int_modN||function(h){return o.create(P(h))},M=Xe(c);function E(b){return Ge("num < 2^"+c,b,Ft,M),o.toBytes(b)}function x(b,h){return K(b,void 0,"message"),h?K(t(b),void 0,"prehashed message"):b}function C(b,h,v){let{lowS:L,prehash:T,extraEntropy:R}=Rs(v,p);b=x(b,T);let _=U(b),k=o.fromBytes(h);if(!o.isValidNot0(k))throw new Error("invalid private key");let N=[E(k),E(_)];if(R!=null&&R!==!1){let X=R===!0?n(d.secretKey):R;N.push(K(X,void 0,"extraEntropy"))}let G=yt(...N),$=_;function q(X){let st=P(X);if(!o.isValidNot0(st))return;let Lt=o.inv(st),j=r.BASE.multiply(st).toAffine(),ot=o.create(j.x);if(ot===Ft)return;let pr=o.create(Lt*o.create($+ot*k));if(pr===Ft)return;let ti=(j.x===ot?0:2)|Number(j.y&Ce),ei=pr;return L&&S(pr)&&(ei=o.neg(pr),ti^=1),new B(ot,ei,I?void 0:ti)}return{seed:G,k2sig:q}}function O(b,h,v={}){let{seed:L,k2sig:T}=C(b,h,v);return Xi(t.outputLen,o.BYTES,s)(L,T).toBytes(v.format)}function D(b,h,v,L={}){let{lowS:T,prehash:R,format:_}=Rs(L,p);if(v=K(v,void 0,"publicKey"),h=x(h,R),!ie(b)){let k=b instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+k)}w(b,_);try{let k=B.fromBytes(b,_),N=r.fromBytes(v);if(T&&k.hasHighS())return!1;let{r:G,s:$}=k,q=U(h),X=o.inv($),st=o.create(q*X),Lt=o.create(G*X),j=r.BASE.multiplyUnsafe(st).add(N.multiplyUnsafe(Lt));return j.is0()?!1:o.create(j.x)===G}catch{return!1}}function m(b,h,v={}){let{prehash:L}=Rs(v,p);return h=x(h,L),B.fromBytes(b,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:u,utils:y,lengths:d,Point:r,sign:O,verify:D,recoverPublicKey:m,Signature:B,hash:t})}var Ns={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Vu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Zo=BigInt(2);function Hu(r){let t=Ns.p,e=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,l=f*f*r%t,u=Z(l,e,t)*l%t,y=Z(u,e,t)*l%t,d=Z(y,Zo,t)*f%t,p=Z(d,s,t)*d%t,I=Z(p,i,t)*p%t,S=Z(I,a,t)*I%t,g=Z(S,c,t)*S%t,A=Z(g,a,t)*I%t,w=Z(A,e,t)*l%t,B=Z(w,o,t)*p%t,P=Z(B,n,t)*f%t,U=Z(P,Zo,t);if(!Cs.eql(Cs.sqr(U),r))throw new Error("Cannot find square root");return U}var Cs=Te(Ns.p,{sqrt:Hu}),Fu=Ho(Ns,{Fp:Cs,endo:Vu}),Ne=$o(Fu,Be);function Yo(r,t,e,n){let s=se.digest(e instanceof Uint8Array?e:e.subarray());if(kr(s))return s.then(({digest:i})=>(n?.signal?.throwIfAborted(),Ne.verify(t,i,r,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Je(String(i))});try{return n?.signal?.throwIfAborted(),Ne.verify(t,s.digest,r,{prehash:!1,format:"der"})}catch(i){throw new Je(String(i))}}var qr=class{type="secp256k1";raw;_key;constructor(t){this._key=Xo(t),this.raw=Go(this._key)}toMultihash(){return At.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e,n){return Yo(this._key,e,t,n)}};function Ks(r){return new qr(r)}function Go(r){return Ne.Point.fromBytes(r).toBytes()}function Xo(r){try{return Ne.Point.fromBytes(r),r}catch(t){throw new ye(String(t))}}function Us(r,t){let{Type:e,Data:n}=Rt.decode(r),s=n??new Uint8Array;switch(e){case tt.RSA:return Ls(s,t);case tt.Ed25519:return ts(s);case tt.secp256k1:return Ks(s);case tt.ECDSA:return Tn(s);default:throw new re}}function jo(r){let{Type:t,Data:e}=Rt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return ts(n);case tt.secp256k1:return Ks(n);case tt.ECDSA:return Tn(n);default:throw new re}}function Nt(r){return Rt.encode({Type:tt[r.type],Data:r.raw})}var Wo=Symbol.for("nodejs.util.inspect.custom"),zu=114,nr=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()})`}[tn]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(zu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return pt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return pt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Wo](){return`PeerId(${this.toString()})`}},sr=class extends nr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},ir=class extends nr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},or=class extends nr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},$u=2336,Vr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(F(this.url))}[Wo](){return`PeerId(${this.url})`}[tn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1($u,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};function Ms(r){if(r.type==="Ed25519")return new ir({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new or({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new sr({multihash:r.toCID().multihash,publicKey:r});throw new re}function Jo(r){return Ms(r.publicKey)}function ar(r){if(Yu(r))return new sr({multihash:r});if(Zu(r))try{let t=jo(r);if(t.type==="Ed25519")return new ir({multihash:r,publicKey:t});if(t.type==="secp256k1")return new or({multihash:r,publicKey:t})}catch{let e=H(r.digest);return new Vr(new URL(e))}throw new br("Supplied PeerID Multihash is invalid")}function Zu(r){return r.code===At.code}function Yu(r){return r.code===se.code}function pe(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:t(s)}}};return e}function Hr(r){let t=$t(Y.decode(`z${r}`));return ar(t)}var cr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return pe(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return pe(this.map.values(),t=>t.key)}values(){return pe(this.map.values(),t=>t.value)}get size(){return this.map.size}};var ur=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return pe(this.set.entries(),t=>{let e=Hr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Hr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return pe(this.set.values(),t=>Hr(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};var Os=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},qs=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Qo=r=>globalThis.DOMException===void 0?new qs(r):new DOMException(r),ta=r=>{let t=r.reason===void 0?Qo("This operation was aborted."):r.reason;return t instanceof Error?t:Qo(t)};function Vs(r,t){let{milliseconds:e,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout}}=t,o,a,f=new Promise((l,u)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:d}=t;d.aborted&&u(ta(d)),a=()=>{u(ta(d))},d.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(l,u);return}let y=new Os;o=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(d){u(d)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?l():s instanceof Error?u(s):(y.message=s??`Promise timed out after ${e} milliseconds`,u(y))},e),(async()=>{try{l(await r)}catch(d){u(d)}})()}).finally(()=>{f.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return f.clear=()=>{i.clearTimeout.call(void 0,o),o=void 0},f}var Gu=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function Xu(r,t,e){let n,s=new Promise((i,o)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:f,removeListener:l}=Gu(r),u=async(...d)=>{let p=e.multiArgs?d:d[0];if(e.filter)try{if(!await e.filter(p))return}catch(I){n(),o(I);return}c.push(p),e.count===c.length&&(n(),i(c))},y=(...d)=>{n(),o(e.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)l(d,u);for(let d of e.rejectionEvents)a.includes(d)||l(d,y)};for(let d of a)f(d,u);for(let d of e.rejectionEvents)a.includes(d)||f(d,y);e.signal&&e.signal.addEventListener("abort",()=>{y(e.signal.reason)},{once:!0}),e.resolveImmediately&&i(c)});if(s.cancel=n,typeof e.timeout=="number"){let i=Vs(s,{milliseconds:e.timeout});return i.cancel=()=>{n(),i.clear()},i}return s}function ea(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=Xu(r,t,e),s=n.then(i=>i[0]);return s.cancel=n.cancel,s}var me=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function ju(r){return r.reason}async function Hs(r,t,e){if(t==null)return r;let n=e?.translateError??ju;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let s;try{return await Promise.race([r,new Promise((i,o)=>{s=()=>{o(n(t))},t.addEventListener("abort",s)})])}finally{s!=null&&t.removeEventListener("abort",s)}}var Ju=4194304,Fr=class extends Error{static name="UnwrappedError";name="UnwrappedError"},zs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},$s=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Zs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Qu(r){return typeof r?.closeRead=="function"}function tf(r){return typeof r?.close=="function"}function Fs(r){return Qu(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:tf(r)?r.status!=="open":!1}function ef(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function rf(r,t){let e=t?.maxBufferSize??Ju,n=new et,s,i=!1;if(!ef(r))throw new z("Argument should be a Stream or a Multiaddr");let o=l=>{if(n.append(l.data),n.byteLength>e){let u=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${u} > ${e}`))}s?.resolve()};r.addEventListener("message",o);let a=l=>{l.error!=null?s?.reject(l.error):s?.resolve()};r.addEventListener("close",a);let c=()=>{s?.resolve()};r.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(l){if(i===!0)throw new Fr("Stream was unwrapped");if(Fs(r)){if(l?.bytes==null)return null;if(n.byteLength<l.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new me(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let u=l?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=u){s.resolve();break}if(await Hs(s.promise,l?.signal),Fs(r)){if(n.byteLength===0&&l?.bytes==null)return null;break}s=Promise.withResolvers()}let y=l?.bytes??n.byteLength;if(n.byteLength<y){if(Fs(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,y),new me(`Unexpected EOF - stream closed while reading ${n.byteLength}/${y} bytes`);return f.read(l)}let d=n.sublist(0,y);return n.consume(y),d},async write(l,u){if(i===!0)throw new Fr("Stream was unwrapped");r.send(l)||await ea(r,"drain",{signal:u?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,r.removeEventListener("message",o),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return f}function nf(r,t={}){let e=rf(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ht(t.maxDataLength));let n=t?.lengthDecoder??So,s=t?.lengthEncoder??vo;return{async read(o){let a=-1,c=new et;for(;;){let l=await e.read({...o,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new zs("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Zs(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new $s(`Message length too long - ${a} > ${t.maxDataLength}`);let f=await e.read({...o,bytes:a});if(f==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new me(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new me(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(o,a){await e.write(new et(s(o.byteLength),o),a)},async writeV(o,a){let c=new et(...o.flatMap(f=>[s(f.byteLength),f]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function Ys(r,t){let e=nf(r,t),n={read:async(s,i)=>{let o=await e.read(i);return s.decode(o)},write:async(s,i,o)=>{await e.write(i.encode(s),o)},writeV:async(s,i,o)=>{await e.writeV(s.map(a=>i.encode(a)),o)},pb:s=>({read:async i=>n.read(s,i),write:async(i,o)=>n.write(i,s,o),writeV:async(i,o)=>n.writeV(i,s,o),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Xs=ga(na(),1);var js=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},sa=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Ws(r,t){let{milliseconds:e,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=t,a,c,l=new Promise((u,y)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(o?.aborted){y(sa(o));return}if(o&&(c=()=>{y(sa(o))},o.addEventListener("abort",c,{once:!0})),r.then(u,y),e===Number.POSITIVE_INFINITY)return;let d=new js;a=i.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(p){y(p)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?u():s instanceof Error?y(s):(d.message=s??`Promise timed out after ${e} milliseconds`,y(d))},e)}).finally(()=>{l.clear(),c&&o&&o.removeEventListener("abort",c)});return l.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},l}function Js(r,t,e){let n=0,s=r.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;e(r[o],t)<=0?(n=++o,s-=i+1):s=i}return n}var lr=class{#t=[];enqueue(t,e){let{priority:n=0,id:s}=e??{},i={priority:n,id:s,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let o=Js(this.#t,i,(a,c)=>c.priority-a.priority);this.#t.splice(o,0,i)}setPriority(t,e){let n=this.#t.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[s]=this.#t.splice(n,1);this.enqueue(s.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var hr=class extends Xs.default{#t;#o;#a=0;#d;#m=!1;#g=!1;#c;#B=0;#w=0;#u;#f;#i;#s=[];#n=0;#e;#L;#r=0;#b;#l;#k=1n;#y=new Map;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:lr,strict:!1,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#o=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#c=t.interval,this.#i=t.strict,this.#e=new t.queueClass,this.#L=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#q()}#x(t){for(;this.#n<this.#s.length;){let n=this.#s[this.#n];if(n!==void 0&&t-n>=this.#c)this.#n++;else break}(this.#n>100&&this.#n>this.#s.length/2||this.#n===this.#s.length)&&(this.#s=this.#s.slice(this.#n),this.#n=0)}#P(t){this.#i?this.#s.push(t):this.#a++}#C(){this.#i?this.#s.length>this.#n&&this.#s.pop():this.#a>0&&this.#a--}#E(){return this.#s.length-this.#n}get#N(){return this.#o?!0:this.#i?this.#E()<this.#d:this.#a<this.#d}get#K(){return this.#r<this.#b}#U(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#A(),this.emit("next")}#M(){this.#f=void 0,this.#D(),this.#T()}#O(t){if(this.#i){if(this.#x(t),this.#E()>=this.#d){let n=this.#s[this.#n],s=this.#c-(t-n);return this.#v(s),!0}return!1}if(this.#u===void 0){let e=this.#B-t;if(e<0){if(this.#w>0){let n=t-this.#w;if(n<this.#c)return this.#v(this.#c-n),!0}this.#a=this.#t?this.#r:0}else return this.#v(e),!0}return!1}#v(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#M()},t))}#S(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#_(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#A(){if(this.#e.size===0){if(this.#S(),this.emit("empty"),this.#r===0){if(this.#_(),this.#i&&this.#n>0){let e=Date.now();this.#x(e)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let e=Date.now(),n=!this.#O(e);if(this.#N&&this.#K){let s=this.#e.dequeue();this.#o||(this.#P(e),this.#p()),this.emit("active"),s(),n&&this.#T(),t=!0}}return t}#T(){this.#o||this.#u!==void 0||this.#i||(this.#u=setInterval(()=>{this.#D()},this.#c),this.#B=Date.now()+this.#c)}#D(){this.#i||(this.#a===0&&this.#r===0&&this.#u&&this.#S(),this.#a=this.#t?this.#r:0),this.#I(),this.#p()}#I(){for(;this.#A(););}get concurrency(){return this.#b}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#b=t,this.#I()}setPriority(t,e){if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${e}\` (${typeof e})`);this.#e.setPriority(t,e)}async add(t,e={}){return e={timeout:this.timeout,...e,id:e.id??(this.#k++).toString()},new Promise((n,s)=>{let i=Symbol(`task-${e.id}`);this.#e.enqueue(async()=>{this.#r++,this.#y.set(i,{id:e.id,priority:e.priority??0,startTime:Date.now(),timeout:e.timeout});let o;try{try{e.signal?.throwIfAborted()}catch(f){throw this.#V(),this.#y.delete(i),f}this.#w=Date.now();let a=t({signal:e.signal});if(e.timeout&&(a=Ws(Promise.resolve(a),{milliseconds:e.timeout,message:`Task timed out after ${e.timeout}ms (queue has ${this.#r} running, ${this.#e.size} waiting)`})),e.signal){let{signal:f}=e;a=Promise.race([a,new Promise((l,u)=>{o=()=>{u(f.reason)},f.addEventListener("abort",o,{once:!0})})])}let c=await a;n(c),this.emit("completed",c)}catch(a){s(a),this.emit("error",a)}finally{o&&e.signal?.removeEventListener("abort",o),this.#y.delete(i),queueMicrotask(()=>{this.#U()})}},e),this.emit("add"),this.#A()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#l?(this.#l=!1,this.#I(),this):this}pause(){this.#l=!0}clear(){this.#e=new this.#L,this.#S(),this.#R(),this.emit("empty"),this.#r===0&&(this.#_(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#r===0&&this.#e.size===0||await this.#h("idle")}async onPendingZero(){this.#r!==0&&await this.#h("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#h("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#h("rateLimitCleared")}onError(){return new Promise((t,e)=>{let n=s=>{this.off("error",n),e(s)};this.on("error",n)})}async#h(t,e){return new Promise(n=>{let s=()=>{e&&!e()||(this.off(t,s),n())};this.on(t,s)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#r}get isPaused(){return this.#l}#q(){this.#o||(this.on("add",()=>{this.#e.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#o||this.#g||(this.#g=!0,queueMicrotask(()=>{this.#g=!1,this.#R()}))}#V(){this.#o||(this.#C(),this.#p())}#R(){let t=this.#m;if(this.#o||this.#e.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let e;if(this.#i){let s=Date.now();this.#x(s),e=this.#E()}else e=this.#a;let n=e>=this.#d;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#r===this.#b&&this.#e.size>0||this.isRateLimited&&this.#e.size>0}get runningTasks(){return[...this.#y.values()].map(t=>({...t}))}};var $r=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,e){this.entries.set(t,{value:e,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[e,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(e);else break}}has(t){return this.entries.has(t)}get(t){let e=this.entries.get(t);return e!=null&&e.validUntilMs>=Date.now()?e.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var be;(function(r){let t;(function(s){let i;s.codec=()=>(i==null&&(i=xt((o,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),o.subscribe!=null&&(a.uint32(8),a.bool(o.subscribe)),o.topic!=null&&(a.uint32(18),a.string(o.topic)),c.lengthDelimited!==!1&&a.ldelim()},(o,a,c={})=>{let f={},l=a==null?o.len:o.pos+a;for(;o.pos<l;){let u=o.uint32();switch(u>>>3){case 1:{f.subscribe=o.bool();break}case 2:{f.topic=o.string();break}default:{o.skipType(u&7);break}}}return f})),i),s.encode=o=>wt(o,s.codec()),s.decode=(o,a)=>gt(o,s.codec(),a)})(t=r.SubOpts||(r.SubOpts={}));let e;(function(s){let i;s.codec=()=>(i==null&&(i=xt((o,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),o.from!=null&&(a.uint32(10),a.bytes(o.from)),o.data!=null&&(a.uint32(18),a.bytes(o.data)),o.sequenceNumber!=null&&(a.uint32(26),a.bytes(o.sequenceNumber)),o.topic!=null&&(a.uint32(34),a.string(o.topic)),o.signature!=null&&(a.uint32(42),a.bytes(o.signature)),o.key!=null&&(a.uint32(50),a.bytes(o.key)),c.lengthDelimited!==!1&&a.ldelim()},(o,a,c={})=>{let f={},l=a==null?o.len:o.pos+a;for(;o.pos<l;){let u=o.uint32();switch(u>>>3){case 1:{f.from=o.bytes();break}case 2:{f.data=o.bytes();break}case 3:{f.sequenceNumber=o.bytes();break}case 4:{f.topic=o.string();break}case 5:{f.signature=o.bytes();break}case 6:{f.key=o.bytes();break}default:{o.skipType(u&7);break}}}return f})),i),s.encode=o=>wt(o,s.codec()),s.decode=(o,a)=>gt(o,s.codec(),a)})(e=r.Message||(r.Message={}));let n;r.codec=()=>(n==null&&(n=xt((s,i,o={})=>{if(o.lengthDelimited!==!1&&i.fork(),s.subscriptions!=null)for(let a of s.subscriptions)i.uint32(10),r.SubOpts.codec().encode(a,i);if(s.messages!=null)for(let a of s.messages)i.uint32(18),r.Message.codec().encode(a,i);s.control!=null&&(i.uint32(26),Zr.codec().encode(s.control,i)),o.lengthDelimited!==!1&&i.ldelim()},(s,i,o={})=>{let a={subscriptions:[],messages:[]},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let f=s.uint32();switch(f>>>3){case 1:{if(o.limits?.subscriptions!=null&&a.subscriptions.length===o.limits.subscriptions)throw new St('Decode error - map field "subscriptions" had too many elements');a.subscriptions.push(r.SubOpts.codec().decode(s,s.uint32(),{limits:o.limits?.subscriptions$}));break}case 2:{if(o.limits?.messages!=null&&a.messages.length===o.limits.messages)throw new St('Decode error - map field "messages" had too many elements');a.messages.push(r.Message.codec().decode(s,s.uint32(),{limits:o.limits?.messages$}));break}case 3:{a.control=Zr.codec().decode(s,s.uint32(),{limits:o.limits?.control});break}default:{s.skipType(f&7);break}}}return a})),n),r.encode=s=>wt(s,r.codec()),r.decode=(s,i)=>gt(s,r.codec(),i)})(be||(be={}));var Zr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.ihave!=null)for(let i of e.ihave)n.uint32(10),Yr.codec().encode(i,n);if(e.iwant!=null)for(let i of e.iwant)n.uint32(18),Gr.codec().encode(i,n);if(e.graft!=null)for(let i of e.graft)n.uint32(26),Xr.codec().encode(i,n);if(e.prune!=null)for(let i of e.prune)n.uint32(34),jr.codec().encode(i,n);s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={ihave:[],iwant:[],graft:[],prune:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{if(s.limits?.ihave!=null&&i.ihave.length===s.limits.ihave)throw new St('Decode error - map field "ihave" had too many elements');i.ihave.push(Yr.codec().decode(e,e.uint32(),{limits:s.limits?.ihave$}));break}case 2:{if(s.limits?.iwant!=null&&i.iwant.length===s.limits.iwant)throw new St('Decode error - map field "iwant" had too many elements');i.iwant.push(Gr.codec().decode(e,e.uint32(),{limits:s.limits?.iwant$}));break}case 3:{if(s.limits?.graft!=null&&i.graft.length===s.limits.graft)throw new St('Decode error - map field "graft" had too many elements');i.graft.push(Xr.codec().decode(e,e.uint32(),{limits:s.limits?.graft$}));break}case 4:{if(s.limits?.prune!=null&&i.prune.length===s.limits.prune)throw new St('Decode error - map field "prune" had too many elements');i.prune.push(jr.codec().decode(e,e.uint32(),{limits:s.limits?.prune$}));break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Zr||(Zr={}));var Yr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.messageIDs!=null)for(let i of e.messageIDs)n.uint32(18),n.bytes(i);s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={messageIDs:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.topic=e.string();break}case 2:{if(s.limits?.messageIDs!=null&&i.messageIDs.length===s.limits.messageIDs)throw new St('Decode error - map field "messageIDs" had too many elements');i.messageIDs.push(e.bytes());break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Yr||(Yr={}));var Gr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.messageIDs!=null)for(let i of e.messageIDs)n.uint32(10),n.bytes(i);s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={messageIDs:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{if(s.limits?.messageIDs!=null&&i.messageIDs.length===s.limits.messageIDs)throw new St('Decode error - map field "messageIDs" had too many elements');i.messageIDs.push(e.bytes());break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Gr||(Gr={}));var Xr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.topic=e.string();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Xr||(Xr={}));var jr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.peers!=null)for(let i of e.peers)n.uint32(18),Wr.codec().encode(i,n);e.backoff!=null&&(n.uint32(24),n.uint64(e.backoff)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={peers:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.topic=e.string();break}case 2:{if(s.limits?.peers!=null&&i.peers.length===s.limits.peers)throw new St('Decode error - map field "peers" had too many elements');i.peers.push(Wr.codec().decode(e,e.uint32(),{limits:s.limits?.peers$}));break}case 3:{i.backoff=e.uint64();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(jr||(jr={}));var Wr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.peerID!=null&&(n.uint32(10),n.bytes(e.peerID)),e.signedPeerRecord!=null&&(n.uint32(18),n.bytes(e.signedPeerRecord)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.peerID=e.bytes();break}case 2:{i.signedPeerRecord=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Wr||(Wr={}));var Jr=class extends ge{peerId;shutDownController;inboundPb;outboundPb;constructor(t){super(),this.peerId=t,this.shutDownController=new AbortController}attachInboundStream(t,e){this.inboundPb=Ys(t,e).pb(be),Promise.resolve().then(async()=>{for(;;){if(this.inboundPb==null)return;let n=await this.inboundPb.read({signal:this.shutDownController.signal});this.safeDispatchEvent("message",{detail:n})}}).catch(n=>{this.inboundPb?.unwrap().unwrap().abort(n)})}attachOutboundStream(t,e){this.outboundPb=Ys(t,e).pb(be)}write(t){this.outboundPb!=null&&this.outboundPb.write(t,{signal:this.shutDownController.signal}).catch(e=>{this.outboundPb?.unwrap().unwrap().abort(e)})}close(){this.shutDownController.abort(),Promise.all([this.inboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)}),this.outboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)})]).finally(()=>{this.safeDispatchEvent("close")})}};function ia(){return BigInt(`0x${H(Ur(8),"base16")}`)}var oa=(r,t)=>{let e=F(t.toString(16).padStart(16,"0"),"base16"),n=Nt(r),s=new Uint8Array(n.byteLength+e.length);return s.set(n,0),s.set(e,n.byteLength),s},aa=r=>se.encode(r);var af=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=ar($t(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return Ms(Us(e)).equals(t)}return!1},ca=async r=>{if(r.from==null)throw new J("RPC message was missing from");if(!await af(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=ar($t(r.from)),e=r.key??t.publicKey;if(e==null)throw new J("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:uf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?Us(e):e}},dr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:cf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Nt(r.key):void 0}:{data:r.data,topic:r.topic},cf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},uf=r=>BigInt(`0x${H(r,"base16")}`);var ua=F("libp2p-pubsub:");async function fa(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Jo(r)},s=ne([ua,e(dr(n)).subarray()]);return n.signature=await r.sign(s),n.key=r.publicKey,n}async function la(r,t){if(r.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(r.signature==null)throw new Error("Message must contain a signature to be verified");if(r.from==null)throw new Error("Message must contain a from property to be verified");let e=ne([ua,t({...dr(r),signature:void 0,key:void 0}).subarray()]);return ff(r).verify(e,r.signature)}function ff(r){if(r.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(r.from==null)throw new Error("Could not get the public key from the originator id");if(r.key!=null)return r.key;if(r.from.publicKey!=null)return r.from.publicKey;throw new Error("Could not get the public key from the originator id")}var Qr=class extends ge{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocol=e.protocol??Qs,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new cr,this.globalSignaturePolicy=e.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=e.canRelayMessage??!0,this.emitSelf=e.emitSelf??!1,this.topicValidators=new Map,this.queue=new hr({concurrency:e.messageProcessingConcurrency??10}),this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.seenCache=new $r({validityMs:e?.seenTTL??3e4}),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[Ue]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[ni]=["@libp2p/pubsub"];[si]=["@libp2p/identify"];async start(){this.started||(this.log("starting"),await this.components.registrar.handle(this.protocol,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this._registrarTopologyId=await this.components.registrar.register(this.protocol,{onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected}),this.log("started"),this.started=!0)}async stop(){if(!this.started)return;let t=this.components.registrar;this._registrarTopologyId!=null&&t.unregister(this._registrarTopologyId),await t.unhandle(this.protocol),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t,e){this.addPeer(e.remotePeer,t).attachInboundStream(t)}async _onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(i=>i.direction==="outbound"&&i.protocol===this.protocol)){this.log("outbound pubsub stream already present on connection from %p",t);return}let n=await e.newStream(this.protocol);this.addPeer(t,n).attachOutboundStream(n),this.send(t,{subscriptions:Array.from(this.subscriptions).map(i=>i.toString()),subscribe:!0})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let s=new Jr(t);return this.peers.set(t,s),s.addEventListener("message",i=>{let o=i.detail,a=[];for(let c of o.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(s,{subscriptions:(o.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}),s.addEventListener("close",()=>this._removePeer(t),{once:!0}),s}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t)}}async processRpc(t,e){this.log("rpc from %p",t.peerId);let{subscriptions:n,messages:s}=e;return n!=null&&n.length>0&&(this.log("subscription update from %p",t.peerId),n.forEach(i=>{this.processRpcSubOpt(t.peerId,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:t.peerId,subscriptions:n.map(({topic:i,subscribe:o})=>({topic:`${i??""}`,subscribe:!!o}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t.peerId),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let o=await ca(i);await this.processMessage(t.peerId,o)}catch(o){this.log.error("failed to queue messages from %p - %e",t.peerId,o)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let s=this.topics.get(n);s==null&&(s=new ur,this.topics.set(n,s)),e.subscribe===!0?s.add(t):s.delete(t)}async processMessage(t,e){if(this.components.peerId.equals(t)&&!this.emitSelf)return;let n=await this.getMsgId(e),s=H(n,"base64");if(!this.seenCache.has(s)){this.seenCache.put(s,!0);try{await this.validate(t,e)}catch(i){this.log("Message is invalid, dropping it. %O",i);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new J("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new J("Need key when signature policy is StrictSign but it was missing");return oa(t.key,t.sequenceNumber);case"StrictNoSign":return aa(t.data);default:throw new J("Cannot get message id: unhandled signature policy")}}encodeMessage(t){return be.Message.encode(t)}send(t,e){let{messages:n,subscriptions:s,subscribe:i}=e;this.sendRpc(t,{subscriptions:(s??[]).map(o=>({topic:o,subscribe:!!i})),messages:(n??[]).map(dr)})}sendRpc(t,e){let n=this.peers.get(t);if(n==null){this.log.error("cannot send RPC to %p as there are no streams to it available",t);return}n.write(e)}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new J('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new J("StrictNoSigning: signature should not be present");if(e.key!=null)throw new J("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new J("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new J("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new J("StrictSigning: Signing required and no sequenceNumber was present");if(!await la(e,this.encodeMessage.bind(this)))throw new J("StrictSigning: Invalid message signature");break;default:throw new J("Cannot validate message: unhandled signature policy")}let s=this.topicValidators.get(e.topic);if(s!=null){let i=await s(t,e);if(i===Ke.Reject||i===Ke.Ignore)throw new J("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return fa(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new J("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new yr("not started yet");if(t==null)throw new z("Topic is required");let e=this.topics.get(t.toString());return e==null?[]:Array.from(e.values())}async publish(t,e){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:e??new Uint8Array(0),sequenceNumber:ia()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let s=await this.buildMessage(n),i=!1;this.emitSelf&&this.subscriptions.has(t)&&(i=!0,super.dispatchEvent(new CustomEvent("message",{detail:s})));let o=await this.publishMessage(this.components.peerId,s);return i&&(o.recipients=[...o.recipients,this.components.peerId]),o}async publishMessage(t,e){let n=this.getSubscribers(e.topic),s=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",e.topic),{recipients:s}):(n.forEach(i=>{if(this.components.peerId.equals(i)){this.log("not sending message on topic %s to myself",e.topic);return}if(i.equals(t)){this.log("not sending message on topic %s to sender %p",e.topic,i);return}this.log("publish msgs on topics %s %p",e.topic,i),s.push(i),this.send(i,{messages:[e]})}),{recipients:s})}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(!this.subscriptions.has(t)){this.log("subscribe to topic: %s",t),this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");if(this.subscriptions.has(t)){this.log("unsubscribe from %s",t),this.subscriptions.delete(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};var Qs="/floodsub/1.0.0",lf="StrictSign",hf="StrictNoSign",Ke;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ke||(Ke={}));function df(r){return!!r?.[Ue]}function pf(r={}){return t=>new Qr(t,r)}return wa(mf);})();
2
+ "use strict";var Libp2PFloodsub=(()=>{var aa=Object.create;var br=Object.defineProperty;var ca=Object.getOwnPropertyDescriptor;var ua=Object.getOwnPropertyNames;var fa=Object.getPrototypeOf,la=Object.prototype.hasOwnProperty;var ha=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),dt=(r,t)=>{for(var e in t)br(r,e,{get:t[e],enumerable:!0})},Qs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ua(t))!la.call(r,s)&&s!==e&&br(r,s,{get:()=>t[s],enumerable:!(n=ca(t,s))||n.enumerable});return r};var da=(r,t,e)=>(e=r!=null?aa(fa(r)):{},Qs(t||!r||!r.__esModule?br(e,"default",{value:r,enumerable:!0}):e,r)),pa=r=>Qs(br({},"__esModule",{value:!0}),r);var Qo=ha((pm,Gs)=>{"use strict";var Qu=Object.prototype.hasOwnProperty,ht="~";function lr(){}Object.create&&(lr.prototype=Object.create(null),new lr().__proto__||(ht=!1));function tf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Jo(r,t,e,n,s){if(typeof e!="function")throw new TypeError("The listener must be a function");var i=new tf(e,n||r,s),o=ht?ht+t:t;return r._events[o]?r._events[o].fn?r._events[o]=[r._events[o],i]:r._events[o].push(i):(r._events[o]=i,r._eventsCount++),r}function $r(r,t){--r._eventsCount===0?r._events=new lr:delete r._events[t]}function ft(){this._events=new lr,this._eventsCount=0}ft.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Qu.call(e,n)&&t.push(ht?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};ft.prototype.listeners=function(t){var e=ht?ht+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,i=n.length,o=new Array(i);s<i;s++)o[s]=n[s].fn;return o};ft.prototype.listenerCount=function(t){var e=ht?ht+t:t,n=this._events[e];return n?n.fn?1:n.length:0};ft.prototype.emit=function(t,e,n,s,i,o){var a=ht?ht+t:t;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,f;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,s),!0;case 5:return c.fn.call(c.context,e,n,s,i),!0;case 6:return c.fn.call(c.context,e,n,s,i,o),!0}for(f=1,l=new Array(u-1);f<u;f++)l[f-1]=arguments[f];c.fn.apply(c.context,l)}else{var y=c.length,b;for(f=0;f<y;f++)switch(c[f].once&&this.removeListener(t,c[f].fn,void 0,!0),u){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,e);break;case 3:c[f].fn.call(c[f].context,e,n);break;case 4:c[f].fn.call(c[f].context,e,n,s);break;default:if(!l)for(b=1,l=new Array(u-1);b<u;b++)l[b-1]=arguments[b];c[f].fn.apply(c[f].context,l)}}return!0};ft.prototype.on=function(t,e,n){return Jo(this,t,e,n,!1)};ft.prototype.once=function(t,e,n){return Jo(this,t,e,n,!0)};ft.prototype.removeListener=function(t,e,n,s){var i=ht?ht+t:t;if(!this._events[i])return this;if(!e)return $r(this,i),this;var o=this._events[i];if(o.fn)o.fn===e&&(!s||o.once)&&(!n||o.context===n)&&$r(this,i);else{for(var a=0,c=[],u=o.length;a<u;a++)(o[a].fn!==e||s&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[i]=c.length===1?c[0]:c:$r(this,i)}return this};ft.prototype.removeAllListeners=function(t){var e;return t?(e=ht?ht+t:t,this._events[e]&&$r(this,e)):(this._events=new lr,this._eventsCount=0),this};ft.prototype.off=ft.prototype.removeListener;ft.prototype.addListener=ft.prototype.on;ft.prefixed=ht;ft.EventEmitter=ft;typeof Gs<"u"&&(Gs.exports=ft)});var ff={};dt(ff,{StrictNoSign:()=>af,StrictSign:()=>of,TopicValidatorResult:()=>Ke,floodsub:()=>uf,isPubSub:()=>cf,protocol:()=>Xs,pubSubSymbol:()=>Ue});var Ue=Symbol.for("@libp2p/pubsub");var z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ye=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var yr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var J=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var gr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var re=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var en=Symbol.for("@libp2p/peer-id");var ge=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let s=this.#t.get(t);s!=null&&(s=s.filter(({callback:i})=>i!==e),this.#t.set(t,s))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:s})=>!s),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var ti=Symbol.for("@libp2p/service-capabilities"),ei=Symbol.for("@libp2p/service-dependencies");var an={};dt(an,{base58btc:()=>G,base58flickr:()=>Ea});var Vf=new Uint8Array(0);function ri(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 kt(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 ni(r){return new TextEncoder().encode(r)}function si(r){return new TextDecoder().decode(r)}function ma(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 s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var I=0,S=0,g=0,A=d.length;g!==A&&d[g]===0;)g++,I++;for(var w=(A-g)*l+1>>>0,B=new Uint8Array(w);g!==A;){for(var C=d[g],U=0,M=w-1;(C!==0||U<S)&&M!==-1;M--,U++)C+=256*B[M]>>>0,B[M]=C%a>>>0,C=C/a>>>0;if(C!==0)throw new Error("Non-zero carry");S=U,g++}for(var E=w-S;E!==w&&B[E]===0;)E++;for(var x=c.repeat(I);E<w;++E)x+=r.charAt(B[E]);return x}function y(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var I=0;if(d[I]!==" "){for(var S=0,g=0;d[I]===c;)S++,I++;for(var A=(d.length-I)*u+1>>>0,w=new Uint8Array(A);d[I];){var B=e[d.charCodeAt(I)];if(B===255)return;for(var C=0,U=A-1;(B!==0||C<g)&&U!==-1;U--,C++)B+=a*w[U]>>>0,w[U]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");g=C,I++}if(d[I]!==" "){for(var M=A-g;M!==A&&w[M]===0;)M++;for(var E=new Uint8Array(S+(A-M)),x=S;M!==A;)E[x++]=w[M++];return E}}}function b(d){var I=y(d);if(I)return I;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:y,decode:b}}var ba=ma,ya=ba,oi=ya;var rn=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")}},nn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let s=e.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 ai(this,t)}},sn=class{decoders;constructor(t){this.decoders=t}or(t){return ai(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 ai(r,t){return new sn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var on=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new rn(t,e,n),this.decoder=new nn(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function we({name:r,prefix:t,encode:e,decode:n}){return new on(r,t,e,n)}function zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=oi(e,r);return we({prefix:t,name:r,encode:n,decode:i=>kt(s(i))})}function ga(r,t,e,n){let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),o=0,a=0,c=0;for(let u=0;u<s;++u){let l=t[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,o+=e,o>=8&&(o-=8,i[c++]=255&a>>o)}if(o>=e||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function wa(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>e;)o-=e,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<e-o]),n)for(;(i.length*e&7)!==0;)i+="=";return i}function xa(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function W({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let s=xa(n);return we({prefix:t,name:r,encode(i){return wa(i,n,e)},decode(i){return ga(i,s,e,r)}})}var G=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ea=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var cn={};dt(cn,{base32:()=>xe,base32hex:()=>Ia,base32hexpad:()=>La,base32hexpadupper:()=>_a,base32hexupper:()=>Ba,base32pad:()=>Sa,base32padupper:()=>Aa,base32upper:()=>va,base32z:()=>Da});var xe=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),va=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Sa=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Aa=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ia=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ba=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),La=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),_a=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Da=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var un={};dt(un,{base36:()=>Me,base36upper:()=>Ta});var Me=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ta=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ra=fi,ci=128,ka=127,Ca=~ka,Pa=Math.pow(2,31);function fi(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Pa;)t[e++]=r&255|ci,r/=128;for(;r&Ca;)t[e++]=r&255|ci,r>>>=7;return t[e]=r|0,fi.bytes=e-n+1,t}var Na=fn,Ka=128,ui=127;function fn(r,n){var e=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw fn.bytes=0,new RangeError("Could not decode varint");o=r[i++],e+=s<28?(o&ui)<<s:(o&ui)*Math.pow(2,s),s+=7}while(o>=Ka);return fn.bytes=i-n,e}var Ua=Math.pow(2,7),Ma=Math.pow(2,14),Oa=Math.pow(2,21),qa=Math.pow(2,28),Va=Math.pow(2,35),Ha=Math.pow(2,42),Fa=Math.pow(2,49),za=Math.pow(2,56),$a=Math.pow(2,63),Za=function(r){return r<Ua?1:r<Ma?2:r<Oa?3:r<qa?4:r<Va?5:r<Ha?6:r<Fa?7:r<za?8:r<$a?9:10},Ga={encode:Ra,decode:Na,encodingLength:Za},Ya=Ga,Oe=Ya;function qe(r,t=0){return[Oe.decode(r,t),Oe.decode.bytes]}function Ee(r,t,e=0){return Oe.encode(r,t,e),t}function ve(r){return Oe.encodingLength(r)}function _t(r,t){let e=t.byteLength,n=ve(r),s=n+ve(e),i=new Uint8Array(s+e);return Ee(r,i,0),Ee(e,i,n),i.set(t,s),new Se(r,e,t,i)}function $t(r){let t=kt(r),[e,n]=qe(t),[s,i]=qe(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new Se(e,s,o,t)}function li(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ri(r.bytes,e.bytes)}}var Se=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function hi(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Xa(e,ln(r),t??G.encoder);default:return Wa(e,ln(r),t??xe.encoder)}}var di=new WeakMap;function ln(r){let t=di.get(r);if(t==null){let e=new Map;return di.set(r,e),e}return t}var at=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}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!==Ve)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ja)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=_t(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&&li(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 e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:s,multihash:i,bytes:o}=e;return new r(n,s,i,o??pi(n,s,i.bytes))}else if(e[Qa]===!0){let{version:n,multihash:s,code:i}=e,o=$t(s);return r.create(n,i,o)}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!==Ve)throw new Error(`Version 0 CID must use dag-pb (code: ${Ve}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=pi(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ve,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,s=kt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=s.subarray(e.multihashSize-e.digestSize),o=new Se(e.multihashCode,e.digestSize,i,s);return[e.version===0?r.createV0(o):r.createV1(e.codec,o),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,y]=qe(t.subarray(e));return e+=y,f},s=n(),i=Ve;if(s===18?(s=0,e=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=e,a=n(),c=n(),u=e+c,l=u-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,s]=ja(t,e),i=r.decode(s);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ln(i).set(n,t),i}};function ja(r,t){switch(r[0]){case"Q":{let e=t??G;return[G.prefix,e.decode(`${G.prefix}${r}`)]}case G.prefix:{let e=t??G;return[G.prefix,e.decode(r)]}case xe.prefix:{let e=t??xe;return[xe.prefix,e.decode(r)]}case Me.prefix:{let e=t??Me;return[Me.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 Xa(r,t,e){let{prefix:n}=e;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return s}function Wa(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let i=e.encode(r);return t.set(n,i),i}else return s}var Ve=112,Ja=18;function pi(r,t,e){let n=ve(r),s=n+ve(t),i=new Uint8Array(s+e.byteLength);return Ee(r,i,0),Ee(t,i,n),i.set(e,s),i}var Qa=Symbol.for("@ipld/js-cid/CID");var hn={};dt(hn,{identity:()=>At});var mi=0,tc="identity",bi=kt;function ec(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return _t(mi,bi(r))}var At={code:mi,name:tc,encode:bi,digest:ec};function pt(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 Ct(r=0){return new Uint8Array(r)}function mt(r=0){return new Uint8Array(r)}function ne(r,t){t==null&&(t=r.reduce((s,i)=>s+i.length,0));let e=mt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}var gi=Symbol.for("@achingbrain/uint8arraylist");function yi(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function xr(r){return!!r?.[gi]}var et=class r{bufs;length;[gi]=!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(xr(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(xr(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=yi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=yi(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(xr(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:s}=this._subList(t,e);return ne(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:ne(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),i=new r;return i.length=s,i.bufs=[...n],i}_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=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(o);break}let f=t-a;n.push(o.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(l){if(e===c){n.push(o);break}n.push(o.subarray(0,e-a));break}n.push(o)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!xr(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 s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let f=0;f<i;f++)o[f]=-1;for(let f=0;f<s;f++)o[n[f]]=f;let a=o,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=c;f+=l){l=0;for(let y=u;y>=0;y--){let b=this.get(f+y);if(n[y]!==b){l=Math.max(1,y-a[b]);break}}if(l===0)return f}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=mt(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 s=Ct(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,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 s=Ct(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,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 s=Ct(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,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=mt(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 s=Ct(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,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 s=Ct(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,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 s=Ct(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,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 s=Ct(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,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 s=Ct(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,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(!pt(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((s,i)=>s+i.byteLength,0)),n.length=e,n}};var dn={};dt(dn,{base10:()=>rc});var rc=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var pn={};dt(pn,{base16:()=>nc,base16upper:()=>sc});var nc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),sc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var mn={};dt(mn,{base2:()=>ic});var ic=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var bn={};dt(bn,{base256emoji:()=>fc});var wi=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}"),oc=wi.reduce((r,t,e)=>(r[e]=t,r),[]),ac=wi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function cc(r){return r.reduce((t,e)=>(t+=oc[e],t),"")}function uc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=ac[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var fc=we({prefix:"\u{1F680}",name:"base256emoji",encode:cc,decode:uc});var yn={};dt(yn,{base64:()=>lc,base64pad:()=>hc,base64url:()=>dc,base64urlpad:()=>pc});var lc=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),hc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),dc=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pc=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var gn={};dt(gn,{base8:()=>mc});var mc=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wn={};dt(wn,{identity:()=>bc});var bc=we({prefix:"\0",name:"identity",encode:r=>si(r),decode:r=>ni(r)});var Al=new TextEncoder,Il=new TextDecoder;var vn={};dt(vn,{sha256:()=>se,sha512:()=>xc});var wc=20;function En({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:s}){return new xn(r,t,e,n,s)}var xn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,s,i){this.name=t,this.code=e,this.encode=n,this.minDigestLength=s??wc,this.maxDigestLength=i}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?xi(n,this.code,e?.truncate):n.then(s=>xi(s,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function xi(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return _t(t,r)}function vi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var se=En({name:"sha2-256",code:18,encode:vi("SHA-256")}),xc=En({name:"sha2-512",code:19,encode:vi("SHA-512")});var Sn={...wn,...mn,...gn,...dn,...pn,...cn,...un,...an,...yn,...bn},Ul={...vn,...hn};function Ai(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Si=Ai("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),An=Ai("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=mt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Ec={utf8:Si,"utf-8":Si,hex:Sn.base16,latin1:An,ascii:An,binary:An,...Sn},Er=Ec;function F(r,t="utf8"){let e=Er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function H(r,t="utf8"){let e=Er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var vc=parseInt("11111",2),In=parseInt("10000000",2),Sc=parseInt("01111111",2),Ii={0:He,1:He,2:Ac,3:Lc,4:_c,5:Bc,6:Ic,16:He,22:He,48:He};function Pt(r,t={offset:0}){let e=r[t.offset]&vc;if(t.offset++,Ii[e]!=null)return Ii[e](r,t);throw new Error("No decoder for tag "+e)}function Fe(r,t){let e=0;if((r[t.offset]&In)===In){let n=r[t.offset]&Sc,s="0x";t.offset++;for(let i=0;i<n;i++,t.offset++)s+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(s,16)}else e=r[t.offset],t.offset++;return e}function He(r,t){Fe(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Pt(r,t);if(n===null)break;e.push(n)}return e}function Ac(r,t){let e=Fe(r,t),n=t.offset,s=t.offset+e,i=[];for(let o=n;o<s;o++)o===n&&r[o]===0||i.push(r[o]);return t.offset+=e,Uint8Array.from(i)}function Ic(r,t){let e=Fe(r,t),n=t.offset+e,s=r[t.offset];t.offset++;let i=0,o=0;s<40?(i=0,o=s):s<80?(i=1,o=s-40):(i=2,o=s-80);let a=`${i}.${o}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let f=0;f<c.length;f++)l+=c[f]<<f*7;a+=`.${l}`,c=[]}}return a}function Bc(r,t){return t.offset++,null}function Lc(r,t){let e=Fe(r,t),n=r[t.offset];t.offset++;let s=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 s}function _c(r,t){let e=Fe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Dc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new et;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Bn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Dc(r.byteLength);return new et(Uint8Array.from([t.byteLength|In]),t)}function bt(r){let t=new et,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new et(Uint8Array.from([2]),Bn(t),t)}function vr(r){let t=Uint8Array.from([0]),e=new et(t,r);return new et(Uint8Array.from([3]),Bn(e),e)}function Gt(r,t=48){let e=new et;for(let n of r)e.append(n);return new et(Uint8Array.from([t]),Bn(e),e)}async function Bi(r,t,e,n){let s=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,t,e.subarray());return n?.signal?.throwIfAborted(),i}var Tc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Rc=Uint8Array.from([6,5,43,129,4,0,34]),kc=Uint8Array.from([6,5,43,129,4,0,35]),Cc={ext:!0,kty:"EC",crv:"P-256"},Pc={ext:!0,kty:"EC",crv:"P-384"},Nc={ext:!0,kty:"EC",crv:"P-521"},Ln=32,_n=48,Dn=66;function Tn(r){let t=Pt(r);return Li(t)}function Li(r){let t=r[1][1][0],e=1,n,s;if(t.byteLength===Ln*2+1)return n=H(t.subarray(e,e+Ln),"base64url"),s=H(t.subarray(e+Ln),"base64url"),new Ae({...Cc,key_ops:["verify"],x:n,y:s});if(t.byteLength===_n*2+1)return n=H(t.subarray(e,e+_n),"base64url"),s=H(t.subarray(e+_n),"base64url"),new Ae({...Pc,key_ops:["verify"],x:n,y:s});if(t.byteLength===Dn*2+1)return n=H(t.subarray(e,e+Dn),"base64url"),s=H(t.subarray(e+Dn),"base64url"),new Ae({...Nc,key_ops:["verify"],x:n,y:s});throw new z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function _i(r){return Gt([bt(Uint8Array.from([1])),Gt([Kc(r.crv)],160),Gt([vr(new et(Uint8Array.from([4]),F(r.x??"","base64url"),F(r.y??"","base64url")))],161)]).subarray()}function Kc(r){if(r==="P-256")return Tc;if(r==="P-384")return Rc;if(r==="P-521")return kc;throw new z(`Invalid curve ${r}`)}var Ae=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=_i(this.jwk)),this._raw}toMultihash(){return At.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}async verify(t,e,n){return Bi(this.jwk,e,t,n)}};function ie(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Dt(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function K(r,t,e=""){let n=ie(r),s=r?.length,i=t!==void 0;if(!n||i&&s!==t){let o=e&&`"${e}" `,a=i?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof r}`;throw new Error(o+"expected Uint8Array"+a+", got "+c)}return r}function Sr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Dt(r.outputLen),Dt(r.blockLen)}function Ie(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 Ti(r,t){K(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function Ut(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Ar(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function It(r,t){return r<<32-t|r>>>t}var Ri=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Uc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Mt(r){if(K(r),Ri)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Uc[r[e]];return t}var Kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Di(r){if(r>=Kt._0&&r<=Kt._9)return r-Kt._0;if(r>=Kt.A&&r<=Kt.F)return r-(Kt.A-10);if(r>=Kt.a&&r<=Kt.f)return r-(Kt.a-10)}function Ot(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Ri)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 s=0,i=0;s<e;s++,i+=2){let o=Di(r.charCodeAt(i)),a=Di(r.charCodeAt(i+1));if(o===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function yt(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];K(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let i=r[n];e.set(i,s),s+=i.length}return e}function Rn(r,t={}){let e=(s,i)=>r(i).update(s).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=s=>r(s),Object.assign(e,t),Object.freeze(e)}function Yt(r=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(r))}var kn=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function ki(r,t,e){return r&t^~r&e}function Ci(r,t,e){return r&t^r&e^t&e}var ze=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,s){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Ar(this.buffer)}update(t){Ie(this),K(t);let{view:e,buffer:n,blockLen:s}=this,i=t.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=Ar(t);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ie(this),Ti(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;e[o++]=128,Ut(this.buffer.subarray(o)),this.padOffset>s-o&&(this.process(n,0),o=0);for(let f=o;f<s;f++)e[f]=0;n.setBigUint64(s-8,BigInt(this.length*8),i),this.process(n,0);let a=Ar(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return t.destroyed=o,t.finished=i,t.length=s,t.pos=a,s%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},qt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var it=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ir=BigInt(4294967295),Pi=BigInt(32);function Mc(r,t=!1){return t?{h:Number(r&Ir),l:Number(r>>Pi&Ir)}:{h:Number(r>>Pi&Ir)|0,l:Number(r&Ir)|0}}function Ni(r,t=!1){let e=r.length,n=new Uint32Array(e),s=new Uint32Array(e);for(let i=0;i<e;i++){let{h:o,l:a}=Mc(r[i],t);[n[i],s[i]]=[o,a]}return[n,s]}var Cn=(r,t,e)=>r>>>e,Pn=(r,t,e)=>r<<32-e|t>>>e,oe=(r,t,e)=>r>>>e|t<<32-e,ae=(r,t,e)=>r<<32-e|t>>>e,$e=(r,t,e)=>r<<64-e|t>>>e-32,Ze=(r,t,e)=>r>>>e-32|t<<64-e;function Tt(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var Ki=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ui=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Mi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Oi=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,qi=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),Vi=(r,t,e,n,s,i)=>t+e+n+s+i+(r/2**32|0)|0;var qc=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]),jt=new Uint32Array(64),Nn=class extends ze{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[t,e,n,s,i,o,a,c]}set(t,e,n,s,i,o,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)jt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let y=jt[f-15],b=jt[f-2],d=It(y,7)^It(y,18)^y>>>3,I=It(b,17)^It(b,19)^b>>>10;jt[f]=I+jt[f-7]+d+jt[f-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let y=It(a,6)^It(a,11)^It(a,25),b=l+y+ki(a,c,u)+qc[f]+jt[f]|0,I=(It(n,2)^It(n,13)^It(n,22))+Ci(n,s,i)|0;l=u,u=c,c=a,a=o+b|0,o=i,i=s,s=n,n=b+I|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,s,i,o,a,c,u,l)}roundClean(){Ut(jt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}},Kn=class extends Nn{A=qt[0]|0;B=qt[1]|0;C=qt[2]|0;D=qt[3]|0;E=qt[4]|0;F=qt[5]|0;G=qt[6]|0;H=qt[7]|0;constructor(){super(32)}};var Hi=Ni(["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))),Vc=Hi[0],Hc=Hi[1],Xt=new Uint32Array(80),Wt=new Uint32Array(80),Un=class extends ze{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:y,Gh:b,Gl:d,Hh:I,Hl:S}=this;return[t,e,n,s,i,o,a,c,u,l,f,y,b,d,I,S]}set(t,e,n,s,i,o,a,c,u,l,f,y,b,d,I,S){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=y|0,this.Gh=b|0,this.Gl=d|0,this.Hh=I|0,this.Hl=S|0}process(t,e){for(let w=0;w<16;w++,e+=4)Xt[w]=t.getUint32(e),Wt[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let B=Xt[w-15]|0,C=Wt[w-15]|0,U=oe(B,C,1)^oe(B,C,8)^Cn(B,C,7),M=ae(B,C,1)^ae(B,C,8)^Pn(B,C,7),E=Xt[w-2]|0,x=Wt[w-2]|0,P=oe(E,x,19)^$e(E,x,61)^Cn(E,x,6),O=ae(E,x,19)^Ze(E,x,61)^Pn(E,x,6),T=Mi(M,O,Wt[w-7],Wt[w-16]),p=Oi(T,U,P,Xt[w-7],Xt[w-16]);Xt[w]=p|0,Wt[w]=T|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:y,Fh:b,Fl:d,Gh:I,Gl:S,Hh:g,Hl:A}=this;for(let w=0;w<80;w++){let B=oe(f,y,14)^oe(f,y,18)^$e(f,y,41),C=ae(f,y,14)^ae(f,y,18)^Ze(f,y,41),U=f&b^~f&I,M=y&d^~y&S,E=qi(A,C,M,Hc[w],Wt[w]),x=Vi(E,g,B,U,Vc[w],Xt[w]),P=E|0,O=oe(n,s,28)^$e(n,s,34)^$e(n,s,39),T=ae(n,s,28)^Ze(n,s,34)^Ze(n,s,39),p=n&i^n&a^i&a,m=s&o^s&c^o&c;g=I|0,A=S|0,I=b|0,S=d|0,b=f|0,d=y|0,{h:f,l:y}=Tt(u|0,l|0,x|0,P|0),u=a|0,l=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let h=Ki(P,T,m);n=Ui(h,x,O,p),s=h|0}({h:n,l:s}=Tt(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=Tt(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=Tt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Tt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:y}=Tt(this.Eh|0,this.El|0,f|0,y|0),{h:b,l:d}=Tt(this.Fh|0,this.Fl|0,b|0,d|0),{h:I,l:S}=Tt(this.Gh|0,this.Gl|0,I|0,S|0),{h:g,l:A}=Tt(this.Hh|0,this.Hl|0,g|0,A|0),this.set(n,s,i,o,a,c,u,l,f,y,b,d,I,S,g,A)}roundClean(){Ut(Xt,Wt)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Mn=class extends Un{Ah=it[0]|0;Al=it[1]|0;Bh=it[2]|0;Bl=it[3]|0;Ch=it[4]|0;Cl=it[5]|0;Dh=it[6]|0;Dl=it[7]|0;Eh=it[8]|0;El=it[9]|0;Fh=it[10]|0;Fl=it[11]|0;Gh=it[12]|0;Gl=it[13]|0;Hh=it[14]|0;Hl=it[15]|0;constructor(){super(64)}};var Be=Rn(()=>new Kn,kn(1));var Fi=Rn(()=>new Mn,kn(3));var qn=BigInt(0),On=BigInt(1);function Vt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function zi(r){if(typeof r=="bigint"){if(!Br(r))throw new Error("positive bigint expected, got "+r)}else Dt(r);return r}function Ge(r){let t=zi(r).toString(16);return t.length&1?"0"+t:t}function $i(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?qn:BigInt("0x"+r)}function Le(r){return $i(Mt(r))}function ce(r){return $i(Mt(_r(K(r)).reverse()))}function Lr(r,t){Dt(t),r=zi(r);let e=Ot(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function Vn(r,t){return Lr(r,t).reverse()}function _r(r){return Uint8Array.from(r)}var Br=r=>typeof r=="bigint"&&qn<=r;function Fc(r,t,e){return Br(r)&&Br(t)&&Br(e)&&t<=r&&r<e}function Ye(r,t,e,n){if(!Fc(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Hn(r){let t;for(t=0;r>qn;r>>=On,t+=1);return t}var je=r=>(On<<BigInt(r))-On;function Zi(r,t,e){if(Dt(r,"hashLen"),Dt(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=S=>new Uint8Array(S),s=Uint8Array.of(),i=Uint8Array.of(0),o=Uint8Array.of(1),a=1e3,c=n(r),u=n(r),l=0,f=()=>{c.fill(1),u.fill(0),l=0},y=(...S)=>e(u,yt(c,...S)),b=(S=s)=>{u=y(i,S),c=y(),S.length!==0&&(u=y(o,S),c=y())},d=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let S=0,g=[];for(;S<t;){c=y();let A=c.slice();g.push(A),S+=c.length}return yt(...g)};return(S,g)=>{f(),b(S);let A;for(;!(A=g(d()));)b();return f(),A}}function Jt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(i,o,a){let c=r[i];if(a&&c===void 0)return;let u=typeof c;if(u!==o||c===null)throw new Error(`param "${i}" is invalid: expected ${o}, got ${u}`)}let s=(i,o)=>Object.entries(i).forEach(([a,c])=>n(a,c,o));s(t,!1),s(e,!0)}function _e(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let i=r(e,...n);return t.set(e,i),i}}var lt=BigInt(0),rt=BigInt(1),ue=BigInt(2),ji=BigInt(3),Xi=BigInt(4),Wi=BigInt(5),zc=BigInt(7),Ji=BigInt(8),$c=BigInt(9),Qi=BigInt(16);function Q(r,t){let e=r%t;return e>=lt?e:t+e}function Z(r,t,e){let n=r;for(;t-- >lt;)n*=n,n%=e;return n}function Gi(r,t){if(r===lt)throw new Error("invert: expected non-zero number");if(t<=lt)throw new Error("invert: expected positive modulus, got "+t);let e=Q(r,t),n=t,s=lt,i=rt,o=rt,a=lt;for(;e!==lt;){let u=n/e,l=n%e,f=s-o*u,y=i-a*u;n=e,e=l,s=o,i=a,o=f,a=y}if(n!==rt)throw new Error("invert: does not exist");return Q(s,t)}function zn(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function to(r,t){let e=(r.ORDER+rt)/Xi,n=r.pow(t,e);return zn(r,n,t),n}function Zc(r,t){let e=(r.ORDER-Wi)/Ji,n=r.mul(t,ue),s=r.pow(n,e),i=r.mul(t,s),o=r.mul(r.mul(i,ue),s),a=r.mul(i,r.sub(o,r.ONE));return zn(r,a,t),a}function Gc(r){let t=De(r),e=eo(r),n=e(t,t.neg(t.ONE)),s=e(t,n),i=e(t,t.neg(n)),o=(r+zc)/Qi;return(a,c)=>{let u=a.pow(c,o),l=a.mul(u,n),f=a.mul(u,s),y=a.mul(u,i),b=a.eql(a.sqr(l),c),d=a.eql(a.sqr(f),c);u=a.cmov(u,l,b),l=a.cmov(y,f,d);let I=a.eql(a.sqr(l),c),S=a.cmov(u,l,I);return zn(a,S,c),S}}function eo(r){if(r<ji)throw new Error("sqrt is not defined for small field");let t=r-rt,e=0;for(;t%ue===lt;)t/=ue,e++;let n=ue,s=De(r);for(;Yi(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return to;let i=s.pow(n,t),o=(t+rt)/ue;return function(c,u){if(c.is0(u))return u;if(Yi(c,u)!==1)throw new Error("Cannot find square root");let l=e,f=c.mul(c.ONE,i),y=c.pow(u,t),b=c.pow(u,o);for(;!c.eql(y,c.ONE);){if(c.is0(y))return c.ZERO;let d=1,I=c.sqr(y);for(;!c.eql(I,c.ONE);)if(d++,I=c.sqr(I),d===l)throw new Error("Cannot find square root");let S=rt<<BigInt(l-d-1),g=c.pow(f,S);l=d,f=c.sqr(g),y=c.mul(y,f),b=c.mul(b,g)}return b}}function Yc(r){return r%Xi===ji?to:r%Ji===Wi?Zc:r%Qi===$c?Gc(r):eo(r)}var ro=(r,t)=>(Q(r,t)&rt)===rt,jc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function $n(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=jc.reduce((n,s)=>(n[s]="function",n),t);return Jt(r,e),r}function Xc(r,t,e){if(e<lt)throw new Error("invalid exponent, negatives unsupported");if(e===lt)return r.ONE;if(e===rt)return t;let n=r.ONE,s=t;for(;e>lt;)e&rt&&(n=r.mul(n,s)),s=r.sqr(s),e>>=rt;return n}function Xe(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),s=t.reduce((o,a,c)=>r.is0(a)?o:(n[c]=o,r.mul(o,a)),r.ONE),i=r.inv(s);return t.reduceRight((o,a,c)=>r.is0(a)?o:(n[c]=r.mul(o,n[c]),r.mul(o,a)),i),n}function Yi(r,t){let e=(r.ORDER-rt)/ue,n=r.pow(t,e),s=r.eql(n,r.ONE),i=r.eql(n,r.ZERO),o=r.eql(n,r.neg(r.ONE));if(!s&&!i&&!o)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Wc(r,t){t!==void 0&&Dt(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var Fn=class{ORDER;BITS;BYTES;isLE;ZERO=lt;ONE=rt;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=lt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:s,nByteLength:i}=Wc(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return Q(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return lt<=t&&t<this.ORDER}is0(t){return t===lt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&rt)===rt}neg(t){return Q(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Q(t*t,this.ORDER)}add(t,e){return Q(t+e,this.ORDER)}sub(t,e){return Q(t-e,this.ORDER)}mul(t,e){return Q(t*e,this.ORDER)}pow(t,e){return Xc(this,t,e)}div(t,e){return Q(t*Gi(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return Gi(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Yc(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Vn(t,this.BYTES):Lr(t,this.BYTES)}fromBytes(t,e=!1){K(t);let{_lengths:n,BYTES:s,isLE:i,ORDER:o,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(s);u.set(t,i?0:u.length-t.length),t=u}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=i?ce(t):Le(t);if(a&&(c=Q(c,o)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Xe(this,t)}cmov(t,e,n){return n?e:t}};function De(r,t={}){return new Fn(r,t)}function no(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 Zn(r){let t=no(r);return t+Math.ceil(t/2)}function Gn(r,t,e=!1){K(r);let n=r.length,s=no(t),i=Zn(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=e?ce(r):Le(r),a=Q(o,t-rt)+rt;return e?Vn(a,s):Lr(a,s)}var Te=BigInt(0),fe=BigInt(1);function We(r,t){let e=t.negate();return r?e:t}function le(r,t){let e=Xe(r.Fp,t.map(n=>n.Z));return t.map((n,s)=>r.fromAffine(n.toAffine(e[s])))}function ao(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Yn(r,t){ao(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),s=2**r,i=je(r),o=BigInt(r);return{windows:e,windowSize:n,mask:i,maxNumber:s,shiftBy:o}}function so(r,t,e){let{windowSize:n,mask:s,maxNumber:i,shiftBy:o}=e,a=Number(r&s),c=r>>o;a>n&&(a-=i,c+=fe);let u=t*n,l=u+Math.abs(a)-1,f=a===0,y=a<0,b=t%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:y,isNegF:b,offsetF:u}}var jn=new WeakMap,co=new WeakMap;function Xn(r){return co.get(r)||1}function io(r){if(r!==Te)throw new Error("invalid wNAF")}var Re=class{BASE;ZERO;Fn;bits;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 s=t;for(;e>Te;)e&fe&&(n=n.add(s)),s=s.double(),e>>=fe;return n}precomputeWindow(t,e){let{windows:n,windowSize:s}=Yn(e,this.bits),i=[],o=t,a=o;for(let c=0;c<n;c++){a=o,i.push(a);for(let u=1;u<s;u++)a=a.add(o),i.push(a);o=a.double()}return i}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,i=this.BASE,o=Yn(t,this.bits);for(let a=0;a<o.windows;a++){let{nextN:c,offset:u,isZero:l,isNeg:f,isNegF:y,offsetF:b}=so(n,a,o);n=c,l?i=i.add(We(y,e[b])):s=s.add(We(f,e[u]))}return io(n),{p:s,f:i}}wNAFUnsafe(t,e,n,s=this.ZERO){let i=Yn(t,this.bits);for(let o=0;o<i.windows&&n!==Te;o++){let{nextN:a,offset:c,isZero:u,isNeg:l}=so(n,o,i);if(n=a,!u){let f=e[c];s=s.add(l?f.negate():f)}}return io(n),s}getPrecomputes(t,e,n){let s=jn.get(e);return s||(s=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(s=n(s)),jn.set(e,s))),s}cached(t,e,n){let s=Xn(t);return this.wNAF(s,this.getPrecomputes(s,t,n),e)}unsafe(t,e,n,s){let i=Xn(t);return i===1?this._unsafeLadder(t,e,s):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),e,s)}createCache(t,e){ao(e,this.bits),co.set(t,e),jn.delete(t)}hasCache(t){return Xn(t)!==1}};function uo(r,t,e,n){let s=t,i=r.ZERO,o=r.ZERO;for(;e>Te||n>Te;)e&fe&&(i=i.add(s)),n&fe&&(o=o.add(s)),s=s.double(),e>>=fe,n>>=fe;return{p1:i,p2:o}}function oo(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return $n(t),t}else return De(r,{isLE:e})}function Dr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Te))throw new Error(`CURVE.${c} must be positive bigint`)}let s=oo(t.p,e.Fp,n),i=oo(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:i}}function Tr(r,t){return function(n){let s=r(n);return{secretKey:s,publicKey:t(s)}}}var Qt=BigInt(0),nt=BigInt(1),Wn=BigInt(2),Jc=BigInt(8);function Qc(r,t,e,n){let s=r.sqr(e),i=r.sqr(n),o=r.add(r.mul(t.a,s),i),a=r.add(r.ONE,r.mul(t.d,r.mul(s,i)));return r.eql(o,a)}function fo(r,t={}){let e=Dr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:s}=e,i=e.CURVE,{h:o}=i;Jt(t,{},{uvRatio:"function"});let a=Wn<<BigInt(s.BYTES*8)-nt,c=S=>n.create(S),u=t.uvRatio||((S,g)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,g))}}catch{return{isValid:!1,value:Qt}}});if(!Qc(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(S,g,A=!1){let w=A?nt:Qt;return Ye("coordinate "+S,g,w,a),g}function f(S){if(!(S instanceof d))throw new Error("EdwardsPoint expected")}let y=_e((S,g)=>{let{X:A,Y:w,Z:B}=S,C=S.is0();g==null&&(g=C?Jc:n.inv(B));let U=c(A*g),M=c(w*g),E=n.mul(B,g);if(C)return{x:Qt,y:nt};if(E!==nt)throw new Error("invZ was invalid");return{x:U,y:M}}),b=_e(S=>{let{a:g,d:A}=i;if(S.is0())throw new Error("bad point: ZERO");let{X:w,Y:B,Z:C,T:U}=S,M=c(w*w),E=c(B*B),x=c(C*C),P=c(x*x),O=c(M*g),T=c(x*c(O+E)),p=c(P+c(A*c(M*E)));if(T!==p)throw new Error("bad point: equation left != right (1)");let m=c(w*B),h=c(C*U);if(m!==h)throw new Error("bad point: equation left != right (2)");return!0});class d{static BASE=new d(i.Gx,i.Gy,nt,c(i.Gx*i.Gy));static ZERO=new d(Qt,nt,nt,Qt);static Fp=n;static Fn=s;X;Y;Z;T;constructor(g,A,w,B){this.X=l("x",g),this.Y=l("y",A),this.Z=l("z",w,!0),this.T=l("t",B),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof d)throw new Error("extended point not allowed");let{x:A,y:w}=g||{};return l("x",A),l("y",w),new d(A,w,nt,c(A*w))}static fromBytes(g,A=!1){let w=n.BYTES,{a:B,d:C}=i;g=_r(K(g,w,"point")),Vt(A,"zip215");let U=_r(g),M=g[w-1];U[w-1]=M&-129;let E=ce(U),x=A?a:n.ORDER;Ye("point.y",E,Qt,x);let P=c(E*E),O=c(P-nt),T=c(C*P-B),{isValid:p,value:m}=u(O,T);if(!p)throw new Error("bad point: invalid y coordinate");let h=(m&nt)===nt,v=(M&128)!==0;if(!A&&m===Qt&&v)throw new Error("bad point: x=0 and x_0=1");return v!==h&&(m=c(-m)),d.fromAffine({x:m,y:E})}static fromHex(g,A=!1){return d.fromBytes(Ot(g),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,A=!0){return I.createCache(this,g),A||this.multiply(Wn),this}assertValidity(){b(this)}equals(g){f(g);let{X:A,Y:w,Z:B}=this,{X:C,Y:U,Z:M}=g,E=c(A*M),x=c(C*B),P=c(w*M),O=c(U*B);return E===x&&P===O}is0(){return this.equals(d.ZERO)}negate(){return new d(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:g}=i,{X:A,Y:w,Z:B}=this,C=c(A*A),U=c(w*w),M=c(Wn*c(B*B)),E=c(g*C),x=A+w,P=c(c(x*x)-C-U),O=E+U,T=O-M,p=E-U,m=c(P*T),h=c(O*p),v=c(P*p),L=c(T*O);return new d(m,h,L,v)}add(g){f(g);let{a:A,d:w}=i,{X:B,Y:C,Z:U,T:M}=this,{X:E,Y:x,Z:P,T:O}=g,T=c(B*E),p=c(C*x),m=c(M*w*O),h=c(U*P),v=c((B+C)*(E+x)-T-p),L=h-m,D=h+m,R=c(p-A*T),_=c(v*L),k=c(D*R),N=c(v*R),Y=c(L*D);return new d(_,k,Y,N)}subtract(g){return this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=I.cached(this,g,B=>le(d,B));return le(d,[A,w])[0]}multiplyUnsafe(g,A=d.ZERO){if(!s.isValid(g))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return g===Qt?d.ZERO:this.is0()||g===nt?this:I.unsafe(this,g,w=>le(d,w),A)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return I.unsafe(this,i.n).is0()}toAffine(g){return y(this,g)}clearCofactor(){return o===nt?this:this.multiplyUnsafe(o)}toBytes(){let{x:g,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=g&nt?128:0,w}toHex(){return Mt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let I=new Re(d,s.BITS);return d.BASE.precompute(8),d}function lo(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');Jt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:s,Fp:i,Fn:o}=r,a=e.randomBytes||Yt,c=e.adjustScalarBytes||(E=>E),u=e.domain||((E,x,P)=>{if(Vt(P,"phflag"),x.length||P)throw new Error("Contexts/pre-hash are not supported");return E});function l(E){return o.create(ce(E))}function f(E){let x=w.secretKey;K(E,w.secretKey,"secretKey");let P=K(t(E),2*x,"hashedSecretKey"),O=c(P.slice(0,x)),T=P.slice(x,2*x),p=l(O);return{head:O,prefix:T,scalar:p}}function y(E){let{head:x,prefix:P,scalar:O}=f(E),T=s.multiply(O),p=T.toBytes();return{head:x,prefix:P,scalar:O,point:T,pointBytes:p}}function b(E){return y(E).pointBytes}function d(E=Uint8Array.of(),...x){let P=yt(...x);return l(t(u(P,K(E,void 0,"context"),!!n)))}function I(E,x,P={}){E=K(E,void 0,"message"),n&&(E=n(E));let{prefix:O,scalar:T,pointBytes:p}=y(x),m=d(P.context,O,E),h=s.multiply(m).toBytes(),v=d(P.context,h,p,E),L=o.create(m+v*T);if(!o.isValid(L))throw new Error("sign failed: invalid s");let D=yt(h,o.toBytes(L));return K(D,w.signature,"result")}let S={zip215:!0};function g(E,x,P,O=S){let{context:T,zip215:p}=O,m=w.signature;E=K(E,m,"signature"),x=K(x,void 0,"message"),P=K(P,w.publicKey,"publicKey"),p!==void 0&&Vt(p,"zip215"),n&&(x=n(x));let h=m/2,v=E.subarray(0,h),L=ce(E.subarray(h,m)),D,R,_;try{D=r.fromBytes(P,p),R=r.fromBytes(v,p),_=s.multiplyUnsafe(L)}catch{return!1}if(!p&&D.isSmallOrder())return!1;let k=d(T,R.toBytes(),D.toBytes(),x);return R.add(D.multiplyUnsafe(k)).subtract(_).clearCofactor().is0()}let A=i.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function B(E=a(w.seed)){return K(E,w.seed,"seed")}function C(E){return ie(E)&&E.length===o.BYTES}function U(E,x){try{return!!r.fromBytes(E,x)}catch{return!1}}let M={getExtendedPublicKey:y,randomSecretKey:B,isValidSecretKey:C,isValidPublicKey:U,toMontgomery(E){let{y:x}=r.fromBytes(E),P=w.publicKey,O=P===32;if(!O&&P!==57)throw new Error("only defined for 25519 and 448");let T=O?i.div(nt+x,nt-x):i.div(x-nt,x+nt);return i.toBytes(T)},toMontgomerySecret(E){let x=w.secretKey;K(E,x);let P=t(E.subarray(0,x));return c(P).subarray(0,x)}};return Object.freeze({keygen:Tr(B,b),getPublicKey:b,sign:I,verify:g,utils:M,Point:r,lengths:w})}var tu=BigInt(1),ho=BigInt(2);var eu=BigInt(5),ru=BigInt(8),Jn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),nu={p:Jn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:ru,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function su(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),i=Jn,a=r*r%i*r%i,c=Z(a,ho,i)*a%i,u=Z(c,tu,i)*r%i,l=Z(u,eu,i)*u%i,f=Z(l,t,i)*l%i,y=Z(f,e,i)*f%i,b=Z(y,n,i)*y%i,d=Z(b,s,i)*b%i,I=Z(d,s,i)*b%i,S=Z(I,t,i)*l%i;return{pow_p_5_8:Z(S,ho,i)*r%i,b2:a}}function iu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var po=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ou(r,t){let e=Jn,n=Q(t*t*t,e),s=Q(n*n*t,e),i=su(r*s).pow_p_5_8,o=Q(r*n*i,e),a=Q(t*o*o,e),c=o,u=Q(o*po,e),l=a===r,f=a===Q(-r,e),y=a===Q(-r*po,e);return l&&(o=c),(f||y)&&(o=u),ro(o,e)&&(o=Q(-o,e)),{isValid:l||f,value:o}}var au=fo(nu,{uvRatio:ou});function cu(r){return lo(au,Fi,Object.assign({adjustScalarBytes:iu},r))}var mo=cu({});var Je=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Rr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var bo={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Rr("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 vt=bo;var kr=32;var Qn,uu=(async()=>{try{return await vt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function fu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await vt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await vt.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 lu(r,t,e){return mo.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function yo(r,t,e){return Qn==null&&(Qn=await uu),Qn?fu(r,t,e):lu(r,t,e)}function Cr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Pr=class{type="Ed25519";raw;constructor(t){this.raw=ts(t,kr)}toMultihash(){return At.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let s=yo(this.raw,e,t);return Cr(s)?s.then(i=>(n?.signal?.throwIfAborted(),i)):s}};function es(r){return r=ts(r,kr),new Pr(r)}function ts(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new z(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var du=Math.pow(2,7),pu=Math.pow(2,14),mu=Math.pow(2,21),rs=Math.pow(2,28),ns=Math.pow(2,35),ss=Math.pow(2,42),is=Math.pow(2,49),V=128,ct=127;function Ht(r){if(r<du)return 1;if(r<pu)return 2;if(r<mu)return 3;if(r<rs)return 4;if(r<ns)return 5;if(r<ss)return 6;if(r<is)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function os(r,t,e=0){switch(Ht(r)){case 8:t[e++]=r&255|V,r/=128;case 7:t[e++]=r&255|V,r/=128;case 6:t[e++]=r&255|V,r/=128;case 5:t[e++]=r&255|V,r/=128;case 4:t[e++]=r&255|V,r>>>=7;case 3:t[e++]=r&255|V,r>>>=7;case 2:t[e++]=r&255|V,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function bu(r,t,e=0){switch(Ht(r)){case 8:t.set(e++,r&255|V),r/=128;case 7:t.set(e++,r&255|V),r/=128;case 6:t.set(e++,r&255|V),r/=128;case 5:t.set(e++,r&255|V),r/=128;case 4:t.set(e++,r&255|V),r>>>=7;case 3:t.set(e++,r&255|V),r>>>=7;case 2:t.set(e++,r&255|V),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function as(r,t){let e=r[t],n=0;if(n+=e&ct,e<V||(e=r[t+1],n+=(e&ct)<<7,e<V)||(e=r[t+2],n+=(e&ct)<<14,e<V)||(e=r[t+3],n+=(e&ct)<<21,e<V)||(e=r[t+4],n+=(e&ct)*rs,e<V)||(e=r[t+5],n+=(e&ct)*ns,e<V)||(e=r[t+6],n+=(e&ct)*ss,e<V)||(e=r[t+7],n+=(e&ct)*is,e<V))return n;throw new RangeError("Could not decode varint")}function yu(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<V||(e=r.get(t+1),n+=(e&ct)<<7,e<V)||(e=r.get(t+2),n+=(e&ct)<<14,e<V)||(e=r.get(t+3),n+=(e&ct)<<21,e<V)||(e=r.get(t+4),n+=(e&ct)*rs,e<V)||(e=r.get(t+5),n+=(e&ct)*ns,e<V)||(e=r.get(t+6),n+=(e&ct)*ss,e<V)||(e=r.get(t+7),n+=(e&ct)*is,e<V))return n;throw new RangeError("Could not decode varint")}function wo(r,t,e=0){return t==null&&(t=mt(Ht(r))),t instanceof Uint8Array?os(r,t,e):bu(r,t,e)}function xo(r,t=0){return r instanceof Uint8Array?as(r,t):yu(r,t)}var cs=new Float32Array([-0]),te=new Uint8Array(cs.buffer);function Eo(r,t,e){cs[0]=r,t[e]=te[0],t[e+1]=te[1],t[e+2]=te[2],t[e+3]=te[3]}function vo(r,t){return te[0]=r[t],te[1]=r[t+1],te[2]=r[t+2],te[3]=r[t+3],cs[0]}var us=new Float64Array([-0]),ut=new Uint8Array(us.buffer);function So(r,t,e){us[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function Ao(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],us[0]}var wu=BigInt(Number.MAX_SAFE_INTEGER),xu=BigInt(Number.MIN_SAFE_INTEGER),Et=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 he;if(t<wu&&t>xu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>Io&&(s=0n,++n>Io&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return he;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}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):he}},he=new Et(0,0);he.toBigInt=function(){return 0n};he.zzEncode=he.zzDecode=function(){return this};he.length=function(){return 1};var Io=4294967296n;function Bo(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 Lo(r,t,e){if(e-t<1)return"";let s,i=[],o=0,a;for(;t<e;)a=r[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(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,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function fs(r,t,e){let n=e,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function Bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Nr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ls=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Bt(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 Bt(this,4);return Nr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Nr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=vo(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=Ao(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 Bt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Lo(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(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 Et(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 Bt(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 Bt(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 Bt(this,8);let t=Nr(this.buf,this.pos+=4),e=Nr(this.buf,this.pos+=4);return new Et(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=as(this.buf,this.pos);return this.pos+=Ht(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 hs(r){return new ls(r instanceof Uint8Array?r:r.subarray())}function gt(r,t,e){let n=hs(r);return t.decode(n,void 0,e)}function ds(r){let t=r??8192,e=t>>>1,n,s=t;return function(o){if(o<1||o>e)return mt(o);s+o>t&&(n=mt(t),s=0);let a=n.subarray(s,s+=o);return(s&7)!==0&&(s=(s|7)+1),a}}var de=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function ps(){}var bs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Eu=ds();function vu(r){return globalThis.Buffer!=null?mt(r):Eu(r)}var tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(ps,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new de(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ys((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Kr,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Et.fromBigInt(t);return this._push(Kr,e.length(),e)}uint64Number(t){return this._push(os,Ht(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=Et.fromBigInt(t).zzEncode();return this._push(Kr,e.length(),e)}sint64Number(t){let e=Et.fromNumber(t).zzEncode();return this._push(Kr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ms,1,t?1:0)}fixed32(t){return this._push(Qe,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Et.fromBigInt(t);return this._push(Qe,4,e.lo)._push(Qe,4,e.hi)}fixed64Number(t){let e=Et.fromNumber(t);return this._push(Qe,4,e.lo)._push(Qe,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(Eo,4,t)}double(t){return this._push(So,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ms,1,0):this.uint32(e)._push(Au,e,t)}string(t){let e=Bo(t);return e!==0?this.uint32(e)._push(fs,e,t):this._push(ms,1,0)}fork(){return this.states=new bs(this),this.head=this.tail=new de(ps,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new de(ps,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=vu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ms(r,t,e){t[e]=r&255}function Su(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ys=class extends de{next;constructor(t,e){super(Su,t,e),this.next=void 0}};function Kr(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 Qe(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 Au(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(tr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Iu,t,r),this},tr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Bu,t,r),this});function Iu(r,t,e){t.set(r,e)}function Bu(r,t,e){r.length<40?fs(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(F(r),e)}function gs(){return new tr}function wt(r,t){let e=gs();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ke;(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"})(ke||(ke={}));function Ur(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ws(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,o){let a=t(i);o.int32(a)},n=function(i){let o=i.int32();return t(o)};return Ur("enum",ke.VARINT,e,n)}function xt(r,t){return Ur("message",ke.LENGTH_DELIMITED,r,t)}var St=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var xs;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(xs||(xs={}));(function(r){r.codec=()=>ws(xs)})(tt||(tt={}));var Rt;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.Type=tt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Rt||(Rt={}));var Es;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.Type=tt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Es||(Es={}));function Mr(r){if(isNaN(r)||r<=0)throw new z("random bytes length must be a Number bigger than 0");return Yt(r)}var rr={};dt(rr,{MAX_RSA_KEY_SIZE:()=>vs,generateRSAKeyPair:()=>Co,jwkToJWKKeyPair:()=>Po,jwkToPkcs1:()=>Tu,jwkToPkix:()=>Bs,jwkToRSAPrivateKey:()=>Ts,pkcs1MessageToJwk:()=>As,pkcs1MessageToRSAPrivateKey:()=>Ls,pkcs1ToJwk:()=>Du,pkcs1ToRSAPrivateKey:()=>ko,pkixMessageToJwk:()=>Is,pkixMessageToRSAPublicKey:()=>Ds,pkixToJwk:()=>Ru,pkixToRSAPublicKey:()=>_s});var Ce=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e,n){return Ro(this.jwk,e,t,n)}},er=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=rr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}sign(t,e){return To(this.jwk,t,e)}};var vs=8192,Ss=18,Lu=1062,_u=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Du(r){let t=Pt(r);return As(t)}function As(r){return{n:H(r[1],"base64url"),e:H(r[2],"base64url"),d:H(r[3],"base64url"),p:H(r[4],"base64url"),q:H(r[5],"base64url"),dp:H(r[6],"base64url"),dq:H(r[7],"base64url"),qi:H(r[8],"base64url"),kty:"RSA"}}function Tu(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 z("JWK was missing components");return Gt([bt(Uint8Array.from([0])),bt(F(r.n,"base64url")),bt(F(r.e,"base64url")),bt(F(r.d,"base64url")),bt(F(r.p,"base64url")),bt(F(r.q,"base64url")),bt(F(r.dp,"base64url")),bt(F(r.dq,"base64url")),bt(F(r.qi,"base64url"))]).subarray()}function Ru(r){let t=Pt(r,{offset:0});return Is(t)}function Is(r){let t=Pt(r[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function Bs(r){if(r.n==null||r.e==null)throw new z("JWK was missing components");return Gt([_u,vr(Gt([bt(F(r.n,"base64url")),bt(F(r.e,"base64url"))]))]).subarray()}function ko(r){let t=Pt(r);return Ls(t)}function Ls(r){let t=As(r);return Ts(t)}function _s(r,t){if(r.byteLength>=Lu)throw new ye("Key size is too large");let e=Pt(r,{offset:0});return Ds(e,r,t)}function Ds(r,t,e){let n=Is(r);if(e==null){let s=Be(Rt.encode({Type:tt.RSA,Data:t}));e=_t(Ss,s)}return new Ce(n,e)}function Ts(r){if(Ko(r)>vs)throw new z("Key size is too large");let t=Po(r),e=Be(Rt.encode({Type:tt.RSA,Data:Bs(t.publicKey)})),n=_t(Ss,e);return new er(t.privateKey,new Ce(t.publicKey,n))}async function Co(r){if(r>vs)throw new z("Key size is too large");let t=await No(r),e=Be(Rt.encode({Type:tt.RSA,Data:Bs(t.publicKey)})),n=_t(Ss,e);return new er(t.privateKey,new Ce(t.publicKey,n))}function Po(r){if(r==null)throw new z("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function No(r,t){let e=await vt.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 ku(e,t);return{privateKey:n[0],publicKey:n[1]}}async function To(r,t,e){let n=await vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let s=await vt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function Ro(r,t,e,n){let s=await vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await vt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),i}async function ku(r,t){if(r.privateKey==null||r.publicKey==null)throw new z("Private and public key are required");let e=await Promise.all([vt.get().subtle.exportKey("jwk",r.privateKey),vt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Ko(r){if(r.kty!=="RSA")throw new z("invalid key type");if(r.n==null)throw new z("invalid key modulus");return F(r.n,"base64url").length*8}var Or=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Sr(t),K(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(e.length>n?t.create().update(e).digest():e);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),Ut(s)}update(t){return Ie(this),this.iHash.update(t),this}digestInto(t){Ie(this),K(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=i,t.blockLen=o,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()}},Rs=(r,t,e)=>new Or(r,t).update(e).digest();Rs.create=(r,t)=>new Or(r,t);var Uo=(r,t)=>(r+(r>=0?t:-t)/Mo)/t;function Cu(r,t,e){let[[n,s],[i,o]]=t,a=Uo(o*r,e),c=Uo(-s*r,e),u=r-a*n-c*i,l=-a*s-c*o,f=u<Ft,y=l<Ft;f&&(u=-u),y&&(l=-l);let b=je(Math.ceil(Hn(e)/2))+Pe;if(u<Ft||u>=b||l<Ft||l>=b)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:f,k1:u,k2neg:y,k2:l}}function Cs(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function ks(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Vt(e.lowS,"lowS"),Vt(e.prehash,"prehash"),e.format!==void 0&&Cs(e.format),e}var Ps=class extends Error{constructor(t=""){super(t)}},ee={Err:Ps,_tlv:{encode:(r,t)=>{let{Err:e}=ee;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,s=Ge(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let i=n>127?Ge(s.length/2|128):"";return Ge(r)+i+s+t},decode(r,t){let{Err:e}=ee,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 s=t[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&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 l of u)o=o<<8|l;if(n+=c,o<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+o);if(a.length!==o)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(r){let{Err:t}=ee;if(r<Ft)throw new t("integer: negative integers are not allowed");let e=Ge(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}=ee;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 Le(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=ee,s=K(r,void 0,"signature"),{v:i,l:o}=n.decode(48,s);if(o.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l}=n.decode(2,c);if(l.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}=ee,n=t.encode(2,e.encode(r.r)),s=t.encode(2,e.encode(r.s)),i=n+s;return t.encode(48,i)}},Ft=BigInt(0),Pe=BigInt(1),Mo=BigInt(2),qr=BigInt(3),Pu=BigInt(4);function Oo(r,t={}){let e=Dr("weierstrass",r,t),{Fp:n,Fn:s}=e,i=e.CURVE,{h:o,n:a}=i;Jt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Vo(n,s);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(T,p,m){let{x:h,y:v}=p.toAffine(),L=n.toBytes(h);if(Vt(m,"isCompressed"),m){l();let D=!n.isOdd(v);return yt(qo(D),L)}else return yt(Uint8Array.of(4),L,n.toBytes(v))}function y(T){K(T,void 0,"Point");let{publicKey:p,publicKeyUncompressed:m}=u,h=T.length,v=T[0],L=T.subarray(1);if(h===p&&(v===2||v===3)){let D=n.fromBytes(L);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let R=I(D),_;try{_=n.sqrt(R)}catch(Y){let $=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+$)}l();let k=n.isOdd(_);return(v&1)===1!==k&&(_=n.neg(_)),{x:D,y:_}}else if(h===m&&v===4){let D=n.BYTES,R=n.fromBytes(L.subarray(0,D)),_=n.fromBytes(L.subarray(D,D*2));if(!S(R,_))throw new Error("bad point: is not on curve");return{x:R,y:_}}else throw new Error(`bad point: got length ${h}, expected compressed=${p} or uncompressed=${m}`)}let b=t.toBytes||f,d=t.fromBytes||y;function I(T){let p=n.sqr(T),m=n.mul(p,T);return n.add(n.add(m,n.mul(T,i.a)),i.b)}function S(T,p){let m=n.sqr(p),h=I(T);return n.eql(m,h)}if(!S(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(i.a,qr),Pu),A=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(g,A)))throw new Error("bad curve params: a or b");function w(T,p,m=!1){if(!n.isValid(p)||m&&n.is0(p))throw new Error(`bad point coordinate ${T}`);return p}function B(T){if(!(T instanceof x))throw new Error("Weierstrass Point expected")}function C(T){if(!c||!c.basises)throw new Error("no endo");return Cu(T,c.basises,s.ORDER)}let U=_e((T,p)=>{let{X:m,Y:h,Z:v}=T;if(n.eql(v,n.ONE))return{x:m,y:h};let L=T.is0();p==null&&(p=L?n.ONE:n.inv(v));let D=n.mul(m,p),R=n.mul(h,p),_=n.mul(v,p);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:D,y:R}}),M=_e(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:p,y:m}=T.toAffine();if(!n.isValid(p)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!S(p,m))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function E(T,p,m,h,v){return m=new x(n.mul(m.X,T),m.Y,m.Z),p=We(h,p),m=We(v,m),p.add(m)}class x{static BASE=new x(i.Gx,i.Gy,n.ONE);static ZERO=new x(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(p,m,h){this.X=w("x",p),this.Y=w("y",m,!0),this.Z=w("z",h),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x:m,y:h}=p||{};if(!p||!n.isValid(m)||!n.isValid(h))throw new Error("invalid affine point");if(p instanceof x)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(h)?x.ZERO:new x(m,h,n.ONE)}static fromBytes(p){let m=x.fromAffine(d(K(p,void 0,"point")));return m.assertValidity(),m}static fromHex(p){return x.fromBytes(Ot(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,m=!0){return O.createCache(this,p),m||this.multiply(qr),this}assertValidity(){M(this)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){B(p);let{X:m,Y:h,Z:v}=this,{X:L,Y:D,Z:R}=p,_=n.eql(n.mul(m,R),n.mul(L,v)),k=n.eql(n.mul(h,R),n.mul(D,v));return _&&k}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:p,b:m}=i,h=n.mul(m,qr),{X:v,Y:L,Z:D}=this,R=n.ZERO,_=n.ZERO,k=n.ZERO,N=n.mul(v,v),Y=n.mul(L,L),$=n.mul(D,D),q=n.mul(v,L);return q=n.add(q,q),k=n.mul(v,D),k=n.add(k,k),R=n.mul(p,k),_=n.mul(h,$),_=n.add(R,_),R=n.sub(Y,_),_=n.add(Y,_),_=n.mul(R,_),R=n.mul(q,R),k=n.mul(h,k),$=n.mul(p,$),q=n.sub(N,$),q=n.mul(p,q),q=n.add(q,k),k=n.add(N,N),N=n.add(k,N),N=n.add(N,$),N=n.mul(N,q),_=n.add(_,N),$=n.mul(L,D),$=n.add($,$),N=n.mul($,q),R=n.sub(R,N),k=n.mul($,Y),k=n.add(k,k),k=n.add(k,k),new x(R,_,k)}add(p){B(p);let{X:m,Y:h,Z:v}=this,{X:L,Y:D,Z:R}=p,_=n.ZERO,k=n.ZERO,N=n.ZERO,Y=i.a,$=n.mul(i.b,qr),q=n.mul(m,L),j=n.mul(h,D),st=n.mul(v,R),Lt=n.add(m,h),X=n.add(L,D);Lt=n.mul(Lt,X),X=n.add(q,j),Lt=n.sub(Lt,X),X=n.add(m,v);let ot=n.add(L,R);return X=n.mul(X,ot),ot=n.add(q,st),X=n.sub(X,ot),ot=n.add(h,v),_=n.add(D,R),ot=n.mul(ot,_),_=n.add(j,st),ot=n.sub(ot,_),N=n.mul(Y,X),_=n.mul($,st),N=n.add(_,N),_=n.sub(j,N),N=n.add(j,N),k=n.mul(_,N),j=n.add(q,q),j=n.add(j,q),st=n.mul(Y,st),X=n.mul($,X),j=n.add(j,st),st=n.sub(q,st),st=n.mul(Y,st),X=n.add(X,st),q=n.mul(j,X),k=n.add(k,q),q=n.mul(ot,X),_=n.mul(Lt,_),_=n.sub(_,q),q=n.mul(Lt,j),N=n.mul(ot,N),N=n.add(N,q),new x(_,k,N)}subtract(p){return this.add(p.negate())}is0(){return this.equals(x.ZERO)}multiply(p){let{endo:m}=t;if(!s.isValidNot0(p))throw new Error("invalid scalar: out of range");let h,v,L=D=>O.cached(this,D,R=>le(x,R));if(m){let{k1neg:D,k1:R,k2neg:_,k2:k}=C(p),{p:N,f:Y}=L(R),{p:$,f:q}=L(k);v=Y.add(q),h=E(m.beta,N,$,D,_)}else{let{p:D,f:R}=L(p);h=D,v=R}return le(x,[h,v])[0]}multiplyUnsafe(p){let{endo:m}=t,h=this;if(!s.isValid(p))throw new Error("invalid scalar: out of range");if(p===Ft||h.is0())return x.ZERO;if(p===Pe)return h;if(O.hasCache(this))return this.multiply(p);if(m){let{k1neg:v,k1:L,k2neg:D,k2:R}=C(p),{p1:_,p2:k}=uo(x,h,L,R);return E(m.beta,_,k,v,D)}else return O.unsafe(h,p)}toAffine(p){return U(this,p)}isTorsionFree(){let{isTorsionFree:p}=t;return o===Pe?!0:p?p(x,this):O.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=t;return o===Pe?this:p?p(x,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(p=!0){return Vt(p,"isCompressed"),this.assertValidity(),b(x,this,p)}toHex(p=!0){return Mt(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=s.BITS,O=new Re(x,t.endo?Math.ceil(P/2):P);return x.BASE.precompute(8),x}function qo(r){return Uint8Array.of(r?2:3)}function Vo(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Nu(r,t={}){let{Fn:e}=r,n=t.randomBytes||Yt,s=Object.assign(Vo(r.Fp,e),{seed:Zn(e.ORDER)});function i(b){try{let d=e.fromBytes(b);return e.isValidNot0(d)}catch{return!1}}function o(b,d){let{publicKey:I,publicKeyUncompressed:S}=s;try{let g=b.length;return d===!0&&g!==I||d===!1&&g!==S?!1:!!r.fromBytes(b)}catch{return!1}}function a(b=n(s.seed)){return Gn(K(b,s.seed,"seed"),e.ORDER)}function c(b,d=!0){return r.BASE.multiply(e.fromBytes(b)).toBytes(d)}function u(b){let{secretKey:d,publicKey:I,publicKeyUncompressed:S}=s;if(!ie(b)||"_lengths"in e&&e._lengths||d===I)return;let g=K(b,void 0,"key").length;return g===I||g===S}function l(b,d,I=!0){if(u(b)===!0)throw new Error("first arg must be private key");if(u(d)===!1)throw new Error("second arg must be public key");let S=e.fromBytes(b);return r.fromBytes(d).multiply(S).toBytes(I)}let f={isValidSecretKey:i,isValidPublicKey:o,randomSecretKey:a},y=Tr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:y,Point:r,utils:f,lengths:s})}function Ho(r,t,e={}){Sr(t),Jt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||Yt,s=e.hmac||((m,h)=>Rs(t,m,h)),{Fp:i,Fn:o}=r,{ORDER:a,BITS:c}=o,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:y,lengths:b}=Nu(r,e),d={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},I=a*Mo<i.ORDER;function S(m){let h=a>>Pe;return m>h}function g(m,h){if(!o.isValidNot0(h))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return h}function A(){if(I)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(m,h){Cs(h);let v=b.signature,L=h==="compact"?v:h==="recovered"?v+1:void 0;return K(m,L)}class B{r;s;recovery;constructor(h,v,L){if(this.r=g("r",h),this.s=g("s",v),L!=null){if(A(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(h,v=d.format){w(h,v);let L;if(v==="der"){let{r:k,s:N}=ee.toSig(K(h));return new B(k,N)}v==="recovered"&&(L=h[0],v="compact",h=h.subarray(1));let D=b.signature/2,R=h.subarray(0,D),_=h.subarray(D,D*2);return new B(o.fromBytes(R),o.fromBytes(_),L)}static fromHex(h,v){return this.fromBytes(Ot(h),v)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new B(this.r,this.s,h)}recoverPublicKey(h){let{r:v,s:L}=this,D=this.assertRecovery(),R=D===2||D===3?v+a:v;if(!i.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let _=i.toBytes(R),k=r.fromBytes(yt(qo((D&1)===0),_)),N=o.inv(R),Y=U(K(h,void 0,"msgHash")),$=o.create(-Y*N),q=o.create(L*N),j=r.BASE.multiplyUnsafe($).add(k.multiplyUnsafe(q));if(j.is0())throw new Error("invalid recovery: point at infinify");return j.assertValidity(),j}hasHighS(){return S(this.s)}toBytes(h=d.format){if(Cs(h),h==="der")return Ot(ee.hexFromSig(this));let{r:v,s:L}=this,D=o.toBytes(v),R=o.toBytes(L);return h==="recovered"?(A(),yt(Uint8Array.of(this.assertRecovery()),D,R)):yt(D,R)}toHex(h){return Mt(this.toBytes(h))}}let C=e.bits2int||function(h){if(h.length>8192)throw new Error("input is too large");let v=Le(h),L=h.length*8-c;return L>0?v>>BigInt(L):v},U=e.bits2int_modN||function(h){return o.create(C(h))},M=je(c);function E(m){return Ye("num < 2^"+c,m,Ft,M),o.toBytes(m)}function x(m,h){return K(m,void 0,"message"),h?K(t(m),void 0,"prehashed message"):m}function P(m,h,v){let{lowS:L,prehash:D,extraEntropy:R}=ks(v,d);m=x(m,D);let _=U(m),k=o.fromBytes(h);if(!o.isValidNot0(k))throw new Error("invalid private key");let N=[E(k),E(_)];if(R!=null&&R!==!1){let j=R===!0?n(b.secretKey):R;N.push(K(j,void 0,"extraEntropy"))}let Y=yt(...N),$=_;function q(j){let st=C(j);if(!o.isValidNot0(st))return;let Lt=o.inv(st),X=r.BASE.multiply(st).toAffine(),ot=o.create(X.x);if(ot===Ft)return;let mr=o.create(Lt*o.create($+ot*k));if(mr===Ft)return;let Ws=(X.x===ot?0:2)|Number(X.y&Pe),Js=mr;return L&&S(mr)&&(Js=o.neg(mr),Ws^=1),new B(ot,Js,I?void 0:Ws)}return{seed:Y,k2sig:q}}function O(m,h,v={}){let{seed:L,k2sig:D}=P(m,h,v);return Zi(t.outputLen,o.BYTES,s)(L,D).toBytes(v.format)}function T(m,h,v,L={}){let{lowS:D,prehash:R,format:_}=ks(L,d);if(v=K(v,void 0,"publicKey"),h=x(h,R),!ie(m)){let k=m instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+k)}w(m,_);try{let k=B.fromBytes(m,_),N=r.fromBytes(v);if(D&&k.hasHighS())return!1;let{r:Y,s:$}=k,q=U(h),j=o.inv($),st=o.create(q*j),Lt=o.create(Y*j),X=r.BASE.multiplyUnsafe(st).add(N.multiplyUnsafe(Lt));return X.is0()?!1:o.create(X.x)===Y}catch{return!1}}function p(m,h,v={}){let{prehash:L}=ks(v,d);return h=x(h,L),B.fromBytes(m,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:y,lengths:b,Point:r,sign:O,verify:T,recoverPublicKey:p,Signature:B,hash:t})}var Ks={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ku={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Fo=BigInt(2);function Uu(r){let t=Ks.p,e=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=Z(l,e,t)*l%t,y=Z(f,e,t)*l%t,b=Z(y,Fo,t)*u%t,d=Z(b,s,t)*b%t,I=Z(d,i,t)*d%t,S=Z(I,a,t)*I%t,g=Z(S,c,t)*S%t,A=Z(g,a,t)*I%t,w=Z(A,e,t)*l%t,B=Z(w,o,t)*d%t,C=Z(B,n,t)*u%t,U=Z(C,Fo,t);if(!Ns.eql(Ns.sqr(U),r))throw new Error("Cannot find square root");return U}var Ns=De(Ks.p,{sqrt:Uu}),Mu=Oo(Ks,{Fp:Ns,endo:Ku}),Ne=Ho(Mu,Be);function zo(r,t,e,n){let s=se.digest(e instanceof Uint8Array?e:e.subarray());if(Cr(s))return s.then(({digest:i})=>(n?.signal?.throwIfAborted(),Ne.verify(t,i,r,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Je(String(i))});try{return n?.signal?.throwIfAborted(),Ne.verify(t,s.digest,r,{prehash:!1,format:"der"})}catch(i){throw new Je(String(i))}}var Vr=class{type="secp256k1";raw;_key;constructor(t){this._key=Zo(t),this.raw=$o(this._key)}toMultihash(){return At.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e,n){return zo(this._key,e,t,n)}};function Us(r){return new Vr(r)}function $o(r){return Ne.Point.fromBytes(r).toBytes()}function Zo(r){try{return Ne.Point.fromBytes(r),r}catch(t){throw new ye(String(t))}}function Ms(r,t){let{Type:e,Data:n}=Rt.decode(r),s=n??new Uint8Array;switch(e){case tt.RSA:return _s(s,t);case tt.Ed25519:return es(s);case tt.secp256k1:return Us(s);case tt.ECDSA:return Tn(s);default:throw new re}}function Go(r){let{Type:t,Data:e}=Rt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return es(n);case tt.secp256k1:return Us(n);case tt.ECDSA:return Tn(n);default:throw new re}}function Nt(r){return Rt.encode({Type:tt[r.type],Data:r.raw})}var Yo=Symbol.for("nodejs.util.inspect.custom"),Ou=114,nr=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()})`}[en]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Ou,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return pt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return pt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Yo](){return`PeerId(${this.toString()})`}},sr=class extends nr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},ir=class extends nr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},or=class extends nr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},qu=2336,Hr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(F(this.url))}[Yo](){return`PeerId(${this.url})`}[en]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(qu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};function Os(r){if(r.type==="Ed25519")return new ir({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new or({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new sr({multihash:r.toCID().multihash,publicKey:r});throw new re}function jo(r){return Os(r.publicKey)}function ar(r){if(Hu(r))return new sr({multihash:r});if(Vu(r))try{let t=Go(r);if(t.type==="Ed25519")return new ir({multihash:r,publicKey:t});if(t.type==="secp256k1")return new or({multihash:r,publicKey:t})}catch{let e=H(r.digest);return new Hr(new URL(e))}throw new yr("Supplied PeerID Multihash is invalid")}function Vu(r){return r.code===At.code}function Hu(r){return r.code===se.code}function pe(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:t(s)}}};return e}function Fr(r){let t=$t(G.decode(`z${r}`));return ar(t)}var cr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return pe(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return pe(this.map.values(),t=>t.key)}values(){return pe(this.map.values(),t=>t.value)}get size(){return this.map.size}};var ur=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return pe(this.set.entries(),t=>{let e=Fr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Fr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return pe(this.set.values(),t=>Fr(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};var qs=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},Xo=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function fr(r,t){let{milliseconds:e,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=t,a,c,l=new Promise((f,y)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(o?.aborted){y(Xo(o));return}if(o&&(c=()=>{y(Xo(o))},o.addEventListener("abort",c,{once:!0})),r.then(f,y),e===Number.POSITIVE_INFINITY)return;let b=new qs;a=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){y(d)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?f():s instanceof Error?y(s):(b.message=s??`Promise timed out after ${e} milliseconds`,y(b))},e)}).finally(()=>{l.clear(),c&&o&&o.removeEventListener("abort",c)});return l.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},l}var Fu=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function zu(r,t,e){let n,s=new Promise((i,o)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:l}=Fu(r),f=async(...b)=>{let d=e.multiArgs?b:b[0];if(e.filter)try{if(!await e.filter(d))return}catch(I){n(),o(I);return}c.push(d),e.count===c.length&&(n(),i(c))},y=(...b)=>{n(),o(e.rejectionMultiArgs?b:b[0])};n=()=>{for(let b of a)l(b,f);for(let b of e.rejectionEvents)a.includes(b)||l(b,y)};for(let b of a)u(b,f);for(let b of e.rejectionEvents)a.includes(b)||u(b,y);e.signal&&e.signal.addEventListener("abort",()=>{y(e.signal.reason)},{once:!0}),e.resolveImmediately&&i(c)});if(s.cancel=n,typeof e.timeout=="number"){let i=fr(s,{milliseconds:e.timeout});return i.cancel=()=>{n(),i.clear()},i}return s}function Wo(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=zu(r,t,e),s=n.then(i=>i[0]);return s.cancel=n.cancel,s}var me=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function $u(r){return r.reason}async function Vs(r,t,e){if(t==null)return r;let n=e?.translateError??$u;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let s;try{return await Promise.race([r,new Promise((i,o)=>{s=()=>{o(n(t))},t.addEventListener("abort",s)})])}finally{s!=null&&t.removeEventListener("abort",s)}}var Gu=4194304,zr=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Fs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},zs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},$s=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Yu(r){return typeof r?.closeRead=="function"}function ju(r){return typeof r?.close=="function"}function Hs(r){return Yu(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:ju(r)?r.status!=="open":!1}function Xu(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Wu(r,t){let e=t?.maxBufferSize??Gu,n=new et,s,i=!1;if(!Xu(r))throw new z("Argument should be a Stream or a Multiaddr");let o=l=>{if(n.append(l.data),n.byteLength>e){let f=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${f} > ${e}`))}s?.resolve()};r.addEventListener("message",o);let a=l=>{l.error!=null?s?.reject(l.error):s?.resolve()};r.addEventListener("close",a);let c=()=>{s?.resolve()};r.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(l){if(i===!0)throw new zr("Stream was unwrapped");if(Hs(r)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new me(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let f=l?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=f){s.resolve();break}if(await Vs(s.promise,l?.signal),Hs(r)){if(n.byteLength===0&&l?.bytes==null)return null;break}s=Promise.withResolvers()}let y=l?.bytes??n.byteLength;if(n.byteLength<y){if(Hs(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,y),new me(`Unexpected EOF - stream closed while reading ${n.byteLength}/${y} bytes`);return u.read(l)}let b=n.sublist(0,y);return n.consume(y),b},async write(l,f){if(i===!0)throw new zr("Stream was unwrapped");r.send(l)||await Wo(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,r.removeEventListener("message",o),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return u}function Ju(r,t={}){let e=Wu(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ht(t.maxDataLength));let n=t?.lengthDecoder??xo,s=t?.lengthEncoder??wo;return{async read(o){let a=-1,c=new et;for(;;){let l=await e.read({...o,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new Fs("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new $s(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new zs(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await e.read({...o,bytes:a});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new me(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new me(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(o,a){await e.write(new et(s(o.byteLength),o),a)},async writeV(o,a){let c=new et(...o.flatMap(u=>[s(u.byteLength),u]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function Zs(r,t){let e=Ju(r,t),n={read:async(s,i)=>{let o=await e.read(i);return s.decode(o)},write:async(s,i,o)=>{await e.write(i.encode(s),o)},writeV:async(s,i,o)=>{await e.writeV(s.map(a=>i.encode(a)),o)},pb:s=>({read:async i=>n.read(s,i),write:async(i,o)=>n.write(i,s,o),writeV:async(i,o)=>n.writeV(i,s,o),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Ys=da(Qo(),1);function js(r,t,e){let n=0,s=r.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;e(r[o],t)<=0?(n=++o,s-=i+1):s=i}return n}var hr=class{#t=[];enqueue(t,e){let{priority:n=0,id:s}=e??{},i={priority:n,id:s,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let o=js(this.#t,i,(a,c)=>c.priority-a.priority);this.#t.splice(o,0,i)}setPriority(t,e){let n=this.#t.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[s]=this.#t.splice(n,1);this.enqueue(s.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var dr=class extends Ys.default{#t;#o;#a=0;#d;#m=!1;#g=!1;#c;#B=0;#w=0;#u;#f;#i;#s=[];#n=0;#e;#L;#r=0;#b;#l;#k=1n;#y=new Map;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:hr,strict:!1,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#o=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#c=t.interval,this.#i=t.strict,this.#e=new t.queueClass,this.#L=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#q()}#x(t){for(;this.#n<this.#s.length;){let n=this.#s[this.#n];if(n!==void 0&&t-n>=this.#c)this.#n++;else break}(this.#n>100&&this.#n>this.#s.length/2||this.#n===this.#s.length)&&(this.#s=this.#s.slice(this.#n),this.#n=0)}#C(t){this.#i?this.#s.push(t):this.#a++}#P(){this.#i?this.#s.length>this.#n&&this.#s.pop():this.#a>0&&this.#a--}#E(){return this.#s.length-this.#n}get#N(){return this.#o?!0:this.#i?this.#E()<this.#d:this.#a<this.#d}get#K(){return this.#r<this.#b}#U(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#A(),this.emit("next")}#M(){this.#f=void 0,this.#T(),this.#D()}#O(t){if(this.#i){if(this.#x(t),this.#E()>=this.#d){let n=this.#s[this.#n],s=this.#c-(t-n);return this.#v(s),!0}return!1}if(this.#u===void 0){let e=this.#B-t;if(e<0){if(this.#w>0){let n=t-this.#w;if(n<this.#c)return this.#v(this.#c-n),!0}this.#a=this.#t?this.#r:0}else return this.#v(e),!0}return!1}#v(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#M()},t))}#S(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#_(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#A(){if(this.#e.size===0){if(this.#S(),this.emit("empty"),this.#r===0){if(this.#_(),this.#i&&this.#n>0){let e=Date.now();this.#x(e)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let e=Date.now(),n=!this.#O(e);if(this.#N&&this.#K){let s=this.#e.dequeue();this.#o||(this.#C(e),this.#p()),this.emit("active"),s(),n&&this.#D(),t=!0}}return t}#D(){this.#o||this.#u!==void 0||this.#i||(this.#u=setInterval(()=>{this.#T()},this.#c),this.#B=Date.now()+this.#c)}#T(){this.#i||(this.#a===0&&this.#r===0&&this.#u&&this.#S(),this.#a=this.#t?this.#r:0),this.#I(),this.#p()}#I(){for(;this.#A(););}get concurrency(){return this.#b}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#b=t,this.#I()}setPriority(t,e){if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${e}\` (${typeof e})`);this.#e.setPriority(t,e)}async add(t,e={}){return e={timeout:this.timeout,...e,id:e.id??(this.#k++).toString()},new Promise((n,s)=>{let i=Symbol(`task-${e.id}`);this.#e.enqueue(async()=>{this.#r++,this.#y.set(i,{id:e.id,priority:e.priority??0,startTime:Date.now(),timeout:e.timeout});let o;try{try{e.signal?.throwIfAborted()}catch(u){throw this.#V(),this.#y.delete(i),u}this.#w=Date.now();let a=t({signal:e.signal});if(e.timeout&&(a=fr(Promise.resolve(a),{milliseconds:e.timeout,message:`Task timed out after ${e.timeout}ms (queue has ${this.#r} running, ${this.#e.size} waiting)`})),e.signal){let{signal:u}=e;a=Promise.race([a,new Promise((l,f)=>{o=()=>{f(u.reason)},u.addEventListener("abort",o,{once:!0})})])}let c=await a;n(c),this.emit("completed",c)}catch(a){s(a),this.emit("error",a)}finally{o&&e.signal?.removeEventListener("abort",o),this.#y.delete(i),queueMicrotask(()=>{this.#U()})}},e),this.emit("add"),this.#A()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#l?(this.#l=!1,this.#I(),this):this}pause(){this.#l=!0}clear(){this.#e=new this.#L,this.#S(),this.#R(),this.emit("empty"),this.#r===0&&(this.#_(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#r===0&&this.#e.size===0||await this.#h("idle")}async onPendingZero(){this.#r!==0&&await this.#h("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#h("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#h("rateLimitCleared")}onError(){return new Promise((t,e)=>{let n=s=>{this.off("error",n),e(s)};this.on("error",n)})}async#h(t,e){return new Promise(n=>{let s=()=>{e&&!e()||(this.off(t,s),n())};this.on(t,s)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#r}get isPaused(){return this.#l}#q(){this.#o||(this.on("add",()=>{this.#e.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#o||this.#g||(this.#g=!0,queueMicrotask(()=>{this.#g=!1,this.#R()}))}#V(){this.#o||(this.#P(),this.#p())}#R(){let t=this.#m;if(this.#o||this.#e.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let e;if(this.#i){let s=Date.now();this.#x(s),e=this.#E()}else e=this.#a;let n=e>=this.#d;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#r===this.#b&&this.#e.size>0||this.isRateLimited&&this.#e.size>0}get runningTasks(){return[...this.#y.values()].map(t=>({...t}))}};var Zr=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,e){this.entries.set(t,{value:e,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[e,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(e);else break}}has(t){return this.entries.has(t)}get(t){let e=this.entries.get(t);return e!=null&&e.validUntilMs>=Date.now()?e.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var be;(function(r){let t;(function(s){let i;s.codec=()=>(i==null&&(i=xt((o,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),o.subscribe!=null&&(a.uint32(8),a.bool(o.subscribe)),o.topic!=null&&(a.uint32(18),a.string(o.topic)),c.lengthDelimited!==!1&&a.ldelim()},(o,a,c={})=>{let u={},l=a==null?o.len:o.pos+a;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{u.subscribe=o.bool();break}case 2:{u.topic=o.string();break}default:{o.skipType(f&7);break}}}return u})),i),s.encode=o=>wt(o,s.codec()),s.decode=(o,a)=>gt(o,s.codec(),a)})(t=r.SubOpts||(r.SubOpts={}));let e;(function(s){let i;s.codec=()=>(i==null&&(i=xt((o,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),o.from!=null&&(a.uint32(10),a.bytes(o.from)),o.data!=null&&(a.uint32(18),a.bytes(o.data)),o.sequenceNumber!=null&&(a.uint32(26),a.bytes(o.sequenceNumber)),o.topic!=null&&(a.uint32(34),a.string(o.topic)),o.signature!=null&&(a.uint32(42),a.bytes(o.signature)),o.key!=null&&(a.uint32(50),a.bytes(o.key)),c.lengthDelimited!==!1&&a.ldelim()},(o,a,c={})=>{let u={},l=a==null?o.len:o.pos+a;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{u.from=o.bytes();break}case 2:{u.data=o.bytes();break}case 3:{u.sequenceNumber=o.bytes();break}case 4:{u.topic=o.string();break}case 5:{u.signature=o.bytes();break}case 6:{u.key=o.bytes();break}default:{o.skipType(f&7);break}}}return u})),i),s.encode=o=>wt(o,s.codec()),s.decode=(o,a)=>gt(o,s.codec(),a)})(e=r.Message||(r.Message={}));let n;r.codec=()=>(n==null&&(n=xt((s,i,o={})=>{if(o.lengthDelimited!==!1&&i.fork(),s.subscriptions!=null)for(let a of s.subscriptions)i.uint32(10),r.SubOpts.codec().encode(a,i);if(s.messages!=null)for(let a of s.messages)i.uint32(18),r.Message.codec().encode(a,i);s.control!=null&&(i.uint32(26),Gr.codec().encode(s.control,i)),o.lengthDelimited!==!1&&i.ldelim()},(s,i,o={})=>{let a={subscriptions:[],messages:[]},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{if(o.limits?.subscriptions!=null&&a.subscriptions.length===o.limits.subscriptions)throw new St('Decode error - map field "subscriptions" had too many elements');a.subscriptions.push(r.SubOpts.codec().decode(s,s.uint32(),{limits:o.limits?.subscriptions$}));break}case 2:{if(o.limits?.messages!=null&&a.messages.length===o.limits.messages)throw new St('Decode error - map field "messages" had too many elements');a.messages.push(r.Message.codec().decode(s,s.uint32(),{limits:o.limits?.messages$}));break}case 3:{a.control=Gr.codec().decode(s,s.uint32(),{limits:o.limits?.control});break}default:{s.skipType(u&7);break}}}return a})),n),r.encode=s=>wt(s,r.codec()),r.decode=(s,i)=>gt(s,r.codec(),i)})(be||(be={}));var Gr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.ihave!=null)for(let i of e.ihave)n.uint32(10),Yr.codec().encode(i,n);if(e.iwant!=null)for(let i of e.iwant)n.uint32(18),jr.codec().encode(i,n);if(e.graft!=null)for(let i of e.graft)n.uint32(26),Xr.codec().encode(i,n);if(e.prune!=null)for(let i of e.prune)n.uint32(34),Wr.codec().encode(i,n);s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={ihave:[],iwant:[],graft:[],prune:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{if(s.limits?.ihave!=null&&i.ihave.length===s.limits.ihave)throw new St('Decode error - map field "ihave" had too many elements');i.ihave.push(Yr.codec().decode(e,e.uint32(),{limits:s.limits?.ihave$}));break}case 2:{if(s.limits?.iwant!=null&&i.iwant.length===s.limits.iwant)throw new St('Decode error - map field "iwant" had too many elements');i.iwant.push(jr.codec().decode(e,e.uint32(),{limits:s.limits?.iwant$}));break}case 3:{if(s.limits?.graft!=null&&i.graft.length===s.limits.graft)throw new St('Decode error - map field "graft" had too many elements');i.graft.push(Xr.codec().decode(e,e.uint32(),{limits:s.limits?.graft$}));break}case 4:{if(s.limits?.prune!=null&&i.prune.length===s.limits.prune)throw new St('Decode error - map field "prune" had too many elements');i.prune.push(Wr.codec().decode(e,e.uint32(),{limits:s.limits?.prune$}));break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Gr||(Gr={}));var Yr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.messageIDs!=null)for(let i of e.messageIDs)n.uint32(18),n.bytes(i);s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={messageIDs:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.topic=e.string();break}case 2:{if(s.limits?.messageIDs!=null&&i.messageIDs.length===s.limits.messageIDs)throw new St('Decode error - map field "messageIDs" had too many elements');i.messageIDs.push(e.bytes());break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Yr||(Yr={}));var jr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.messageIDs!=null)for(let i of e.messageIDs)n.uint32(10),n.bytes(i);s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={messageIDs:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{if(s.limits?.messageIDs!=null&&i.messageIDs.length===s.limits.messageIDs)throw new St('Decode error - map field "messageIDs" had too many elements');i.messageIDs.push(e.bytes());break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(jr||(jr={}));var Xr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.topic=e.string();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Xr||(Xr={}));var Wr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.peers!=null)for(let i of e.peers)n.uint32(18),Jr.codec().encode(i,n);e.backoff!=null&&(n.uint32(24),n.uint64(e.backoff)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={peers:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.topic=e.string();break}case 2:{if(s.limits?.peers!=null&&i.peers.length===s.limits.peers)throw new St('Decode error - map field "peers" had too many elements');i.peers.push(Jr.codec().decode(e,e.uint32(),{limits:s.limits?.peers$}));break}case 3:{i.backoff=e.uint64();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Wr||(Wr={}));var Jr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.peerID!=null&&(n.uint32(10),n.bytes(e.peerID)),e.signedPeerRecord!=null&&(n.uint32(18),n.bytes(e.signedPeerRecord)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.peerID=e.bytes();break}case 2:{i.signedPeerRecord=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Jr||(Jr={}));var Qr=class extends ge{peerId;shutDownController;inboundPb;outboundPb;constructor(t){super(),this.peerId=t,this.shutDownController=new AbortController}attachInboundStream(t,e){this.inboundPb=Zs(t,e).pb(be),Promise.resolve().then(async()=>{for(;;){if(this.inboundPb==null)return;let n=await this.inboundPb.read({signal:this.shutDownController.signal});this.safeDispatchEvent("message",{detail:n})}}).catch(n=>{this.inboundPb?.unwrap().unwrap().abort(n)})}attachOutboundStream(t,e){this.outboundPb=Zs(t,e).pb(be)}write(t){this.outboundPb!=null&&this.outboundPb.write(t,{signal:this.shutDownController.signal}).catch(e=>{this.outboundPb?.unwrap().unwrap().abort(e)})}close(){this.shutDownController.abort(),Promise.all([this.inboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)}),this.outboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)})]).finally(()=>{this.safeDispatchEvent("close")})}};function ta(){return BigInt(`0x${H(Mr(8),"base16")}`)}var ea=(r,t)=>{let e=F(t.toString(16).padStart(16,"0"),"base16"),n=Nt(r),s=new Uint8Array(n.byteLength+e.length);return s.set(n,0),s.set(e,n.byteLength),s},ra=r=>se.encode(r);var ef=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=ar($t(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return Os(Ms(e)).equals(t)}return!1},na=async r=>{if(r.from==null)throw new J("RPC message was missing from");if(!await ef(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=ar($t(r.from)),e=r.key??t.publicKey;if(e==null)throw new J("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:nf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?Ms(e):e}},pr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:rf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Nt(r.key):void 0}:{data:r.data,topic:r.topic},rf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},nf=r=>BigInt(`0x${H(r,"base16")}`);var sa=F("libp2p-pubsub:");async function ia(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:jo(r)},s=ne([sa,e(pr(n)).subarray()]);return n.signature=await r.sign(s),n.key=r.publicKey,n}async function oa(r,t){if(r.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(r.signature==null)throw new Error("Message must contain a signature to be verified");if(r.from==null)throw new Error("Message must contain a from property to be verified");let e=ne([sa,t({...pr(r),signature:void 0,key:void 0}).subarray()]);return sf(r).verify(e,r.signature)}function sf(r){if(r.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(r.from==null)throw new Error("Could not get the public key from the originator id");if(r.key!=null)return r.key;if(r.from.publicKey!=null)return r.from.publicKey;throw new Error("Could not get the public key from the originator id")}var tn=class extends ge{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocol=e.protocol??Xs,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new cr,this.globalSignaturePolicy=e.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=e.canRelayMessage??!0,this.emitSelf=e.emitSelf??!1,this.topicValidators=new Map,this.queue=new dr({concurrency:e.messageProcessingConcurrency??10}),this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.seenCache=new Zr({validityMs:e?.seenTTL??3e4}),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[Ue]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[ti]=["@libp2p/pubsub"];[ei]=["@libp2p/identify"];async start(){this.started||(this.log("starting"),await this.components.registrar.handle(this.protocol,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this._registrarTopologyId=await this.components.registrar.register(this.protocol,{onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected}),this.log("started"),this.started=!0)}async stop(){if(!this.started)return;let t=this.components.registrar;this._registrarTopologyId!=null&&t.unregister(this._registrarTopologyId),await t.unhandle(this.protocol),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t,e){this.addPeer(e.remotePeer,t).attachInboundStream(t)}async _onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(i=>i.direction==="outbound"&&i.protocol===this.protocol)){this.log("outbound pubsub stream already present on connection from %p",t);return}let n=await e.newStream(this.protocol);this.addPeer(t,n).attachOutboundStream(n),this.send(t,{subscriptions:Array.from(this.subscriptions).map(i=>i.toString()),subscribe:!0})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let s=new Qr(t);return this.peers.set(t,s),s.addEventListener("message",i=>{let o=i.detail,a=[];for(let c of o.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(s,{subscriptions:(o.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}),s.addEventListener("close",()=>this._removePeer(t),{once:!0}),s}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t)}}async processRpc(t,e){this.log("rpc from %p",t.peerId);let{subscriptions:n,messages:s}=e;return n!=null&&n.length>0&&(this.log("subscription update from %p",t.peerId),n.forEach(i=>{this.processRpcSubOpt(t.peerId,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:t.peerId,subscriptions:n.map(({topic:i,subscribe:o})=>({topic:`${i??""}`,subscribe:!!o}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t.peerId),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let o=await na(i);await this.processMessage(t.peerId,o)}catch(o){this.log.error("failed to queue messages from %p - %e",t.peerId,o)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let s=this.topics.get(n);s==null&&(s=new ur,this.topics.set(n,s)),e.subscribe===!0?s.add(t):s.delete(t)}async processMessage(t,e){if(this.components.peerId.equals(t)&&!this.emitSelf)return;let n=await this.getMsgId(e),s=H(n,"base64");if(!this.seenCache.has(s)){this.seenCache.put(s,!0);try{await this.validate(t,e)}catch(i){this.log("Message is invalid, dropping it. %O",i);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new J("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new J("Need key when signature policy is StrictSign but it was missing");return ea(t.key,t.sequenceNumber);case"StrictNoSign":return ra(t.data);default:throw new J("Cannot get message id: unhandled signature policy")}}encodeMessage(t){return be.Message.encode(t)}send(t,e){let{messages:n,subscriptions:s,subscribe:i}=e;this.sendRpc(t,{subscriptions:(s??[]).map(o=>({topic:o,subscribe:!!i})),messages:(n??[]).map(pr)})}sendRpc(t,e){let n=this.peers.get(t);if(n==null){this.log.error("cannot send RPC to %p as there are no streams to it available",t);return}n.write(e)}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new J('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new J("StrictNoSigning: signature should not be present");if(e.key!=null)throw new J("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new J("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new J("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new J("StrictSigning: Signing required and no sequenceNumber was present");if(!await oa(e,this.encodeMessage.bind(this)))throw new J("StrictSigning: Invalid message signature");break;default:throw new J("Cannot validate message: unhandled signature policy")}let s=this.topicValidators.get(e.topic);if(s!=null){let i=await s(t,e);if(i===Ke.Reject||i===Ke.Ignore)throw new J("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return ia(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new J("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new gr("not started yet");if(t==null)throw new z("Topic is required");let e=this.topics.get(t.toString());return e==null?[]:Array.from(e.values())}async publish(t,e){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:e??new Uint8Array(0),sequenceNumber:ta()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let s=await this.buildMessage(n),i=!1;this.emitSelf&&this.subscriptions.has(t)&&(i=!0,super.dispatchEvent(new CustomEvent("message",{detail:s})));let o=await this.publishMessage(this.components.peerId,s);return i&&(o.recipients=[...o.recipients,this.components.peerId]),o}async publishMessage(t,e){let n=this.getSubscribers(e.topic),s=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",e.topic),{recipients:s}):(n.forEach(i=>{if(this.components.peerId.equals(i)){this.log("not sending message on topic %s to myself",e.topic);return}if(i.equals(t)){this.log("not sending message on topic %s to sender %p",e.topic,i);return}this.log("publish msgs on topics %s %p",e.topic,i),s.push(i),this.send(i,{messages:[e]})}),{recipients:s})}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(!this.subscriptions.has(t)){this.log("subscribe to topic: %s",t),this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");if(this.subscriptions.has(t)){this.log("unsubscribe from %s",t),this.subscriptions.delete(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};var Xs="/floodsub/1.0.0",of="StrictSign",af="StrictNoSign",Ke;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ke||(Ke={}));function cf(r){return!!r?.[Ue]}function uf(r={}){return t=>new tn(t,r)}return pa(ff);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/utils.js: