@libp2p/floodsub 11.0.15 → 11.0.16-2151144c3

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 ca=Object.create;var Sr=Object.defineProperty;var ua=Object.getOwnPropertyDescriptor;var fa=Object.getOwnPropertyNames;var la=Object.getPrototypeOf,ha=Object.prototype.hasOwnProperty;var da=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),pt=(e,t)=>{for(var r in t)Sr(e,r,{get:t[r],enumerable:!0})},ti=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of fa(t))!ha.call(e,i)&&i!==r&&Sr(e,i,{get:()=>t[i],enumerable:!(n=ua(t,i))||n.enumerable});return e};var pa=(e,t,r)=>(r=e!=null?ca(la(e)):{},ti(t||!e||!e.__esModule?Sr(r,"default",{value:e,enumerable:!0}):r,e)),ma=e=>ti(Sr({},"__esModule",{value:!0}),e);var ta=da((g0,Gs)=>{"use strict";var tf=Object.prototype.hasOwnProperty,dt="~";function hr(){}Object.create&&(hr.prototype=Object.create(null),new hr().__proto__||(dt=!1));function ef(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function Qo(e,t,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new ef(r,n||e,i),o=dt?dt+t:t;return e._events[o]?e._events[o].fn?e._events[o]=[e._events[o],s]:e._events[o].push(s):(e._events[o]=s,e._eventsCount++),e}function Qr(e,t){--e._eventsCount===0?e._events=new hr:delete e._events[t]}function lt(){this._events=new hr,this._eventsCount=0}lt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)tf.call(r,n)&&t.push(dt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};lt.prototype.listeners=function(t){var r=dt?dt+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,o=new Array(s);i<s;i++)o[i]=n[i].fn;return o};lt.prototype.listenerCount=function(t){var r=dt?dt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};lt.prototype.emit=function(t,r,n,i,s,o){var c=dt?dt+t:t;if(!this._events[c])return!1;var a=this._events[c],u=arguments.length,f,h;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),u){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,r),!0;case 3:return a.fn.call(a.context,r,n),!0;case 4:return a.fn.call(a.context,r,n,i),!0;case 5:return a.fn.call(a.context,r,n,i,s),!0;case 6:return a.fn.call(a.context,r,n,i,s,o),!0}for(h=1,f=new Array(u-1);h<u;h++)f[h-1]=arguments[h];a.fn.apply(a.context,f)}else{var l=a.length,d;for(h=0;h<l;h++)switch(a[h].once&&this.removeListener(t,a[h].fn,void 0,!0),u){case 1:a[h].fn.call(a[h].context);break;case 2:a[h].fn.call(a[h].context,r);break;case 3:a[h].fn.call(a[h].context,r,n);break;case 4:a[h].fn.call(a[h].context,r,n,i);break;default:if(!f)for(d=1,f=new Array(u-1);d<u;d++)f[d-1]=arguments[d];a[h].fn.apply(a[h].context,f)}}return!0};lt.prototype.on=function(t,r,n){return Qo(this,t,r,n,!1)};lt.prototype.once=function(t,r,n){return Qo(this,t,r,n,!0)};lt.prototype.removeListener=function(t,r,n,i){var s=dt?dt+t:t;if(!this._events[s])return this;if(!r)return Qr(this,s),this;var o=this._events[s];if(o.fn)o.fn===r&&(!i||o.once)&&(!n||o.context===n)&&Qr(this,s);else{for(var c=0,a=[],u=o.length;c<u;c++)(o[c].fn!==r||i&&!o[c].once||n&&o[c].context!==n)&&a.push(o[c]);a.length?this._events[s]=a.length===1?a[0]:a:Qr(this,s)}return this};lt.prototype.removeAllListeners=function(t){var r;return t?(r=dt?dt+t:t,this._events[r]&&Qr(this,r)):(this._events=new hr,this._eventsCount=0),this};lt.prototype.off=lt.prototype.removeListener;lt.prototype.addListener=lt.prototype.on;lt.prefixed=dt;lt.EventEmitter=lt;typeof Gs<"u"&&(Gs.exports=lt)});var lf={};pt(lf,{StrictNoSign:()=>cf,StrictSign:()=>af,TopicValidatorResult:()=>Ke,floodsub:()=>ff,isPubSub:()=>uf,protocol:()=>Ws,pubSubSymbol:()=>Ue});var Ue=Symbol.for("@libp2p/pubsub");var F=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ge=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ar=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Q=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Ir=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ne=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var nn=Symbol.for("@libp2p/peer-id");var we=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let i=this.#t.get(t);i==null&&(i=[],this.#t.set(t,i)),i.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let i=this.#t.get(t);i!=null&&(i=i.filter(({callback:s})=>s!==r),this.#t.set(t,i))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:i})=>!i),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var ei=Symbol.for("@libp2p/service-capabilities"),ri=Symbol.for("@libp2p/service-dependencies");var un={};pt(un,{base58btc:()=>Y,base58flickr:()=>va});var Hf=new Uint8Array(0);function ni(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Ct(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function si(e){return new TextEncoder().encode(e)}function ii(e){return new TextDecoder().decode(e)}function ba(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<e.length;i++){var s=e.charAt(i),o=s.charCodeAt(0);if(r[o]!==255)throw new TypeError(s+" is ambiguous");r[o]=i}var c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function h(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 v=0,S=0,b=0,I=p.length;b!==I&&p[b]===0;)b++,v++;for(var w=(I-b)*f+1>>>0,B=new Uint8Array(w);b!==I;){for(var C=p[b],U=0,M=w-1;(C!==0||U<S)&&M!==-1;M--,U++)C+=256*B[M]>>>0,B[M]=C%c>>>0,C=C/c>>>0;if(C!==0)throw new Error("Non-zero carry");S=U,b++}for(var E=w-S;E!==w&&B[E]===0;)E++;for(var x=a.repeat(v);E<w;++E)x+=e.charAt(B[E]);return x}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var v=0;if(p[v]!==" "){for(var S=0,b=0;p[v]===a;)S++,v++;for(var I=(p.length-v)*u+1>>>0,w=new Uint8Array(I);p[v];){var B=r[p.charCodeAt(v)];if(B===255)return;for(var C=0,U=I-1;(B!==0||C<b)&&U!==-1;U--,C++)B+=c*w[U]>>>0,w[U]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");b=C,v++}if(p[v]!==" "){for(var M=I-b;M!==I&&w[M]===0;)M++;for(var E=new Uint8Array(S+(I-M)),x=S;M!==I;)E[x++]=w[M++];return E}}}function d(p){var v=l(p);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:l,decode:d}}var ya=ba,ga=ya,ai=ga;var sn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},on=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,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 ci(this,t)}},an=class{decoders;constructor(t){this.decoders=t}or(t){return ci(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ci(e,t){return new an({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var cn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,i){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new sn(t,r,n),this.decoder=new on(t,r,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function xe({name:e,prefix:t,encode:r,decode:n}){return new cn(e,t,r,n)}function zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:i}=ai(r,e);return xe({prefix:t,name:e,encode:n,decode:s=>Ct(i(s))})}function wa(e,t,r,n){let i=e.length;for(;e[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),o=0,c=0,a=0;for(let u=0;u<i;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|f,o+=r,o>=8&&(o-=8,s[a++]=255&c>>o)}if(o>=r||(255&c<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return s}function xa(e,t,r){let n=t[t.length-1]==="=",i=(1<<r)-1,s="",o=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],o+=8;o>r;)o-=r,s+=t[i&c>>o];if(o!==0&&(s+=t[i&c<<r-o]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Ea(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function J({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let i=Ea(n);return xe({prefix:t,name:e,encode(s){return xa(s,n,r)},decode(s){return wa(s,i,r,e)}})}var Y=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),va=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var fn={};pt(fn,{base32:()=>Ee,base32hex:()=>Ba,base32hexpad:()=>Da,base32hexpadupper:()=>_a,base32hexupper:()=>La,base32pad:()=>Aa,base32padupper:()=>Ia,base32upper:()=>Sa,base32z:()=>Ta});var Ee=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Sa=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Aa=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ia=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ba=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),La=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Da=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),_a=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ta=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ln={};pt(ln,{base36:()=>Me,base36upper:()=>ka});var Me=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ka=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ra=li,ui=128,Ca=127,Pa=~Ca,Na=Math.pow(2,31);function li(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Na;)t[r++]=e&255|ui,e/=128;for(;e&Pa;)t[r++]=e&255|ui,e>>>=7;return t[r]=e|0,li.bytes=r-n+1,t}var Ka=hn,Ua=128,fi=127;function hn(e,n){var r=0,n=n||0,i=0,s=n,o,c=e.length;do{if(s>=c)throw hn.bytes=0,new RangeError("Could not decode varint");o=e[s++],r+=i<28?(o&fi)<<i:(o&fi)*Math.pow(2,i),i+=7}while(o>=Ua);return hn.bytes=s-n,r}var Ma=Math.pow(2,7),Oa=Math.pow(2,14),qa=Math.pow(2,21),Va=Math.pow(2,28),Ha=Math.pow(2,35),$a=Math.pow(2,42),Fa=Math.pow(2,49),za=Math.pow(2,56),Za=Math.pow(2,63),Ya=function(e){return e<Ma?1:e<Oa?2:e<qa?3:e<Va?4:e<Ha?5:e<$a?6:e<Fa?7:e<za?8:e<Za?9:10},Ga={encode:Ra,decode:Ka,encodingLength:Ya},ja=Ga,Oe=ja;function qe(e,t=0){return[Oe.decode(e,t),Oe.decode.bytes]}function ve(e,t,r=0){return Oe.encode(e,t,r),t}function Se(e){return Oe.encodingLength(e)}function _t(e,t){let r=t.byteLength,n=Se(e),i=n+Se(r),s=new Uint8Array(i+r);return ve(e,s,0),ve(r,s,n),s.set(t,i),new Ae(e,r,t,s)}function Zt(e){let t=Ct(e),[r,n]=qe(t),[i,s]=qe(t.subarray(n)),o=t.subarray(n+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new Ae(r,i,o,t)}function hi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ni(e.bytes,r.bytes)}}var Ae=class{code;size;digest;bytes;constructor(t,r,n,i){this.code=t,this.size=r,this.digest=n,this.bytes=i}};function di(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Wa(r,dn(e),t??Y.encoder);default:return Ja(r,dn(e),t??Ee.encoder)}}var pi=new WeakMap;function dn(e){let t=pi.get(e);if(t==null){let r=new Map;return pi.set(e,r),r}return t}var ct=class e{code;version;multihash;bytes;"/";constructor(t,r,n,i){this.code=r,this.version=t,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ve)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Qa)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=_t(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&hi(t.multihash,n.multihash)}toString(t){return di(this,t)}toJSON(){return{"/":di(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:s,bytes:o}=r;return new e(n,i,s,o??mi(n,i,s.bytes))}else if(r[tc]===!0){let{version:n,multihash:i,code:s}=r,o=Zt(i);return e.create(n,s,o)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Ve)throw new Error(`Version 0 CID must use dag-pb (code: ${Ve}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let i=mi(t,r,n.bytes);return new e(t,r,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ve,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,i=Ct(t.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=i.subarray(r.multihashSize-r.digestSize),o=new Ae(r.multihashCode,r.digestSize,s,i);return[r.version===0?e.createV0(o):e.createV1(r.codec,o),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,l]=qe(t.subarray(r));return r+=l,h},i=n(),s=Ve;if(i===18?(i=0,r=0):s=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let o=r,c=n(),a=n(),u=r+a,f=u-o;return{version:i,codec:s,multihashCode:c,digestSize:a,multihashSize:f,size:u}}static parse(t,r){let[n,i]=Xa(t,r),s=e.decode(i);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return dn(s).set(n,t),s}};function Xa(e,t){switch(e[0]){case"Q":{let r=t??Y;return[Y.prefix,r.decode(`${Y.prefix}${e}`)]}case Y.prefix:{let r=t??Y;return[Y.prefix,r.decode(e)]}case Ee.prefix:{let r=t??Ee;return[Ee.prefix,r.decode(e)]}case Me.prefix:{let r=t??Me;return[Me.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Wa(e,t,r){let{prefix:n}=r;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=t.get(n);if(i==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return i}function Ja(e,t,r){let{prefix:n}=r,i=t.get(n);if(i==null){let s=r.encode(e);return t.set(n,s),s}else return i}var Ve=112,Qa=18;function mi(e,t,r){let n=Se(e),i=n+Se(t),s=new Uint8Array(i+r.byteLength);return ve(e,s,0),ve(t,s,n),s.set(r,i),s}var tc=Symbol.for("@ipld/js-cid/CID");var pn={};pt(pn,{identity:()=>It});var bi=0,ec="identity",yi=Ct;function rc(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return _t(bi,yi(e))}var It={code:bi,name:ec,encode:yi,digest:rc};function mt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Pt(e=0){return new Uint8Array(e)}function bt(e=0){return new Uint8Array(e)}function se(e,t){t==null&&(t=e.reduce((i,s)=>i+s.length,0));let r=bt(t),n=0;for(let i of e)r.set(i,n),n+=i.length;return r}var wi=Symbol.for("@achingbrain/uint8arraylist");function gi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let i=r+n.byteLength;if(t<i)return{buf:n,index:t-r};r=i}throw new RangeError("index is out of bounds")}function Lr(e){return!!e?.[wi]}var rt=class e{bufs;length;[wi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Lr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Lr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=gi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=gi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Lr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:i}=this._subList(t,r);return se(n,i)}subarray(t,r){let{bufs:n,length:i}=this._subList(t,r);return n.length===1?n[0]:se(n,i)}sublist(t,r){let{bufs:n,length:i}=this._subList(t,r),s=new e;return s.length=i,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let s=0;s<this.bufs.length;s++){let o=this.bufs[s],c=i,a=c+o.byteLength;if(i=a,t>=a)continue;let u=t>=c&&t<a,f=r>c&&r<=a;if(u&&f){if(t===c&&r===a){n.push(o);break}let h=t-c;n.push(o.subarray(h,h+(r-t)));break}if(u){if(t===0){n.push(o);continue}n.push(o.subarray(t-c));continue}if(f){if(r===a){n.push(o);break}n.push(o.subarray(0,r-c));break}n.push(o)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Lr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let s=256,o=new Int32Array(s);for(let h=0;h<s;h++)o[h]=-1;for(let h=0;h<i;h++)o[n[h]]=h;let c=o,a=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let h=r;h<=a;h+=f){f=0;for(let l=u;l>=0;l--){let d=this.get(h+l);if(n[l]!==d){f=Math.max(1,l-c[d]);break}}if(f===0)return h}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let i=Pt(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,r,n),this.write(i,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let i=Pt(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,r,n),this.write(i,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let i=Pt(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,r,n),this.write(i,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let i=Pt(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,r,n),this.write(i,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let i=Pt(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,r,n),this.write(i,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let i=Pt(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,r,n),this.write(i,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let i=Pt(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,r,n),this.write(i,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let i=Pt(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,r,n),this.write(i,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!mt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((i,s)=>i+s.byteLength,0)),n.length=r,n}};var mn={};pt(mn,{base10:()=>nc});var nc=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var bn={};pt(bn,{base16:()=>sc,base16upper:()=>ic});var sc=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ic=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var yn={};pt(yn,{base2:()=>oc});var oc=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var gn={};pt(gn,{base256emoji:()=>lc});var xi=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}"),ac=xi.reduce((e,t,r)=>(e[r]=t,e),[]),cc=xi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function uc(e){return e.reduce((t,r)=>(t+=ac[r],t),"")}function fc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=cc[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(i)}return new Uint8Array(t)}var lc=xe({prefix:"\u{1F680}",name:"base256emoji",encode:uc,decode:fc});var wn={};pt(wn,{base64:()=>hc,base64pad:()=>dc,base64url:()=>pc,base64urlpad:()=>mc});var hc=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),dc=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),pc=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),mc=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xn={};pt(xn,{base8:()=>bc});var bc=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var En={};pt(En,{identity:()=>yc});var yc=xe({prefix:"\0",name:"identity",encode:e=>ii(e),decode:e=>si(e)});var Il=new TextEncoder,Bl=new TextDecoder;var An={};pt(An,{sha256:()=>ie,sha512:()=>Ec});var xc=20;function Sn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:i}){return new vn(e,t,r,n,i)}var vn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,i,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=i??xc,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ei(n,this.code,r?.truncate):n.then(i=>Ei(i,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ei(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return _t(t,e)}function Si(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ie=Sn({name:"sha2-256",code:18,encode:Si("SHA-256")}),Ec=Sn({name:"sha2-512",code:19,encode:Si("SHA-512")});var In={...En,...yn,...xn,...mn,...bn,...fn,...ln,...un,...wn,...gn},Ml={...An,...pn};function Ii(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ai=Ii("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Bn=Ii("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=bt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),vc={utf8:Ai,"utf-8":Ai,hex:In.base16,latin1:Bn,ascii:Bn,binary:Bn,...In},Dr=vc;function $(e,t="utf8"){let r=Dr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function H(e,t="utf8"){let r=Dr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Sc=parseInt("11111",2),Ln=parseInt("10000000",2),Ac=parseInt("01111111",2),Bi={0:He,1:He,2:Ic,3:Dc,4:_c,5:Lc,6:Bc,16:He,22:He,48:He};function Nt(e,t={offset:0}){let r=e[t.offset]&Sc;if(t.offset++,Bi[r]!=null)return Bi[r](e,t);throw new Error("No decoder for tag "+r)}function $e(e,t){let r=0;if((e[t.offset]&Ln)===Ln){let n=e[t.offset]&Ac,i="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)i+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(i,16)}else r=e[t.offset],t.offset++;return r}function He(e,t){$e(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Nt(e,t);if(n===null)break;r.push(n)}return r}function Ic(e,t){let r=$e(e,t),n=t.offset,i=t.offset+r,s=[];for(let o=n;o<i;o++)o===n&&e[o]===0||s.push(e[o]);return t.offset+=r,Uint8Array.from(s)}function Bc(e,t){let r=$e(e,t),n=t.offset+r,i=e[t.offset];t.offset++;let s=0,o=0;i<40?(s=0,o=i):i<80?(s=1,o=i-40):(s=2,o=i-80);let c=`${s}.${o}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let f=0;for(let h=0;h<a.length;h++)f+=a[h]<<h*7;c+=`.${f}`,a=[]}}return c}function Lc(e,t){return t.offset++,null}function Dc(e,t){let r=$e(e,t),n=e[t.offset];t.offset++;let i=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return i}function _c(e,t){let r=$e(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Tc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new rt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Dn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Tc(e.byteLength);return new rt(Uint8Array.from([t.byteLength|Ln]),t)}function yt(e){let t=new rt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new rt(Uint8Array.from([2]),Dn(t),t)}function _r(e){let t=Uint8Array.from([0]),r=new rt(t,e);return new rt(Uint8Array.from([3]),Dn(r),r)}function Gt(e,t=48){let r=new rt;for(let n of e)r.append(n);return new rt(Uint8Array.from([t]),Dn(r),r)}async function Li(e,t,r,n){let i=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,t,r.subarray());return n?.signal?.throwIfAborted(),s}var kc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Rc=Uint8Array.from([6,5,43,129,4,0,34]),Cc=Uint8Array.from([6,5,43,129,4,0,35]),Pc={ext:!0,kty:"EC",crv:"P-256"},Nc={ext:!0,kty:"EC",crv:"P-384"},Kc={ext:!0,kty:"EC",crv:"P-521"},_n=32,Tn=48,kn=66;function Rn(e){let t=Nt(e);return Di(t)}function Di(e){let t=e[1][1][0],r=1,n,i;if(t.byteLength===_n*2+1)return n=H(t.subarray(r,r+_n),"base64url"),i=H(t.subarray(r+_n),"base64url"),new Ie({...Pc,key_ops:["verify"],x:n,y:i});if(t.byteLength===Tn*2+1)return n=H(t.subarray(r,r+Tn),"base64url"),i=H(t.subarray(r+Tn),"base64url"),new Ie({...Nc,key_ops:["verify"],x:n,y:i});if(t.byteLength===kn*2+1)return n=H(t.subarray(r,r+kn),"base64url"),i=H(t.subarray(r+kn),"base64url"),new Ie({...Kc,key_ops:["verify"],x:n,y:i});throw new F(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function _i(e){return Gt([yt(Uint8Array.from([1])),Gt([Uc(e.crv)],160),Gt([_r(new rt(Uint8Array.from([4]),$(e.x??"","base64url"),$(e.y??"","base64url")))],161)]).subarray()}function Uc(e){if(e==="P-256")return kc;if(e==="P-384")return Rc;if(e==="P-521")return Cc;throw new F(`Invalid curve ${e}`)}var Ie=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 It.digest(Kt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}async verify(t,r,n){return Li(this.jwk,r,t,n)}};function oe(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Tt(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function K(e,t,r=""){let n=oe(e),i=e?.length,s=t!==void 0;if(!n||s&&i!==t){let o=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${i}`:`type=${typeof e}`;throw new Error(o+"expected Uint8Array"+c+", got "+a)}return e}function Tr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Tt(e.outputLen),Tt(e.blockLen)}function Be(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function ki(e,t){K(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Mt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function kr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Bt(e,t){return e<<32-t|e>>>t}var Ri=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Mc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ot(e){if(K(e),Ri)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Mc[e[r]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ti(e){if(e>=Ut._0&&e<=Ut._9)return e-Ut._0;if(e>=Ut.A&&e<=Ut.F)return e-(Ut.A-10);if(e>=Ut.a&&e<=Ut.f)return e-(Ut.a-10)}function qt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ri)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let i=0,s=0;i<r;i++,s+=2){let o=Ti(e.charCodeAt(s)),c=Ti(e.charCodeAt(s+1));if(o===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[i]=o*16+c}return n}function gt(...e){let t=0;for(let n=0;n<e.length;n++){let i=e[n];K(i),t+=i.length}let r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){let s=e[n];r.set(s,i),i+=s.length}return r}function Cn(e,t={}){let r=(i,s)=>e(s).update(i).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=i=>e(i),Object.assign(r,t),Object.freeze(r)}function jt(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Pn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Ci(e,t,r){return e&t^~e&r}function Pi(e,t,r){return e&t^e&r^t&r}var Fe=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,i){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(t),this.view=kr(this.buffer)}update(t){Be(this),K(t);let{view:r,buffer:n,blockLen:i}=this,s=t.length;for(let o=0;o<s;){let c=Math.min(i-this.pos,s-o);if(c===i){let a=kr(t);for(;i<=s-o;o+=i)this.process(a,o);continue}n.set(t.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Be(this),ki(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:s}=this,{pos:o}=this;r[o++]=128,Mt(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(n,0),o=0);for(let h=o;h<i;h++)r[h]=0;n.setBigUint64(i-8,BigInt(this.length*8),s),this.process(n,0);let c=kr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)c.setUint32(4*h,f[h],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:c}=this;return t.destroyed=o,t.finished=s,t.length=i,t.pos=c,i%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Vt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Rr=BigInt(4294967295),Ni=BigInt(32);function Oc(e,t=!1){return t?{h:Number(e&Rr),l:Number(e>>Ni&Rr)}:{h:Number(e>>Ni&Rr)|0,l:Number(e&Rr)|0}}function Ki(e,t=!1){let r=e.length,n=new Uint32Array(r),i=new Uint32Array(r);for(let s=0;s<r;s++){let{h:o,l:c}=Oc(e[s],t);[n[s],i[s]]=[o,c]}return[n,i]}var Nn=(e,t,r)=>e>>>r,Kn=(e,t,r)=>e<<32-r|t>>>r,ae=(e,t,r)=>e>>>r|t<<32-r,ce=(e,t,r)=>e<<32-r|t>>>r,ze=(e,t,r)=>e<<64-r|t>>>r-32,Ze=(e,t,r)=>e>>>r-32|t<<64-r;function kt(e,t,r,n){let i=(t>>>0)+(n>>>0);return{h:e+r+(i/2**32|0)|0,l:i|0}}var Ui=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Mi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Oi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),qi=(e,t,r,n,i)=>t+r+n+i+(e/2**32|0)|0,Vi=(e,t,r,n,i)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(i>>>0),Hi=(e,t,r,n,i,s)=>t+r+n+i+s+(e/2**32|0)|0;var Vc=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),Un=class extends Fe{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:i,E:s,F:o,G:c,H:a}=this;return[t,r,n,i,s,o,c,a]}set(t,r,n,i,s,o,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(t,r){for(let h=0;h<16;h++,r+=4)Xt[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let l=Xt[h-15],d=Xt[h-2],p=Bt(l,7)^Bt(l,18)^l>>>3,v=Bt(d,17)^Bt(d,19)^d>>>10;Xt[h]=v+Xt[h-7]+p+Xt[h-16]|0}let{A:n,B:i,C:s,D:o,E:c,F:a,G:u,H:f}=this;for(let h=0;h<64;h++){let l=Bt(c,6)^Bt(c,11)^Bt(c,25),d=f+l+Ci(c,a,u)+Vc[h]+Xt[h]|0,v=(Bt(n,2)^Bt(n,13)^Bt(n,22))+Pi(n,i,s)|0;f=u,u=a,a=c,c=o+d|0,o=s,s=i,i=n,n=d+v|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,s,o,c,a,u,f)}roundClean(){Mt(Xt)}destroy(){this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}},Mn=class extends Un{A=Vt[0]|0;B=Vt[1]|0;C=Vt[2]|0;D=Vt[3]|0;E=Vt[4]|0;F=Vt[5]|0;G=Vt[6]|0;H=Vt[7]|0;constructor(){super(32)}};var $i=Ki(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Hc=$i[0],$c=$i[1],Wt=new Uint32Array(80),Jt=new Uint32Array(80),On=class extends Fe{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:i,Ch:s,Cl:o,Dh:c,Dl:a,Eh:u,El:f,Fh:h,Fl:l,Gh:d,Gl:p,Hh:v,Hl:S}=this;return[t,r,n,i,s,o,c,a,u,f,h,l,d,p,v,S]}set(t,r,n,i,s,o,c,a,u,f,h,l,d,p,v,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=f|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=p|0,this.Hh=v|0,this.Hl=S|0}process(t,r){for(let w=0;w<16;w++,r+=4)Wt[w]=t.getUint32(r),Jt[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let B=Wt[w-15]|0,C=Jt[w-15]|0,U=ae(B,C,1)^ae(B,C,8)^Nn(B,C,7),M=ce(B,C,1)^ce(B,C,8)^Kn(B,C,7),E=Wt[w-2]|0,x=Jt[w-2]|0,P=ae(E,x,19)^ze(E,x,61)^Nn(E,x,6),O=ce(E,x,19)^Ze(E,x,61)^Kn(E,x,6),T=Oi(M,O,Jt[w-7],Jt[w-16]),y=qi(T,U,P,Wt[w-7],Wt[w-16]);Wt[w]=y|0,Jt[w]=T|0}let{Ah:n,Al:i,Bh:s,Bl:o,Ch:c,Cl:a,Dh:u,Dl:f,Eh:h,El:l,Fh:d,Fl:p,Gh:v,Gl:S,Hh:b,Hl:I}=this;for(let w=0;w<80;w++){let B=ae(h,l,14)^ae(h,l,18)^ze(h,l,41),C=ce(h,l,14)^ce(h,l,18)^Ze(h,l,41),U=h&d^~h&v,M=l&p^~l&S,E=Vi(I,C,M,$c[w],Jt[w]),x=Hi(E,b,B,U,Hc[w],Wt[w]),P=E|0,O=ae(n,i,28)^ze(n,i,34)^ze(n,i,39),T=ce(n,i,28)^Ze(n,i,34)^Ze(n,i,39),y=n&s^n&c^s&c,g=i&o^i&a^o&a;b=v|0,I=S|0,v=d|0,S=p|0,d=h|0,p=l|0,{h,l}=kt(u|0,f|0,x|0,P|0),u=c|0,f=a|0,c=s|0,a=o|0,s=n|0,o=i|0;let m=Ui(P,T,g);n=Mi(m,x,O,y),i=m|0}({h:n,l:i}=kt(this.Ah|0,this.Al|0,n|0,i|0)),{h:s,l:o}=kt(this.Bh|0,this.Bl|0,s|0,o|0),{h:c,l:a}=kt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=kt(this.Dh|0,this.Dl|0,u|0,f|0),{h,l}=kt(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:p}=kt(this.Fh|0,this.Fl|0,d|0,p|0),{h:v,l:S}=kt(this.Gh|0,this.Gl|0,v|0,S|0),{h:b,l:I}=kt(this.Hh|0,this.Hl|0,b|0,I|0),this.set(n,i,s,o,c,a,u,f,h,l,d,p,v,S,b,I)}roundClean(){Mt(Wt,Jt)}destroy(){Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},qn=class extends On{Ah=ot[0]|0;Al=ot[1]|0;Bh=ot[2]|0;Bl=ot[3]|0;Ch=ot[4]|0;Cl=ot[5]|0;Dh=ot[6]|0;Dl=ot[7]|0;Eh=ot[8]|0;El=ot[9]|0;Fh=ot[10]|0;Fl=ot[11]|0;Gh=ot[12]|0;Gl=ot[13]|0;Hh=ot[14]|0;Hl=ot[15]|0;constructor(){super(64)}};var Le=Cn(()=>new Mn,Pn(1));var Fi=Cn(()=>new qn,Pn(3));var Hn=BigInt(0),Vn=BigInt(1);function Ht(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function zi(e){if(typeof e=="bigint"){if(!Cr(e))throw new Error("positive bigint expected, got "+e)}else Tt(e);return e}function Ye(e){let t=zi(e).toString(16);return t.length&1?"0"+t:t}function Zi(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Hn:BigInt("0x"+e)}function De(e){return Zi(Ot(e))}function ue(e){return Zi(Ot(Nr(K(e)).reverse()))}function Pr(e,t){Tt(t),e=zi(e);let r=qt(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function $n(e,t){return Pr(e,t).reverse()}function Nr(e){return Uint8Array.from(e)}var Cr=e=>typeof e=="bigint"&&Hn<=e;function Fc(e,t,r){return Cr(e)&&Cr(t)&&Cr(r)&&t<=e&&e<r}function Ge(e,t,r,n){if(!Fc(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Fn(e){let t;for(t=0;e>Hn;e>>=Vn,t+=1);return t}var je=e=>(Vn<<BigInt(e))-Vn;function Yi(e,t,r){if(Tt(e,"hashLen"),Tt(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=S=>new Uint8Array(S),i=Uint8Array.of(),s=Uint8Array.of(0),o=Uint8Array.of(1),c=1e3,a=n(e),u=n(e),f=0,h=()=>{a.fill(1),u.fill(0),f=0},l=(...S)=>r(u,gt(a,...S)),d=(S=i)=>{u=l(s,S),a=l(),S.length!==0&&(u=l(o,S),a=l())},p=()=>{if(f++>=c)throw new Error("drbg: tried max amount of iterations");let S=0,b=[];for(;S<t;){a=l();let I=a.slice();b.push(I),S+=a.length}return gt(...b)};return(S,b)=>{h(),d(S);let I;for(;!(I=b(p()));)d();return h(),I}}function Qt(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,o,c){let a=e[s];if(c&&a===void 0)return;let u=typeof a;if(u!==o||a===null)throw new Error(`param "${s}" is invalid: expected ${o}, got ${u}`)}let i=(s,o)=>Object.entries(s).forEach(([c,a])=>n(c,a,o));i(t,!1),i(r,!0)}function _e(e){let t=new WeakMap;return(r,...n)=>{let i=t.get(r);if(i!==void 0)return i;let s=e(r,...n);return t.set(r,s),s}}var ht=BigInt(0),nt=BigInt(1),fe=BigInt(2),Xi=BigInt(3),Wi=BigInt(4),Ji=BigInt(5),zc=BigInt(7),Qi=BigInt(8),Zc=BigInt(9),to=BigInt(16);function tt(e,t){let r=e%t;return r>=ht?r:t+r}function Z(e,t,r){let n=e;for(;t-- >ht;)n*=n,n%=r;return n}function Gi(e,t){if(e===ht)throw new Error("invert: expected non-zero number");if(t<=ht)throw new Error("invert: expected positive modulus, got "+t);let r=tt(e,t),n=t,i=ht,s=nt,o=nt,c=ht;for(;r!==ht;){let u=n/r,f=n%r,h=i-o*u,l=s-c*u;n=r,r=f,i=o,s=c,o=h,c=l}if(n!==nt)throw new Error("invert: does not exist");return tt(i,t)}function Zn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function eo(e,t){let r=(e.ORDER+nt)/Wi,n=e.pow(t,r);return Zn(e,n,t),n}function Yc(e,t){let r=(e.ORDER-Ji)/Qi,n=e.mul(t,fe),i=e.pow(n,r),s=e.mul(t,i),o=e.mul(e.mul(s,fe),i),c=e.mul(s,e.sub(o,e.ONE));return Zn(e,c,t),c}function Gc(e){let t=Te(e),r=ro(e),n=r(t,t.neg(t.ONE)),i=r(t,n),s=r(t,t.neg(n)),o=(e+zc)/to;return(c,a)=>{let u=c.pow(a,o),f=c.mul(u,n),h=c.mul(u,i),l=c.mul(u,s),d=c.eql(c.sqr(f),a),p=c.eql(c.sqr(h),a);u=c.cmov(u,f,d),f=c.cmov(l,h,p);let v=c.eql(c.sqr(f),a),S=c.cmov(u,f,v);return Zn(c,S,a),S}}function ro(e){if(e<Xi)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%fe===ht;)t/=fe,r++;let n=fe,i=Te(e);for(;ji(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return eo;let s=i.pow(n,t),o=(t+nt)/fe;return function(a,u){if(a.is0(u))return u;if(ji(a,u)!==1)throw new Error("Cannot find square root");let f=r,h=a.mul(a.ONE,s),l=a.pow(u,t),d=a.pow(u,o);for(;!a.eql(l,a.ONE);){if(a.is0(l))return a.ZERO;let p=1,v=a.sqr(l);for(;!a.eql(v,a.ONE);)if(p++,v=a.sqr(v),p===f)throw new Error("Cannot find square root");let S=nt<<BigInt(f-p-1),b=a.pow(h,S);f=p,h=a.sqr(b),l=a.mul(l,h),d=a.mul(d,b)}return d}}function jc(e){return e%Wi===Xi?eo:e%Qi===Ji?Yc:e%to===Zc?Gc(e):ro(e)}var no=(e,t)=>(tt(e,t)&nt)===nt,Xc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Yn(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Xc.reduce((n,i)=>(n[i]="function",n),t);return Qt(e,r),e}function Wc(e,t,r){if(r<ht)throw new Error("invalid exponent, negatives unsupported");if(r===ht)return e.ONE;if(r===nt)return t;let n=e.ONE,i=t;for(;r>ht;)r&nt&&(n=e.mul(n,i)),i=e.sqr(i),r>>=nt;return n}function Xe(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),i=t.reduce((o,c,a)=>e.is0(c)?o:(n[a]=o,e.mul(o,c)),e.ONE),s=e.inv(i);return t.reduceRight((o,c,a)=>e.is0(c)?o:(n[a]=e.mul(o,n[a]),e.mul(o,c)),s),n}function ji(e,t){let r=(e.ORDER-nt)/fe,n=e.pow(t,r),i=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),o=e.eql(n,e.neg(e.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Jc(e,t){t!==void 0&&Tt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var zn=class{ORDER;BITS;BYTES;isLE;ZERO=ht;ONE=nt;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=ht)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:i,nByteLength:s}=Jc(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=i,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return tt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return ht<=t&&t<this.ORDER}is0(t){return t===ht}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&nt)===nt}neg(t){return tt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return tt(t*t,this.ORDER)}add(t,r){return tt(t+r,this.ORDER)}sub(t,r){return tt(t-r,this.ORDER)}mul(t,r){return tt(t*r,this.ORDER)}pow(t,r){return Wc(this,t,r)}div(t,r){return tt(t*Gi(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Gi(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=jc(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?$n(t,this.BYTES):Pr(t,this.BYTES)}fromBytes(t,r=!1){K(t);let{_lengths:n,BYTES:i,isLE:s,ORDER:o,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>i)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(i);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+t.length);let a=s?ue(t):De(t);if(c&&(a=tt(a,o)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(t){return Xe(this,t)}cmov(t,r,n){return n?r:t}};function Te(e,t={}){return new zn(e,t)}function so(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Gn(e){let t=so(e);return t+Math.ceil(t/2)}function jn(e,t,r=!1){K(e);let n=e.length,i=so(t),s=Gn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let o=r?ue(e):De(e),c=tt(o,t-nt)+nt;return r?$n(c,i):Pr(c,i)}var ke=BigInt(0),le=BigInt(1);function We(e,t){let r=t.negate();return e?r:t}function he(e,t){let r=Xe(e.Fp,t.map(n=>n.Z));return t.map((n,i)=>e.fromAffine(n.toAffine(r[i])))}function co(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Xn(e,t){co(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),i=2**e,s=je(e),o=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:i,shiftBy:o}}function io(e,t,r){let{windowSize:n,mask:i,maxNumber:s,shiftBy:o}=r,c=Number(e&i),a=e>>o;c>n&&(c-=s,a+=le);let u=t*n,f=u+Math.abs(c)-1,h=c===0,l=c<0,d=t%2!==0;return{nextN:a,offset:f,isZero:h,isNeg:l,isNegF:d,offsetF:u}}var Wn=new WeakMap,uo=new WeakMap;function Jn(e){return uo.get(e)||1}function oo(e){if(e!==ke)throw new Error("invalid wNAF")}var Re=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let i=t;for(;r>ke;)r&le&&(n=n.add(i)),i=i.double(),r>>=le;return n}precomputeWindow(t,r){let{windows:n,windowSize:i}=Xn(r,this.bits),s=[],o=t,c=o;for(let a=0;a<n;a++){c=o,s.push(c);for(let u=1;u<i;u++)c=c.add(o),s.push(c);o=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE,o=Xn(t,this.bits);for(let c=0;c<o.windows;c++){let{nextN:a,offset:u,isZero:f,isNeg:h,isNegF:l,offsetF:d}=io(n,c,o);n=a,f?s=s.add(We(l,r[d])):i=i.add(We(h,r[u]))}return oo(n),{p:i,f:s}}wNAFUnsafe(t,r,n,i=this.ZERO){let s=Xn(t,this.bits);for(let o=0;o<s.windows&&n!==ke;o++){let{nextN:c,offset:a,isZero:u,isNeg:f}=io(n,o,s);if(n=c,!u){let h=r[a];i=i.add(f?h.negate():h)}}return oo(n),i}getPrecomputes(t,r,n){let i=Wn.get(r);return i||(i=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(i=n(i)),Wn.set(r,i))),i}cached(t,r,n){let i=Jn(t);return this.wNAF(i,this.getPrecomputes(i,t,n),r)}unsafe(t,r,n,i){let s=Jn(t);return s===1?this._unsafeLadder(t,r,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,i)}createCache(t,r){co(r,this.bits),uo.set(t,r),Wn.delete(t)}hasCache(t){return Jn(t)!==1}};function fo(e,t,r,n){let i=t,s=e.ZERO,o=e.ZERO;for(;r>ke||n>ke;)r&le&&(s=s.add(i)),n&le&&(o=o.add(i)),i=i.double(),r>>=le,n>>=le;return{p1:s,p2:o}}function ao(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Yn(t),t}else return Te(e,{isLE:r})}function Kr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>ke))throw new Error(`CURVE.${a} must be positive bigint`)}let i=ao(t.p,r.Fp,n),s=ao(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!i.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:s}}function Ur(e,t){return function(n){let i=e(n);return{secretKey:i,publicKey:t(i)}}}var te=BigInt(0),st=BigInt(1),Qn=BigInt(2),Qc=BigInt(8);function tu(e,t,r,n){let i=e.sqr(r),s=e.sqr(n),o=e.add(e.mul(t.a,i),s),c=e.add(e.ONE,e.mul(t.d,e.mul(i,s)));return e.eql(o,c)}function lo(e,t={}){let r=Kr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:i}=r,s=r.CURVE,{h:o}=s;Qt(t,{},{uvRatio:"function"});let c=Qn<<BigInt(i.BYTES*8)-st,a=S=>n.create(S),u=t.uvRatio||((S,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,b))}}catch{return{isValid:!1,value:te}}});if(!tu(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function f(S,b,I=!1){let w=I?st:te;return Ge("coordinate "+S,b,w,c),b}function h(S){if(!(S instanceof p))throw new Error("EdwardsPoint expected")}let l=_e((S,b)=>{let{X:I,Y:w,Z:B}=S,C=S.is0();b==null&&(b=C?Qc:n.inv(B));let U=a(I*b),M=a(w*b),E=n.mul(B,b);if(C)return{x:te,y:st};if(E!==st)throw new Error("invZ was invalid");return{x:U,y:M}}),d=_e(S=>{let{a:b,d:I}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:w,Y:B,Z:C,T:U}=S,M=a(w*w),E=a(B*B),x=a(C*C),P=a(x*x),O=a(M*b),T=a(x*a(O+E)),y=a(P+a(I*a(M*E)));if(T!==y)throw new Error("bad point: equation left != right (1)");let g=a(w*B),m=a(C*U);if(g!==m)throw new Error("bad point: equation left != right (2)");return!0});class p{static BASE=new p(s.Gx,s.Gy,st,a(s.Gx*s.Gy));static ZERO=new p(te,st,st,te);static Fp=n;static Fn=i;X;Y;Z;T;constructor(b,I,w,B){this.X=f("x",b),this.Y=f("y",I),this.Z=f("z",w,!0),this.T=f("t",B),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof p)throw new Error("extended point not allowed");let{x:I,y:w}=b||{};return f("x",I),f("y",w),new p(I,w,st,a(I*w))}static fromBytes(b,I=!1){let w=n.BYTES,{a:B,d:C}=s;b=Nr(K(b,w,"point")),Ht(I,"zip215");let U=Nr(b),M=b[w-1];U[w-1]=M&-129;let E=ue(U),x=I?c:n.ORDER;Ge("point.y",E,te,x);let P=a(E*E),O=a(P-st),T=a(C*P-B),{isValid:y,value:g}=u(O,T);if(!y)throw new Error("bad point: invalid y coordinate");let m=(g&st)===st,A=(M&128)!==0;if(!I&&g===te&&A)throw new Error("bad point: x=0 and x_0=1");return A!==m&&(g=a(-g)),p.fromAffine({x:g,y:E})}static fromHex(b,I=!1){return p.fromBytes(qt(b),I)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,I=!0){return v.createCache(this,b),I||this.multiply(Qn),this}assertValidity(){d(this)}equals(b){h(b);let{X:I,Y:w,Z:B}=this,{X:C,Y:U,Z:M}=b,E=a(I*M),x=a(C*B),P=a(w*M),O=a(U*B);return E===x&&P===O}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:b}=s,{X:I,Y:w,Z:B}=this,C=a(I*I),U=a(w*w),M=a(Qn*a(B*B)),E=a(b*C),x=I+w,P=a(a(x*x)-C-U),O=E+U,T=O-M,y=E-U,g=a(P*T),m=a(O*y),A=a(P*y),L=a(T*O);return new p(g,m,L,A)}add(b){h(b);let{a:I,d:w}=s,{X:B,Y:C,Z:U,T:M}=this,{X:E,Y:x,Z:P,T:O}=b,T=a(B*E),y=a(C*x),g=a(M*w*O),m=a(U*P),A=a((B+C)*(E+x)-T-y),L=m-g,_=m+g,k=a(y-I*T),D=a(A*L),R=a(_*k),N=a(A*k),j=a(L*_);return new p(D,R,j,N)}subtract(b){return this.add(b.negate())}multiply(b){if(!i.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:I,f:w}=v.cached(this,b,B=>he(p,B));return he(p,[I,w])[0]}multiplyUnsafe(b,I=p.ZERO){if(!i.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===te?p.ZERO:this.is0()||b===st?this:v.unsafe(this,b,w=>he(p,w),I)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return v.unsafe(this,s.n).is0()}toAffine(b){return l(this,b)}clearCofactor(){return o===st?this:this.multiplyUnsafe(o)}toBytes(){let{x:b,y:I}=this.toAffine(),w=n.toBytes(I);return w[w.length-1]|=b&st?128:0,w}toHex(){return Ot(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let v=new Re(p,i.BITS);return p.BASE.precompute(8),p}function ho(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Qt(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:i,Fp:s,Fn:o}=e,c=r.randomBytes||jt,a=r.adjustScalarBytes||(E=>E),u=r.domain||((E,x,P)=>{if(Ht(P,"phflag"),x.length||P)throw new Error("Contexts/pre-hash are not supported");return E});function f(E){return o.create(ue(E))}function h(E){let x=w.secretKey;K(E,w.secretKey,"secretKey");let P=K(t(E),2*x,"hashedSecretKey"),O=a(P.slice(0,x)),T=P.slice(x,2*x),y=f(O);return{head:O,prefix:T,scalar:y}}function l(E){let{head:x,prefix:P,scalar:O}=h(E),T=i.multiply(O),y=T.toBytes();return{head:x,prefix:P,scalar:O,point:T,pointBytes:y}}function d(E){return l(E).pointBytes}function p(E=Uint8Array.of(),...x){let P=gt(...x);return f(t(u(P,K(E,void 0,"context"),!!n)))}function v(E,x,P={}){E=K(E,void 0,"message"),n&&(E=n(E));let{prefix:O,scalar:T,pointBytes:y}=l(x),g=p(P.context,O,E),m=i.multiply(g).toBytes(),A=p(P.context,m,y,E),L=o.create(g+A*T);if(!o.isValid(L))throw new Error("sign failed: invalid s");let _=gt(m,o.toBytes(L));return K(_,w.signature,"result")}let S={zip215:!0};function b(E,x,P,O=S){let{context:T,zip215:y}=O,g=w.signature;E=K(E,g,"signature"),x=K(x,void 0,"message"),P=K(P,w.publicKey,"publicKey"),y!==void 0&&Ht(y,"zip215"),n&&(x=n(x));let m=g/2,A=E.subarray(0,m),L=ue(E.subarray(m,g)),_,k,D;try{_=e.fromBytes(P,y),k=e.fromBytes(A,y),D=i.multiplyUnsafe(L)}catch{return!1}if(!y&&_.isSmallOrder())return!1;let R=p(T,k.toBytes(),_.toBytes(),x);return k.add(_.multiplyUnsafe(R)).subtract(D).clearCofactor().is0()}let I=s.BYTES,w={secretKey:I,publicKey:I,signature:2*I,seed:I};function B(E=c(w.seed)){return K(E,w.seed,"seed")}function C(E){return oe(E)&&E.length===o.BYTES}function U(E,x){try{return!!e.fromBytes(E,x)}catch{return!1}}let M={getExtendedPublicKey:l,randomSecretKey:B,isValidSecretKey:C,isValidPublicKey:U,toMontgomery(E){let{y:x}=e.fromBytes(E),P=w.publicKey,O=P===32;if(!O&&P!==57)throw new Error("only defined for 25519 and 448");let T=O?s.div(st+x,st-x):s.div(x-st,x+st);return s.toBytes(T)},toMontgomerySecret(E){let x=w.secretKey;K(E,x);let P=t(E.subarray(0,x));return a(P).subarray(0,x)}};return Object.freeze({keygen:Ur(B,d),getPublicKey:d,sign:v,verify:b,utils:M,Point:e,lengths:w})}var eu=BigInt(1),po=BigInt(2);var ru=BigInt(5),nu=BigInt(8),ts=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),su={p:ts,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:nu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function iu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),i=BigInt(80),s=ts,c=e*e%s*e%s,a=Z(c,po,s)*c%s,u=Z(a,eu,s)*e%s,f=Z(u,ru,s)*u%s,h=Z(f,t,s)*f%s,l=Z(h,r,s)*h%s,d=Z(l,n,s)*l%s,p=Z(d,i,s)*d%s,v=Z(p,i,s)*d%s,S=Z(v,t,s)*f%s;return{pow_p_5_8:Z(S,po,s)*e%s,b2:c}}function ou(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var mo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function au(e,t){let r=ts,n=tt(t*t*t,r),i=tt(n*n*t,r),s=iu(e*i).pow_p_5_8,o=tt(e*n*s,r),c=tt(t*o*o,r),a=o,u=tt(o*mo,r),f=c===e,h=c===tt(-e,r),l=c===tt(-e*mo,r);return f&&(o=a),(h||l)&&(o=u),no(o,r)&&(o=tt(-o,r)),{isValid:f||h,value:o}}var cu=lo(su,{uvRatio:au});function uu(e){return ho(cu,Fi,Object.assign({adjustScalarBytes:ou},e))}var bo=uu({});var Je=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Mr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var yo={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Mr("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 At=yo;var Or=32;var es,fu=(async()=>{try{return await At.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function lu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await At.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await At.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function hu(e,t,r){return bo.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function go(e,t,r){return es==null&&(es=await fu),es?lu(e,t,r):hu(e,t,r)}function qr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Vr=class{type="Ed25519";raw;constructor(t){this.raw=rs(t,Or)}toMultihash(){return It.digest(Kt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let i=go(this.raw,r,t);return qr(i)?i.then(s=>(n?.signal?.throwIfAborted(),s)):i}};function ns(e){return e=rs(e,Or),new Vr(e)}function rs(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new F(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var pu=Math.pow(2,7),mu=Math.pow(2,14),bu=Math.pow(2,21),ss=Math.pow(2,28),is=Math.pow(2,35),os=Math.pow(2,42),as=Math.pow(2,49),V=128,ut=127;function $t(e){if(e<pu)return 1;if(e<mu)return 2;if(e<bu)return 3;if(e<ss)return 4;if(e<is)return 5;if(e<os)return 6;if(e<as)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function cs(e,t,r=0){switch($t(e)){case 8:t[r++]=e&255|V,e/=128;case 7:t[r++]=e&255|V,e/=128;case 6:t[r++]=e&255|V,e/=128;case 5:t[r++]=e&255|V,e/=128;case 4:t[r++]=e&255|V,e>>>=7;case 3:t[r++]=e&255|V,e>>>=7;case 2:t[r++]=e&255|V,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function yu(e,t,r=0){switch($t(e)){case 8:t.set(r++,e&255|V),e/=128;case 7:t.set(r++,e&255|V),e/=128;case 6:t.set(r++,e&255|V),e/=128;case 5:t.set(r++,e&255|V),e/=128;case 4:t.set(r++,e&255|V),e>>>=7;case 3:t.set(r++,e&255|V),e>>>=7;case 2:t.set(r++,e&255|V),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function us(e,t){let r=e[t],n=0;if(n+=r&ut,r<V||(r=e[t+1],n+=(r&ut)<<7,r<V)||(r=e[t+2],n+=(r&ut)<<14,r<V)||(r=e[t+3],n+=(r&ut)<<21,r<V)||(r=e[t+4],n+=(r&ut)*ss,r<V)||(r=e[t+5],n+=(r&ut)*is,r<V)||(r=e[t+6],n+=(r&ut)*os,r<V)||(r=e[t+7],n+=(r&ut)*as,r<V))return n;throw new RangeError("Could not decode varint")}function gu(e,t){let r=e.get(t),n=0;if(n+=r&ut,r<V||(r=e.get(t+1),n+=(r&ut)<<7,r<V)||(r=e.get(t+2),n+=(r&ut)<<14,r<V)||(r=e.get(t+3),n+=(r&ut)<<21,r<V)||(r=e.get(t+4),n+=(r&ut)*ss,r<V)||(r=e.get(t+5),n+=(r&ut)*is,r<V)||(r=e.get(t+6),n+=(r&ut)*os,r<V)||(r=e.get(t+7),n+=(r&ut)*as,r<V))return n;throw new RangeError("Could not decode varint")}function xo(e,t,r=0){return t==null&&(t=bt($t(e))),t instanceof Uint8Array?cs(e,t,r):yu(e,t,r)}function Eo(e,t=0){return e instanceof Uint8Array?us(e,t):gu(e,t)}var fs=new Float32Array([-0]),ee=new Uint8Array(fs.buffer);function vo(e,t,r){fs[0]=e,t[r]=ee[0],t[r+1]=ee[1],t[r+2]=ee[2],t[r+3]=ee[3]}function So(e,t){return ee[0]=e[t],ee[1]=e[t+1],ee[2]=e[t+2],ee[3]=e[t+3],fs[0]}var ls=new Float64Array([-0]),ft=new Uint8Array(ls.buffer);function Ao(e,t,r){ls[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function Io(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],ls[0]}var xu=BigInt(Number.MAX_SAFE_INTEGER),Eu=BigInt(Number.MIN_SAFE_INTEGER),St=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return de;if(t<xu&&t>Eu)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,i=t-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>Bo&&(i=0n,++n>Bo&&(n=0n))),new e(Number(i),Number(n))}static fromNumber(t){if(t===0)return de;let r=t<0;r&&(t=-t);let n=t>>>0,i=(t-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new e(n,i)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):de}},de=new St(0,0);de.toBigInt=function(){return 0n};de.zzEncode=de.zzDecode=function(){return this};de.length=function(){return 1};var Bo=4294967296n;function Lo(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Do(e,t,r){if(r-t<1)return"";let i,s=[],o=0,c;for(;t<r;)c=e[t++],c<128?s[o++]=c:c>191&&c<224?s[o++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[o++]=55296+(c>>10),s[o++]=56320+(c&1023)):s[o++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,o>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,s)),o=0);return i!=null?(o>0&&i.push(String.fromCharCode.apply(String,s.slice(0,o))),i.join("")):String.fromCharCode.apply(String,s.slice(0,o))}function hs(e,t,r){let n=r,i,s;for(let o=0;o<e.length;++o)i=e.charCodeAt(o),i<128?t[r++]=i:i<2048?(t[r++]=i>>6|192,t[r++]=i&63|128):(i&64512)===55296&&((s=e.charCodeAt(o+1))&64512)===56320?(i=65536+((i&1023)<<10)+(s&1023),++o,t[r++]=i>>18|240,t[r++]=i>>12&63|128,t[r++]=i>>6&63|128,t[r++]=i&63|128):(t[r++]=i>>12|224,t[r++]=i>>6&63|128,t[r++]=i&63|128);return r-n}function Lt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Hr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ds=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Lt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Lt(this,4);return Hr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return Hr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=So(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=Io(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Lt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Do(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new St(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Lt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Lt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Lt(this,8);let t=Hr(this.buf,this.pos+=4),r=Hr(this.buf,this.pos+=4);return new St(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=us(this.buf,this.pos);return this.pos+=$t(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 Qe(e){return new ds(e instanceof Uint8Array?e:e.subarray())}function wt(e,t,r){let n=Qe(e);return t.decode(n,void 0,r)}function ps(e){let t=e??8192,r=t>>>1,n,i=t;return function(o){if(o<1||o>r)return bt(o);i+o>t&&(n=bt(t),i=0);let c=n.subarray(i,i+=o);return(i&7)!==0&&(i=(i|7)+1),c}}var pe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function ms(){}var ys=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},vu=ps();function Su(e){return globalThis.Buffer!=null?bt(e):vu(e)}var er=class{len;head;tail;states;constructor(){this.len=0,this.head=new pe(ms,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new pe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new gs((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($r,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=St.fromBigInt(t);return this._push($r,r.length(),r)}uint64Number(t){return this._push(cs,$t(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=St.fromBigInt(t).zzEncode();return this._push($r,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push($r,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(bs,1,t?1:0)}fixed32(t){return this._push(tr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(tr,4,r.lo)._push(tr,4,r.hi)}fixed64Number(t){let r=St.fromNumber(t);return this._push(tr,4,r.lo)._push(tr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(vo,4,t)}double(t){return this._push(Ao,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(bs,1,0):this.uint32(r)._push(Iu,r,t)}string(t){let r=Lo(t);return r!==0?this.uint32(r)._push(hs,r,t):this._push(bs,1,0)}fork(){return this.states=new ys(this),this.head=this.tail=new pe(ms,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 pe(ms,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Su(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function bs(e,t,r){t[r]=e&255}function Au(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var gs=class extends pe{next;constructor(t,r){super(Au,t,r),this.next=void 0}};function $r(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function tr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Iu(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(er.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Bu,t,e),this},er.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Lu,t,e),this});function Bu(e,t,r){t.set(e,r)}function Lu(e,t,r){e.length<40?hs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set($(e),r)}function ws(){return new er}function xt(e,t){let r=ws();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Et(e,t,r){let n=Qe(e);yield*t.stream(n,void 0,"$",r)}var Fr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function zr(e,t,r,n,i){return{name:e,type:t,encode:r,decode:n,stream:i}}function xs(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(o,c){let a=t(o);c.int32(a)},n=function(o){let c=o.int32();return t(c)},i=function*(o){let c=o.int32();yield t(c)};return zr("enum",Fr.VARINT,r,n,i)}function vt(e,t,r){return zr("message",Fr.LENGTH_DELIMITED,e,t,r)}var et=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var G;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(G||(G={}));var Es;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Es||(Es={}));(function(e){e.codec=()=>xs(Es)})(G||(G={}));var Rt;(function(e){let t;e.codec=()=>(t==null&&(t=vt((s,o,c={})=>{c.lengthDelimited!==!1&&o.fork(),s.Type!=null&&(o.uint32(8),G.codec().encode(s.Type,o)),s.Data!=null&&(o.uint32(18),o.bytes(s.Data)),c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.Type=G.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.Type`,value:G.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return xt(s,e.codec())}e.encode=r;function n(s,o){return wt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(Rt||(Rt={}));var vs;(function(e){let t;e.codec=()=>(t==null&&(t=vt((s,o,c={})=>{c.lengthDelimited!==!1&&o.fork(),s.Type!=null&&(o.uint32(8),G.codec().encode(s.Type,o)),s.Data!=null&&(o.uint32(18),o.bytes(s.Data)),c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.Type=G.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.Type`,value:G.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return xt(s,e.codec())}e.encode=r;function n(s,o){return wt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(vs||(vs={}));function Zr(e){if(isNaN(e)||e<=0)throw new F("random bytes length must be a Number bigger than 0");return jt(e)}var nr={};pt(nr,{MAX_RSA_KEY_SIZE:()=>Ss,generateRSAKeyPair:()=>Po,jwkToJWKKeyPair:()=>No,jwkToPkcs1:()=>ku,jwkToPkix:()=>Ls,jwkToRSAPrivateKey:()=>ks,pkcs1MessageToJwk:()=>Is,pkcs1MessageToRSAPrivateKey:()=>Ds,pkcs1ToJwk:()=>Tu,pkcs1ToRSAPrivateKey:()=>Co,pkixMessageToJwk:()=>Bs,pkixMessageToRSAPublicKey:()=>Ts,pkixToJwk:()=>Ru,pkixToRSAPublicKey:()=>_s});var Ce=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=nr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ct.createV1(114,this._multihash)}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,r,n){return Ro(this.jwk,r,t,n)}},rr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=nr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}sign(t,r){return ko(this.jwk,t,r)}};var Ss=8192,As=18,Du=1062,_u=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Tu(e){let t=Nt(e);return Is(t)}function Is(e){return{n:H(e[1],"base64url"),e:H(e[2],"base64url"),d:H(e[3],"base64url"),p:H(e[4],"base64url"),q:H(e[5],"base64url"),dp:H(e[6],"base64url"),dq:H(e[7],"base64url"),qi:H(e[8],"base64url"),kty:"RSA"}}function ku(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new F("JWK was missing components");return Gt([yt(Uint8Array.from([0])),yt($(e.n,"base64url")),yt($(e.e,"base64url")),yt($(e.d,"base64url")),yt($(e.p,"base64url")),yt($(e.q,"base64url")),yt($(e.dp,"base64url")),yt($(e.dq,"base64url")),yt($(e.qi,"base64url"))]).subarray()}function Ru(e){let t=Nt(e,{offset:0});return Bs(t)}function Bs(e){let t=Nt(e[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function Ls(e){if(e.n==null||e.e==null)throw new F("JWK was missing components");return Gt([_u,_r(Gt([yt($(e.n,"base64url")),yt($(e.e,"base64url"))]))]).subarray()}function Co(e){let t=Nt(e);return Ds(t)}function Ds(e){let t=Is(e);return ks(t)}function _s(e,t){if(e.byteLength>=Du)throw new ge("Key size is too large");let r=Nt(e,{offset:0});return Ts(r,e,t)}function Ts(e,t,r){let n=Bs(e);if(r==null){let i=Le(Rt.encode({Type:G.RSA,Data:t}));r=_t(As,i)}return new Ce(n,r)}function ks(e){if(Uo(e)>Ss)throw new F("Key size is too large");let t=No(e),r=Le(Rt.encode({Type:G.RSA,Data:Ls(t.publicKey)})),n=_t(As,r);return new rr(t.privateKey,new Ce(t.publicKey,n))}async function Po(e){if(e>Ss)throw new F("Key size is too large");let t=await Ko(e),r=Le(Rt.encode({Type:G.RSA,Data:Ls(t.publicKey)})),n=_t(As,r);return new rr(t.privateKey,new Ce(t.publicKey,n))}function No(e){if(e==null)throw new F("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Ko(e,t){let r=await At.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Cu(r,t);return{privateKey:n[0],publicKey:n[1]}}async function ko(e,t,r){let n=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let i=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(i,0,i.byteLength)}async function Ro(e,t,r,n){let i=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},i,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Cu(e,t){if(e.privateKey==null||e.publicKey==null)throw new F("Private and public key are required");let r=await Promise.all([At.get().subtle.exportKey("jwk",e.privateKey),At.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Uo(e){if(e.kty!=="RSA")throw new F("invalid key type");if(e.n==null)throw new F("invalid key modulus");return $(e.n,"base64url").length*8}var Yr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(Tr(t),K(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=t.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),Mt(i)}update(t){return Be(this),this.iHash.update(t),this}digestInto(t){Be(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:r,iHash:n,finished:i,destroyed:s,blockLen:o,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=s,t.blockLen=o,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Rs=(e,t,r)=>new Yr(e,t).update(r).digest();Rs.create=(e,t)=>new Yr(e,t);var Mo=(e,t)=>(e+(e>=0?t:-t)/Oo)/t;function Pu(e,t,r){let[[n,i],[s,o]]=t,c=Mo(o*e,r),a=Mo(-i*e,r),u=e-c*n-a*s,f=-c*i-a*o,h=u<Ft,l=f<Ft;h&&(u=-u),l&&(f=-f);let d=je(Math.ceil(Fn(r)/2))+Pe;if(u<Ft||u>=d||f<Ft||f>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:h,k1:u,k2neg:l,k2:f}}function Ps(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Cs(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Ht(r.lowS,"lowS"),Ht(r.prehash,"prehash"),r.format!==void 0&&Ps(r.format),r}var Ns=class extends Error{constructor(t=""){super(t)}},re={Err:Ns,_tlv:{encode:(e,t)=>{let{Err:r}=re;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,i=Ye(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Ye(i.length/2|128):"";return Ye(e)+s+i+t},decode(e,t){let{Err:r}=re,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let i=t[n++],s=!!(i&128),o=0;if(!s)o=i;else{let a=i&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)o=o<<8|f;if(n+=a,o<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+o);if(c.length!==o)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+o)}}},_int:{encode(e){let{Err:t}=re;if(e<Ft)throw new t("integer: negative integers are not allowed");let r=Ye(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=re;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return De(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=re,i=K(e,void 0,"signature"),{v:s,l:o}=n.decode(48,i);if(o.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l:f}=n.decode(2,a);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=re,n=t.encode(2,r.encode(e.r)),i=t.encode(2,r.encode(e.s)),s=n+i;return t.encode(48,s)}},Ft=BigInt(0),Pe=BigInt(1),Oo=BigInt(2),Gr=BigInt(3),Nu=BigInt(4);function qo(e,t={}){let r=Kr("weierstrass",e,t),{Fp:n,Fn:i}=r,s=r.CURVE,{h:o,n:c}=s;Qt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Ho(n,i);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(T,y,g){let{x:m,y:A}=y.toAffine(),L=n.toBytes(m);if(Ht(g,"isCompressed"),g){f();let _=!n.isOdd(A);return gt(Vo(_),L)}else return gt(Uint8Array.of(4),L,n.toBytes(A))}function l(T){K(T,void 0,"Point");let{publicKey:y,publicKeyUncompressed:g}=u,m=T.length,A=T[0],L=T.subarray(1);if(m===y&&(A===2||A===3)){let _=n.fromBytes(L);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let k=v(_),D;try{D=n.sqrt(k)}catch(j){let z=j instanceof Error?": "+j.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}f();let R=n.isOdd(D);return(A&1)===1!==R&&(D=n.neg(D)),{x:_,y:D}}else if(m===g&&A===4){let _=n.BYTES,k=n.fromBytes(L.subarray(0,_)),D=n.fromBytes(L.subarray(_,_*2));if(!S(k,D))throw new Error("bad point: is not on curve");return{x:k,y:D}}else throw new Error(`bad point: got length ${m}, expected compressed=${y} or uncompressed=${g}`)}let d=t.toBytes||h,p=t.fromBytes||l;function v(T){let y=n.sqr(T),g=n.mul(y,T);return n.add(n.add(g,n.mul(T,s.a)),s.b)}function S(T,y){let g=n.sqr(y),m=v(T);return n.eql(g,m)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,Gr),Nu),I=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,I)))throw new Error("bad curve params: a or b");function w(T,y,g=!1){if(!n.isValid(y)||g&&n.is0(y))throw new Error(`bad point coordinate ${T}`);return y}function B(T){if(!(T instanceof x))throw new Error("Weierstrass Point expected")}function C(T){if(!a||!a.basises)throw new Error("no endo");return Pu(T,a.basises,i.ORDER)}let U=_e((T,y)=>{let{X:g,Y:m,Z:A}=T;if(n.eql(A,n.ONE))return{x:g,y:m};let L=T.is0();y==null&&(y=L?n.ONE:n.inv(A));let _=n.mul(g,y),k=n.mul(m,y),D=n.mul(A,y);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(D,n.ONE))throw new Error("invZ was invalid");return{x:_,y:k}}),M=_e(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:y,y:g}=T.toAffine();if(!n.isValid(y)||!n.isValid(g))throw new Error("bad point: x or y not field elements");if(!S(y,g))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,y,g,m,A){return g=new x(n.mul(g.X,T),g.Y,g.Z),y=We(m,y),g=We(A,g),y.add(g)}class x{static BASE=new x(s.Gx,s.Gy,n.ONE);static ZERO=new x(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=i;X;Y;Z;constructor(y,g,m){this.X=w("x",y),this.Y=w("y",g,!0),this.Z=w("z",m),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x:g,y:m}=y||{};if(!y||!n.isValid(g)||!n.isValid(m))throw new Error("invalid affine point");if(y instanceof x)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(m)?x.ZERO:new x(g,m,n.ONE)}static fromBytes(y){let g=x.fromAffine(p(K(y,void 0,"point")));return g.assertValidity(),g}static fromHex(y){return x.fromBytes(qt(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,g=!0){return O.createCache(this,y),g||this.multiply(Gr),this}assertValidity(){M(this)}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){B(y);let{X:g,Y:m,Z:A}=this,{X:L,Y:_,Z:k}=y,D=n.eql(n.mul(g,k),n.mul(L,A)),R=n.eql(n.mul(m,k),n.mul(_,A));return D&&R}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b:g}=s,m=n.mul(g,Gr),{X:A,Y:L,Z:_}=this,k=n.ZERO,D=n.ZERO,R=n.ZERO,N=n.mul(A,A),j=n.mul(L,L),z=n.mul(_,_),q=n.mul(A,L);return q=n.add(q,q),R=n.mul(A,_),R=n.add(R,R),k=n.mul(y,R),D=n.mul(m,z),D=n.add(k,D),k=n.sub(j,D),D=n.add(j,D),D=n.mul(k,D),k=n.mul(q,k),R=n.mul(m,R),z=n.mul(y,z),q=n.sub(N,z),q=n.mul(y,q),q=n.add(q,R),R=n.add(N,N),N=n.add(R,N),N=n.add(N,z),N=n.mul(N,q),D=n.add(D,N),z=n.mul(L,_),z=n.add(z,z),N=n.mul(z,q),k=n.sub(k,N),R=n.mul(z,j),R=n.add(R,R),R=n.add(R,R),new x(k,D,R)}add(y){B(y);let{X:g,Y:m,Z:A}=this,{X:L,Y:_,Z:k}=y,D=n.ZERO,R=n.ZERO,N=n.ZERO,j=s.a,z=n.mul(s.b,Gr),q=n.mul(g,L),X=n.mul(m,_),it=n.mul(A,k),Dt=n.add(g,m),W=n.add(L,_);Dt=n.mul(Dt,W),W=n.add(q,X),Dt=n.sub(Dt,W),W=n.add(g,A);let at=n.add(L,k);return W=n.mul(W,at),at=n.add(q,it),W=n.sub(W,at),at=n.add(m,A),D=n.add(_,k),at=n.mul(at,D),D=n.add(X,it),at=n.sub(at,D),N=n.mul(j,W),D=n.mul(z,it),N=n.add(D,N),D=n.sub(X,N),N=n.add(X,N),R=n.mul(D,N),X=n.add(q,q),X=n.add(X,q),it=n.mul(j,it),W=n.mul(z,W),X=n.add(X,it),it=n.sub(q,it),it=n.mul(j,it),W=n.add(W,it),q=n.mul(X,W),R=n.add(R,q),q=n.mul(at,W),D=n.mul(Dt,D),D=n.sub(D,q),q=n.mul(Dt,X),N=n.mul(at,N),N=n.add(N,q),new x(D,R,N)}subtract(y){return this.add(y.negate())}is0(){return this.equals(x.ZERO)}multiply(y){let{endo:g}=t;if(!i.isValidNot0(y))throw new Error("invalid scalar: out of range");let m,A,L=_=>O.cached(this,_,k=>he(x,k));if(g){let{k1neg:_,k1:k,k2neg:D,k2:R}=C(y),{p:N,f:j}=L(k),{p:z,f:q}=L(R);A=j.add(q),m=E(g.beta,N,z,_,D)}else{let{p:_,f:k}=L(y);m=_,A=k}return he(x,[m,A])[0]}multiplyUnsafe(y){let{endo:g}=t,m=this;if(!i.isValid(y))throw new Error("invalid scalar: out of range");if(y===Ft||m.is0())return x.ZERO;if(y===Pe)return m;if(O.hasCache(this))return this.multiply(y);if(g){let{k1neg:A,k1:L,k2neg:_,k2:k}=C(y),{p1:D,p2:R}=fo(x,m,L,k);return E(g.beta,D,R,A,_)}else return O.unsafe(m,y)}toAffine(y){return U(this,y)}isTorsionFree(){let{isTorsionFree:y}=t;return o===Pe?!0:y?y(x,this):O.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:y}=t;return o===Pe?this:y?y(x,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(y=!0){return Ht(y,"isCompressed"),this.assertValidity(),d(x,this,y)}toHex(y=!0){return Ot(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=i.BITS,O=new Re(x,t.endo?Math.ceil(P/2):P);return x.BASE.precompute(8),x}function Vo(e){return Uint8Array.of(e?2:3)}function Ho(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ku(e,t={}){let{Fn:r}=e,n=t.randomBytes||jt,i=Object.assign(Ho(e.Fp,r),{seed:Gn(r.ORDER)});function s(d){try{let p=r.fromBytes(d);return r.isValidNot0(p)}catch{return!1}}function o(d,p){let{publicKey:v,publicKeyUncompressed:S}=i;try{let b=d.length;return p===!0&&b!==v||p===!1&&b!==S?!1:!!e.fromBytes(d)}catch{return!1}}function c(d=n(i.seed)){return jn(K(d,i.seed,"seed"),r.ORDER)}function a(d,p=!0){return e.BASE.multiply(r.fromBytes(d)).toBytes(p)}function u(d){let{secretKey:p,publicKey:v,publicKeyUncompressed:S}=i;if(!oe(d)||"_lengths"in r&&r._lengths||p===v)return;let b=K(d,void 0,"key").length;return b===v||b===S}function f(d,p,v=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(p)===!1)throw new Error("second arg must be public key");let S=r.fromBytes(d);return e.fromBytes(p).multiply(S).toBytes(v)}let h={isValidSecretKey:s,isValidPublicKey:o,randomSecretKey:c},l=Ur(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:f,keygen:l,Point:e,utils:h,lengths:i})}function $o(e,t,r={}){Tr(t),Qt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||jt,i=r.hmac||((g,m)=>Rs(t,g,m)),{Fp:s,Fn:o}=e,{ORDER:c,BITS:a}=o,{keygen:u,getPublicKey:f,getSharedSecret:h,utils:l,lengths:d}=Ku(e,r),p={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},v=c*Oo<s.ORDER;function S(g){let m=c>>Pe;return g>m}function b(g,m){if(!o.isValidNot0(m))throw new Error(`invalid signature ${g}: out of range 1..Point.Fn.ORDER`);return m}function I(){if(v)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(g,m){Ps(m);let A=d.signature,L=m==="compact"?A:m==="recovered"?A+1:void 0;return K(g,L)}class B{r;s;recovery;constructor(m,A,L){if(this.r=b("r",m),this.s=b("s",A),L!=null){if(I(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(m,A=p.format){w(m,A);let L;if(A==="der"){let{r:R,s:N}=re.toSig(K(m));return new B(R,N)}A==="recovered"&&(L=m[0],A="compact",m=m.subarray(1));let _=d.signature/2,k=m.subarray(0,_),D=m.subarray(_,_*2);return new B(o.fromBytes(k),o.fromBytes(D),L)}static fromHex(m,A){return this.fromBytes(qt(m),A)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new B(this.r,this.s,m)}recoverPublicKey(m){let{r:A,s:L}=this,_=this.assertRecovery(),k=_===2||_===3?A+c:A;if(!s.isValid(k))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=s.toBytes(k),R=e.fromBytes(gt(Vo((_&1)===0),D)),N=o.inv(k),j=U(K(m,void 0,"msgHash")),z=o.create(-j*N),q=o.create(L*N),X=e.BASE.multiplyUnsafe(z).add(R.multiplyUnsafe(q));if(X.is0())throw new Error("invalid recovery: point at infinify");return X.assertValidity(),X}hasHighS(){return S(this.s)}toBytes(m=p.format){if(Ps(m),m==="der")return qt(re.hexFromSig(this));let{r:A,s:L}=this,_=o.toBytes(A),k=o.toBytes(L);return m==="recovered"?(I(),gt(Uint8Array.of(this.assertRecovery()),_,k)):gt(_,k)}toHex(m){return Ot(this.toBytes(m))}}let C=r.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let A=De(m),L=m.length*8-a;return L>0?A>>BigInt(L):A},U=r.bits2int_modN||function(m){return o.create(C(m))},M=je(a);function E(g){return Ge("num < 2^"+a,g,Ft,M),o.toBytes(g)}function x(g,m){return K(g,void 0,"message"),m?K(t(g),void 0,"prehashed message"):g}function P(g,m,A){let{lowS:L,prehash:_,extraEntropy:k}=Cs(A,p);g=x(g,_);let D=U(g),R=o.fromBytes(m);if(!o.isValidNot0(R))throw new Error("invalid private key");let N=[E(R),E(D)];if(k!=null&&k!==!1){let X=k===!0?n(d.secretKey):k;N.push(K(X,void 0,"extraEntropy"))}let j=gt(...N),z=D;function q(X){let it=C(X);if(!o.isValidNot0(it))return;let Dt=o.inv(it),W=e.BASE.multiply(it).toAffine(),at=o.create(W.x);if(at===Ft)return;let vr=o.create(Dt*o.create(z+at*R));if(vr===Ft)return;let Js=(W.x===at?0:2)|Number(W.y&Pe),Qs=vr;return L&&S(vr)&&(Qs=o.neg(vr),Js^=1),new B(at,Qs,v?void 0:Js)}return{seed:j,k2sig:q}}function O(g,m,A={}){let{seed:L,k2sig:_}=P(g,m,A);return Yi(t.outputLen,o.BYTES,i)(L,_).toBytes(A.format)}function T(g,m,A,L={}){let{lowS:_,prehash:k,format:D}=Cs(L,p);if(A=K(A,void 0,"publicKey"),m=x(m,k),!oe(g)){let R=g instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+R)}w(g,D);try{let R=B.fromBytes(g,D),N=e.fromBytes(A);if(_&&R.hasHighS())return!1;let{r:j,s:z}=R,q=U(m),X=o.inv(z),it=o.create(q*X),Dt=o.create(j*X),W=e.BASE.multiplyUnsafe(it).add(N.multiplyUnsafe(Dt));return W.is0()?!1:o.create(W.x)===j}catch{return!1}}function y(g,m,A={}){let{prehash:L}=Cs(A,p);return m=x(m,L),B.fromBytes(g,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:h,utils:l,lengths:d,Point:e,sign:O,verify:T,recoverPublicKey:y,Signature:B,hash:t})}var Us={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Uu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Fo=BigInt(2);function Mu(e){let t=Us.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,f=u*u*e%t,h=Z(f,r,t)*f%t,l=Z(h,r,t)*f%t,d=Z(l,Fo,t)*u%t,p=Z(d,i,t)*d%t,v=Z(p,s,t)*p%t,S=Z(v,c,t)*v%t,b=Z(S,a,t)*S%t,I=Z(b,c,t)*v%t,w=Z(I,r,t)*f%t,B=Z(w,o,t)*p%t,C=Z(B,n,t)*u%t,U=Z(C,Fo,t);if(!Ks.eql(Ks.sqr(U),e))throw new Error("Cannot find square root");return U}var Ks=Te(Us.p,{sqrt:Mu}),Ou=qo(Us,{Fp:Ks,endo:Uu}),Ne=$o(Ou,Le);function zo(e,t,r,n){let i=ie.digest(r instanceof Uint8Array?r:r.subarray());if(qr(i))return i.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ne.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Je(String(s))});try{return n?.signal?.throwIfAborted(),Ne.verify(t,i.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Je(String(s))}}var jr=class{type="secp256k1";raw;_key;constructor(t){this._key=Yo(t),this.raw=Zo(this._key)}toMultihash(){return It.digest(Kt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,r,n){return zo(this._key,r,t,n)}};function Ms(e){return new jr(e)}function Zo(e){return Ne.Point.fromBytes(e).toBytes()}function Yo(e){try{return Ne.Point.fromBytes(e),e}catch(t){throw new ge(String(t))}}function Os(e,t){let{Type:r,Data:n}=Rt.decode(e),i=n??new Uint8Array;switch(r){case G.RSA:return _s(i,t);case G.Ed25519:return ns(i);case G.secp256k1:return Ms(i);case G.ECDSA:return Rn(i);default:throw new ne}}function Go(e){let{Type:t,Data:r}=Rt.decode(e.digest),n=r??new Uint8Array;switch(t){case G.Ed25519:return ns(n);case G.secp256k1:return Ms(n);case G.ECDSA:return Rn(n);default:throw new ne}}function Kt(e){return Rt.encode({Type:G[e.type],Data:e.raw})}var jo=Symbol.for("nodejs.util.inspect.custom"),qu=114,sr=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()})`}[nn]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(qu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return mt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return mt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[jo](){return`PeerId(${this.toString()})`}},ir=class extends sr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},or=class extends sr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},ar=class extends sr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Vu=2336,Xr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=It.digest($(this.url))}[jo](){return`PeerId(${this.url})`}[nn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(Vu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};function qs(e){if(e.type==="Ed25519")return new or({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new ar({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new ir({multihash:e.toCID().multihash,publicKey:e});throw new ne}function Xo(e){return qs(e.publicKey)}function cr(e){if($u(e))return new ir({multihash:e});if(Hu(e))try{let t=Go(e);if(t.type==="Ed25519")return new or({multihash:e,publicKey:t});if(t.type==="secp256k1")return new ar({multihash:e,publicKey:t})}catch{let r=H(e.digest);return new Xr(new URL(r))}throw new Ar("Supplied PeerID Multihash is invalid")}function Hu(e){return e.code===It.code}function $u(e){return e.code===ie.code}function me(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),i=n.value;return n.done===!0||i==null?{done:!0,value:void 0}:{done:!1,value:t(i)}}};return r}function Wr(e){let t=Zt(Y.decode(`z${e}`));return cr(t)}var ur=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return me(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return me(this.map.values(),t=>t.key)}values(){return me(this.map.values(),t=>t.value)}get size(){return this.map.size}};var fr=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.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 me(this.set.entries(),t=>{let r=Wr(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=Wr(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return me(this.set.values(),t=>Wr(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};var Vs=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},Wo=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function lr(e,t){let{milliseconds:r,fallback:n,message:i,customTimers:s={setTimeout,clearTimeout},signal:o}=t,c,a,f=new Promise((h,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(o?.aborted){l(Wo(o));return}if(o&&(a=()=>{l(Wo(o))},o.addEventListener("abort",a,{once:!0})),e.then(h,l),r===Number.POSITIVE_INFINITY)return;let d=new Vs;c=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(p){l(p)}return}typeof e.cancel=="function"&&e.cancel(),i===!1?h():i instanceof Error?l(i):(d.message=i??`Promise timed out after ${r} milliseconds`,l(d))},r)}).finally(()=>{f.clear(),a&&o&&o.removeEventListener("abort",a)});return f.clear=()=>{s.clearTimeout.call(void 0,c),c=void 0},f}var Fu=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function zu(e,t,r){let n,i=new Promise((s,o)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let c=[t].flat(),a=[],{addListener:u,removeListener:f}=Fu(e),h=async(...d)=>{let p=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(p))return}catch(v){n(),o(v);return}a.push(p),r.count===a.length&&(n(),s(a))},l=(...d)=>{n(),o(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of c)f(d,h);for(let d of r.rejectionEvents)c.includes(d)||f(d,l)};for(let d of c)u(d,h);for(let d of r.rejectionEvents)c.includes(d)||u(d,l);r.signal&&r.signal.addEventListener("abort",()=>{l(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(a)});if(i.cancel=n,typeof r.timeout=="number"){let s=lr(i,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return i}function Jo(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=zu(e,t,r),i=n.then(s=>s[0]);return i.cancel=n.cancel,i}var be=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Zu(e){return e.reason}async function Hs(e,t,r){if(t==null)return e;let n=r?.translateError??Zu;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let i;try{return await Promise.race([e,new Promise((s,o)=>{i=()=>{o(n(t))},t.addEventListener("abort",i)})])}finally{i!=null&&t.removeEventListener("abort",i)}}var Gu=4194304,Jr=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"},Zs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function ju(e){return typeof e?.closeRead=="function"}function Xu(e){return typeof e?.close=="function"}function $s(e){return ju(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Xu(e)?e.status!=="open":!1}function Wu(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Ju(e,t){let r=t?.maxBufferSize??Gu,n=new rt,i,s=!1;if(!Wu(e))throw new F("Argument should be a Stream or a Multiaddr");let o=f=>{if(n.append(f.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),i?.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}i?.resolve()};e.addEventListener("message",o);let c=f=>{f.error!=null?i?.reject(f.error):i?.resolve()};e.addEventListener("close",c);let a=()=>{i?.resolve()};e.addEventListener("remoteCloseWrite",a);let u={readBuffer:n,async read(f){if(s===!0)throw new Jr("Stream was unwrapped");if($s(e)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new be(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let h=f?.bytes??1;for(i=Promise.withResolvers();;){if(n.byteLength>=h){i.resolve();break}if(await Hs(i.promise,f?.signal),$s(e)){if(n.byteLength===0&&f?.bytes==null)return null;break}i=Promise.withResolvers()}let l=f?.bytes??n.byteLength;if(n.byteLength<l){if($s(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,l),new be(`Unexpected EOF - stream closed while reading ${n.byteLength}/${l} bytes`);return u.read(f)}let d=n.sublist(0,l);return n.consume(l),d},async write(f,h){if(s===!0)throw new Jr("Stream was unwrapped");e.send(f)||await Jo(e,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",o),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return u}function Qu(e,t={}){let r=Ju(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=$t(t.maxDataLength));let n=t?.lengthDecoder??Eo,i=t?.lengthEncoder??xo;return{async read(o){let c=-1,a=new rt;for(;;){let f=await r.read({...o,bytes:1});if(f==null)break;a.append(f);try{c=n(a)}catch(h){if(h instanceof RangeError)continue;throw h}if(c<0)throw new Fs("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new Zs(`Message length length too long - ${a.byteLength} > ${t.maxLengthLength}`);if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new zs(`Message length too long - ${c} > ${t.maxDataLength}`);let u=await r.read({...o,bytes:c});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",c),new be(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(u.byteLength!==c)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,c),new be(`Unexpected EOF - read ${u.byteLength}/${c} bytes before the stream closed`);return u},async write(o,c){await r.write(new rt(i(o.byteLength),o),c)},async writeV(o,c){let a=new rt(...o.flatMap(u=>[i(u.byteLength),u]));await r.write(a,c)},unwrap(){return r.unwrap()}}}function Ys(e,t){let r=Qu(e,t),n={read:async(i,s)=>{let o=await r.read(s);return i.decode(o)},write:async(i,s,o)=>{await r.write(s.encode(i),o)},writeV:async(i,s,o)=>{await r.writeV(i.map(c=>s.encode(c)),o)},pb:i=>({read:async s=>n.read(i,s),write:async(s,o)=>n.write(s,i,o),writeV:async(s,o)=>n.writeV(s,i,o),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var js=pa(ta(),1);function Xs(e,t,r){let n=0,i=e.length;for(;i>0;){let s=Math.trunc(i/2),o=n+s;r(e[o],t)<=0?(n=++o,i-=s+1):i=s}return n}var dr=class{#t=[];enqueue(t,r){let{priority:n=0,id:i}=r??{},s={priority:n,id:i,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(s);return}let o=Xs(this.#t,s,(c,a)=>a.priority-c.priority);this.#t.splice(o,0,s)}setPriority(t,r){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[i]=this.#t.splice(n,1);this.enqueue(i.run,{priority:r,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#t.length}};var pr=class extends js.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;#R=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:dr,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.#_()}#O(t){if(this.#i){if(this.#x(t),this.#E()>=this.#d){let n=this.#s[this.#n],i=this.#c-(t-n);return this.#v(i),!0}return!1}if(this.#u===void 0){let r=this.#B-t;if(r<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(r),!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)}#D(){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.#D(),this.#i&&this.#n>0){let r=Date.now();this.#x(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#O(r);if(this.#N&&this.#K){let i=this.#e.dequeue();this.#o||(this.#C(r),this.#p()),this.emit("active"),i(),n&&this.#_(),t=!0}}return t}#_(){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,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#e.setPriority(t,r)}async add(t,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#R++).toString()},new Promise((n,i)=>{let s=Symbol(`task-${r.id}`);this.#e.enqueue(async()=>{this.#r++,this.#y.set(s,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let o;try{try{r.signal?.throwIfAborted()}catch(u){throw this.#V(),this.#y.delete(s),u}this.#w=Date.now();let c=t({signal:r.signal});if(r.timeout&&(c=lr(Promise.resolve(c),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#r} running, ${this.#e.size} waiting)`})),r.signal){let{signal:u}=r;c=Promise.race([c,new Promise((f,h)=>{o=()=>{h(u.reason)},u.addEventListener("abort",o,{once:!0})})])}let a=await c;n(a),this.emit("completed",a)}catch(c){i(c),this.emit("error",c)}finally{o&&r.signal?.removeEventListener("abort",o),this.#y.delete(s),queueMicrotask(()=>{this.#U()})}},r),this.emit("add"),this.#A()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#I(),this):this}pause(){this.#l=!0}clear(){this.#e=new this.#L,this.#S(),this.#k(),this.emit("empty"),this.#r===0&&(this.#D(),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,r)=>{let n=i=>{this.off("error",n),r(i)};this.on("error",n)})}async#h(t,r){return new Promise(n=>{let i=()=>{r&&!r()||(this.off(t,i),n())};this.on(t,i)})}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.#k()}))}#V(){this.#o||(this.#P(),this.#p())}#k(){let t=this.#m;if(this.#o||this.#e.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#i){let i=Date.now();this.#x(i),r=this.#E()}else r=this.#a;let n=r>=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 tn=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,r){this.entries.set(t,{value:r,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[r,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(r);else break}}has(t){return this.entries.has(t)}get(t){let r=this.entries.get(t);return r!=null&&r.validUntilMs>=Date.now()?r.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var ye;(function(e){let t;(function(c){let a;c.codec=()=>(a==null&&(a=vt((l,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),l.subscribe!=null&&(d.uint32(8),d.bool(l.subscribe)),l.topic!=null&&(d.uint32(18),d.string(l.topic)),p.lengthDelimited!==!1&&d.ldelim()},(l,d,p={})=>{let v={},S=d==null?l.len:l.pos+d;for(;l.pos<S;){let b=l.uint32();switch(b>>>3){case 1:{v.subscribe=l.bool();break}case 2:{v.topic=l.string();break}default:{l.skipType(b&7);break}}}return v},function*(l,d,p,v={}){let S=d==null?l.len:l.pos+d;for(;l.pos<S;){let b=l.uint32();switch(b>>>3){case 1:{yield{field:`${p}.subscribe`,value:l.bool()};break}case 2:{yield{field:`${p}.topic`,value:l.string()};break}default:{l.skipType(b&7);break}}}})),a);function u(l){return xt(l,c.codec())}c.encode=u;function f(l,d){return wt(l,c.codec(),d)}c.decode=f;function h(l,d){return Et(l,c.codec(),d)}c.stream=h})(t=e.SubOpts||(e.SubOpts={}));let r;(function(c){let a;c.codec=()=>(a==null&&(a=vt((l,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),l.from!=null&&(d.uint32(10),d.bytes(l.from)),l.data!=null&&(d.uint32(18),d.bytes(l.data)),l.sequenceNumber!=null&&(d.uint32(26),d.bytes(l.sequenceNumber)),l.topic!=null&&(d.uint32(34),d.string(l.topic)),l.signature!=null&&(d.uint32(42),d.bytes(l.signature)),l.key!=null&&(d.uint32(50),d.bytes(l.key)),p.lengthDelimited!==!1&&d.ldelim()},(l,d,p={})=>{let v={},S=d==null?l.len:l.pos+d;for(;l.pos<S;){let b=l.uint32();switch(b>>>3){case 1:{v.from=l.bytes();break}case 2:{v.data=l.bytes();break}case 3:{v.sequenceNumber=l.bytes();break}case 4:{v.topic=l.string();break}case 5:{v.signature=l.bytes();break}case 6:{v.key=l.bytes();break}default:{l.skipType(b&7);break}}}return v},function*(l,d,p,v={}){let S=d==null?l.len:l.pos+d;for(;l.pos<S;){let b=l.uint32();switch(b>>>3){case 1:{yield{field:`${p}.from`,value:l.bytes()};break}case 2:{yield{field:`${p}.data`,value:l.bytes()};break}case 3:{yield{field:`${p}.sequenceNumber`,value:l.bytes()};break}case 4:{yield{field:`${p}.topic`,value:l.string()};break}case 5:{yield{field:`${p}.signature`,value:l.bytes()};break}case 6:{yield{field:`${p}.key`,value:l.bytes()};break}default:{l.skipType(b&7);break}}}})),a);function u(l){return xt(l,c.codec())}c.encode=u;function f(l,d){return wt(l,c.codec(),d)}c.decode=f;function h(l,d){return Et(l,c.codec(),d)}c.stream=h})(r=e.Message||(e.Message={}));let n;e.codec=()=>(n==null&&(n=vt((c,a,u={})=>{if(u.lengthDelimited!==!1&&a.fork(),c.subscriptions!=null&&c.subscriptions.length>0)for(let f of c.subscriptions)a.uint32(10),e.SubOpts.codec().encode(f,a);if(c.messages!=null&&c.messages.length>0)for(let f of c.messages)a.uint32(18),e.Message.codec().encode(f,a);c.control!=null&&(a.uint32(26),mr.codec().encode(c.control,a)),u.lengthDelimited!==!1&&a.ldelim()},(c,a,u={})=>{let f={subscriptions:[],messages:[]},h=a==null?c.len:c.pos+a;for(;c.pos<h;){let l=c.uint32();switch(l>>>3){case 1:{if(u.limits?.subscriptions!=null&&f.subscriptions.length===u.limits.subscriptions)throw new et('Decode error - repeated field "subscriptions" had too many elements');f.subscriptions.push(e.SubOpts.codec().decode(c,c.uint32(),{limits:u.limits?.subscriptions$}));break}case 2:{if(u.limits?.messages!=null&&f.messages.length===u.limits.messages)throw new et('Decode error - repeated field "messages" had too many elements');f.messages.push(e.Message.codec().decode(c,c.uint32(),{limits:u.limits?.messages$}));break}case 3:{f.control=mr.codec().decode(c,c.uint32(),{limits:u.limits?.control});break}default:{c.skipType(l&7);break}}}return f},function*(c,a,u,f={}){let h={subscriptions:0,messages:0},l=a==null?c.len:c.pos+a;for(;c.pos<l;){let d=c.uint32();switch(d>>>3){case 1:{if(f.limits?.subscriptions!=null&&h.subscriptions===f.limits.subscriptions)throw new et('Streaming decode error - repeated field "subscriptions" had too many elements');for(let p of e.SubOpts.codec().stream(c,c.uint32(),`${u}.subscriptions[]`,{limits:f.limits?.subscriptions$}))yield{...p,index:h.subscriptions};h.subscriptions++;break}case 2:{if(f.limits?.messages!=null&&h.messages===f.limits.messages)throw new et('Streaming decode error - repeated field "messages" had too many elements');for(let p of e.Message.codec().stream(c,c.uint32(),`${u}.messages[]`,{limits:f.limits?.messages$}))yield{...p,index:h.messages};h.messages++;break}case 3:{yield*mr.codec().stream(c,c.uint32(),`${u}.control`,{limits:f.limits?.control});break}default:{c.skipType(d&7);break}}}})),n);function i(c){return xt(c,e.codec())}e.encode=i;function s(c,a){return wt(c,e.codec(),a)}e.decode=s;function o(c,a){return Et(c,e.codec(),a)}e.stream=o})(ye||(ye={}));var mr;(function(e){let t;e.codec=()=>(t==null&&(t=vt((s,o,c={})=>{if(c.lengthDelimited!==!1&&o.fork(),s.ihave!=null&&s.ihave.length>0)for(let a of s.ihave)o.uint32(10),br.codec().encode(a,o);if(s.iwant!=null&&s.iwant.length>0)for(let a of s.iwant)o.uint32(18),yr.codec().encode(a,o);if(s.graft!=null&&s.graft.length>0)for(let a of s.graft)o.uint32(26),gr.codec().encode(a,o);if(s.prune!=null&&s.prune.length>0)for(let a of s.prune)o.uint32(34),wr.codec().encode(a,o);c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={ihave:[],iwant:[],graft:[],prune:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(c.limits?.ihave!=null&&a.ihave.length===c.limits.ihave)throw new et('Decode error - repeated field "ihave" had too many elements');a.ihave.push(br.codec().decode(s,s.uint32(),{limits:c.limits?.ihave$}));break}case 2:{if(c.limits?.iwant!=null&&a.iwant.length===c.limits.iwant)throw new et('Decode error - repeated field "iwant" had too many elements');a.iwant.push(yr.codec().decode(s,s.uint32(),{limits:c.limits?.iwant$}));break}case 3:{if(c.limits?.graft!=null&&a.graft.length===c.limits.graft)throw new et('Decode error - repeated field "graft" had too many elements');a.graft.push(gr.codec().decode(s,s.uint32(),{limits:c.limits?.graft$}));break}case 4:{if(c.limits?.prune!=null&&a.prune.length===c.limits.prune)throw new et('Decode error - repeated field "prune" had too many elements');a.prune.push(wr.codec().decode(s,s.uint32(),{limits:c.limits?.prune$}));break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u={ihave:0,iwant:0,graft:0,prune:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let h=s.uint32();switch(h>>>3){case 1:{if(a.limits?.ihave!=null&&u.ihave===a.limits.ihave)throw new et('Streaming decode error - repeated field "ihave" had too many elements');for(let l of br.codec().stream(s,s.uint32(),`${c}.ihave[]`,{limits:a.limits?.ihave$}))yield{...l,index:u.ihave};u.ihave++;break}case 2:{if(a.limits?.iwant!=null&&u.iwant===a.limits.iwant)throw new et('Streaming decode error - repeated field "iwant" had too many elements');for(let l of yr.codec().stream(s,s.uint32(),`${c}.iwant[]`,{limits:a.limits?.iwant$}))yield{...l,index:u.iwant};u.iwant++;break}case 3:{if(a.limits?.graft!=null&&u.graft===a.limits.graft)throw new et('Streaming decode error - repeated field "graft" had too many elements');for(let l of gr.codec().stream(s,s.uint32(),`${c}.graft[]`,{limits:a.limits?.graft$}))yield{...l,index:u.graft};u.graft++;break}case 4:{if(a.limits?.prune!=null&&u.prune===a.limits.prune)throw new et('Streaming decode error - repeated field "prune" had too many elements');for(let l of wr.codec().stream(s,s.uint32(),`${c}.prune[]`,{limits:a.limits?.prune$}))yield{...l,index:u.prune};u.prune++;break}default:{s.skipType(h&7);break}}}})),t);function r(s){return xt(s,e.codec())}e.encode=r;function n(s,o){return wt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(mr||(mr={}));var br;(function(e){let t;e.codec=()=>(t==null&&(t=vt((s,o,c={})=>{if(c.lengthDelimited!==!1&&o.fork(),s.topic!=null&&(o.uint32(10),o.string(s.topic)),s.messageIDs!=null&&s.messageIDs.length>0)for(let a of s.messageIDs)o.uint32(18),o.bytes(a);c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={messageIDs:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.topic=s.string();break}case 2:{if(c.limits?.messageIDs!=null&&a.messageIDs.length===c.limits.messageIDs)throw new et('Decode error - repeated field "messageIDs" had too many elements');a.messageIDs.push(s.bytes());break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u={messageIDs:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let h=s.uint32();switch(h>>>3){case 1:{yield{field:`${c}.topic`,value:s.string()};break}case 2:{if(a.limits?.messageIDs!=null&&u.messageIDs===a.limits.messageIDs)throw new et('Streaming decode error - repeated field "messageIDs" had too many elements');yield{field:`${c}.messageIDs[]`,index:u.messageIDs,value:s.bytes()},u.messageIDs++;break}default:{s.skipType(h&7);break}}}})),t);function r(s){return xt(s,e.codec())}e.encode=r;function n(s,o){return wt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(br||(br={}));var yr;(function(e){let t;e.codec=()=>(t==null&&(t=vt((s,o,c={})=>{if(c.lengthDelimited!==!1&&o.fork(),s.messageIDs!=null&&s.messageIDs.length>0)for(let a of s.messageIDs)o.uint32(10),o.bytes(a);c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={messageIDs:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(c.limits?.messageIDs!=null&&a.messageIDs.length===c.limits.messageIDs)throw new et('Decode error - repeated field "messageIDs" had too many elements');a.messageIDs.push(s.bytes());break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u={messageIDs:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let h=s.uint32();switch(h>>>3){case 1:{if(a.limits?.messageIDs!=null&&u.messageIDs===a.limits.messageIDs)throw new et('Streaming decode error - repeated field "messageIDs" had too many elements');yield{field:`${c}.messageIDs[]`,index:u.messageIDs,value:s.bytes()},u.messageIDs++;break}default:{s.skipType(h&7);break}}}})),t);function r(s){return xt(s,e.codec())}e.encode=r;function n(s,o){return wt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(yr||(yr={}));var gr;(function(e){let t;e.codec=()=>(t==null&&(t=vt((s,o,c={})=>{c.lengthDelimited!==!1&&o.fork(),s.topic!=null&&(o.uint32(10),o.string(s.topic)),c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.topic=s.string();break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.topic`,value:s.string()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return xt(s,e.codec())}e.encode=r;function n(s,o){return wt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(gr||(gr={}));var wr;(function(e){let t;e.codec=()=>(t==null&&(t=vt((s,o,c={})=>{if(c.lengthDelimited!==!1&&o.fork(),s.topic!=null&&(o.uint32(10),o.string(s.topic)),s.peers!=null&&s.peers.length>0)for(let a of s.peers)o.uint32(18),xr.codec().encode(a,o);s.backoff!=null&&(o.uint32(24),o.uint64(s.backoff)),c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={peers:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.topic=s.string();break}case 2:{if(c.limits?.peers!=null&&a.peers.length===c.limits.peers)throw new et('Decode error - repeated field "peers" had too many elements');a.peers.push(xr.codec().decode(s,s.uint32(),{limits:c.limits?.peers$}));break}case 3:{a.backoff=s.uint64();break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u={peers:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let h=s.uint32();switch(h>>>3){case 1:{yield{field:`${c}.topic`,value:s.string()};break}case 2:{if(a.limits?.peers!=null&&u.peers===a.limits.peers)throw new et('Streaming decode error - repeated field "peers" had too many elements');for(let l of xr.codec().stream(s,s.uint32(),`${c}.peers[]`,{limits:a.limits?.peers$}))yield{...l,index:u.peers};u.peers++;break}case 3:{yield{field:`${c}.backoff`,value:s.uint64()};break}default:{s.skipType(h&7);break}}}})),t);function r(s){return xt(s,e.codec())}e.encode=r;function n(s,o){return wt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(wr||(wr={}));var xr;(function(e){let t;e.codec=()=>(t==null&&(t=vt((s,o,c={})=>{c.lengthDelimited!==!1&&o.fork(),s.peerID!=null&&(o.uint32(10),o.bytes(s.peerID)),s.signedPeerRecord!=null&&(o.uint32(18),o.bytes(s.signedPeerRecord)),c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.peerID=s.bytes();break}case 2:{a.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.peerID`,value:s.bytes()};break}case 2:{yield{field:`${c}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return xt(s,e.codec())}e.encode=r;function n(s,o){return wt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(xr||(xr={}));var en=class extends we{peerId;shutDownController;inboundPb;outboundPb;constructor(t){super(),this.peerId=t,this.shutDownController=new AbortController}attachInboundStream(t,r){this.inboundPb=Ys(t,r).pb(ye),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,r){this.outboundPb=Ys(t,r).pb(ye)}write(t){this.outboundPb!=null&&this.outboundPb.write(t,{signal:this.shutDownController.signal}).catch(r=>{this.outboundPb?.unwrap().unwrap().abort(r)})}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 ea(){return BigInt(`0x${H(Zr(8),"base16")}`)}var ra=(e,t)=>{let r=$(t.toString(16).padStart(16,"0"),"base16"),n=Kt(e),i=new Uint8Array(n.byteLength+r.length);return i.set(n,0),i.set(r,n.byteLength),i},na=e=>ie.encode(e);var rf=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=cr(Zt(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return qs(Os(r)).equals(t)}return!1},sa=async e=>{if(e.from==null)throw new Q("RPC message was missing from");if(!await rf(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=cr(Zt(e.from)),r=e.key??t.publicKey;if(r==null)throw new Q("RPC message was missing public key");return{type:"signed",from:t,topic:e.topic??"",sequenceNumber:sf(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?Os(r):r}},Er=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:nf(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Kt(e.key):void 0}:{data:e.data,topic:e.topic},nf=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),$(t,"base16")},sf=e=>BigInt(`0x${H(e,"base16")}`);var ia=$("libp2p-pubsub:");async function oa(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Xo(e)},i=se([ia,r(Er(n)).subarray()]);return n.signature=await e.sign(i),n.key=e.publicKey,n}async function aa(e,t){if(e.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(e.signature==null)throw new Error("Message must contain a signature to be verified");if(e.from==null)throw new Error("Message must contain a from property to be verified");let r=se([ia,t({...Er(e),signature:void 0,key:void 0}).subarray()]);return of(e).verify(r,e.signature)}function of(e){if(e.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(e.from==null)throw new Error("Could not get the public key from the originator id");if(e.key!=null)return e.key;if(e.from.publicKey!=null)return e.from.publicKey;throw new Error("Could not get the public key from the originator id")}var rn=class extends we{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;constructor(t,r){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocol=r.protocol??Ws,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new ur,this.globalSignaturePolicy=r.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=r.canRelayMessage??!0,this.emitSelf=r.emitSelf??!1,this.topicValidators=new Map,this.queue=new pr({concurrency:r.messageProcessingConcurrency??10}),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.seenCache=new tn({validityMs:r?.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";[ei]=["@libp2p/pubsub"];[ri]=["@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 r of this.peers.values())r.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t,r){this.addPeer(r.remotePeer,t).attachInboundStream(t)}async _onPeerConnected(t,r){if(this.log("connected %p",t),r.streams.find(s=>s.direction==="outbound"&&s.protocol===this.protocol)){this.log("outbound pubsub stream already present on connection from %p",t);return}let n=await r.newStream(this.protocol);this.addPeer(t,n).attachOutboundStream(n),this.send(t,{subscriptions:Array.from(this.subscriptions).map(s=>s.toString()),subscribe:!0})}_onPeerDisconnected(t,r){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,r){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let i=new en(t);return this.peers.set(t,i),i.addEventListener("message",s=>{let o=s.detail,c=[];for(let a of o.messages??[]){if(a.from==null||a.data==null||a.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}c.push({from:a.from,data:a.data,topic:a.topic,sequenceNumber:a.sequenceNumber??void 0,signature:a.signature??void 0,key:a.key??void 0})}this.processRpc(i,{subscriptions:(o.subscriptions??[]).map(a=>({subscribe:!!a.subscribe,topic:a.topic??""})),messages:c}).catch(a=>{this.log(a)})}),i.addEventListener("close",()=>this._removePeer(t),{once:!0}),i}_removePeer(t){let r=this.peers.get(t);if(r!=null){r.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t)}}async processRpc(t,r){this.log("rpc from %p",t.peerId);let{subscriptions:n,messages:i}=r;return n!=null&&n.length>0&&(this.log("subscription update from %p",t.peerId),n.forEach(s=>{this.processRpcSubOpt(t.peerId,s)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:t.peerId,subscriptions:n.map(({topic:s,subscribe:o})=>({topic:`${s??""}`,subscribe:!!o}))}}))),i!=null&&i.length>0&&(this.log("messages from %p",t.peerId),this.queue.addAll(i.map(s=>async()=>{if(s.topic==null||!this.subscriptions.has(s.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let o=await sa(s);await this.processMessage(t.peerId,o)}catch(o){this.log.error("failed to queue messages from %p - %e",t.peerId,o)}})).catch(s=>{this.log(s)})),!0}processRpcSubOpt(t,r){let n=r.topic;if(n==null)return;let i=this.topics.get(n);i==null&&(i=new fr,this.topics.set(n,i)),r.subscribe===!0?i.add(t):i.delete(t)}async processMessage(t,r){if(this.components.peerId.equals(t)&&!this.emitSelf)return;let n=await this.getMsgId(r),i=H(n,"base64");if(!this.seenCache.has(i)){this.seenCache.put(i,!0);try{await this.validate(t,r)}catch(s){this.log("Message is invalid, dropping it. %O",s);return}this.subscriptions.has(r.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:r})),await this.publishMessage(t,r)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new Q("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new Q("Need key when signature policy is StrictSign but it was missing");return ra(t.key,t.sequenceNumber);case"StrictNoSign":return na(t.data);default:throw new Q("Cannot get message id: unhandled signature policy")}}encodeMessage(t){return ye.Message.encode(t)}send(t,r){let{messages:n,subscriptions:i,subscribe:s}=r;this.sendRpc(t,{subscriptions:(i??[]).map(o=>({topic:o,subscribe:!!s})),messages:(n??[]).map(Er)})}sendRpc(t,r){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(r)}async validate(t,r){switch(this.globalSignaturePolicy){case"StrictNoSign":if(r.type!=="unsigned")throw new Q('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new Q("StrictNoSigning: signature should not be present");if(r.key!=null)throw new Q("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new Q("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new Q("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new Q("StrictSigning: Signing required and no sequenceNumber was present");if(!await aa(r,this.encodeMessage.bind(this)))throw new Q("StrictSigning: Invalid message signature");break;default:throw new Q("Cannot validate message: unhandled signature policy")}let i=this.topicValidators.get(r.topic);if(i!=null){let s=await i(t,r);if(s===Ke.Reject||s===Ke.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return oa(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new Q("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Ir("not started yet");if(t==null)throw new F("Topic is required");let r=this.topics.get(t.toString());return r==null?[]:Array.from(r.values())}async publish(t,r){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:r??new Uint8Array(0),sequenceNumber:ea()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let i=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:i})));let o=await this.publishMessage(this.components.peerId,i);return s&&(o.recipients=[...o.recipients,this.components.peerId]),o}async publishMessage(t,r){let n=this.getSubscribers(r.topic),i=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:i}):(n.forEach(s=>{if(this.components.peerId.equals(s)){this.log("not sending message on topic %s to myself",r.topic);return}if(s.equals(t)){this.log("not sending message on topic %s to sender %p",r.topic,s);return}this.log("publish msgs on topics %s %p",r.topic,s),i.push(s),this.send(s,{messages:[r]})}),{recipients:i})}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 r of this.peers.keys())this.send(r,{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 r of this.peers.keys())this.send(r,{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 Ws="/floodsub/1.0.0",af="StrictSign",cf="StrictNoSign",Ke;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(Ke||(Ke={}));function uf(e){return!!e?.[Ue]}function ff(e={}){return t=>new rn(t,e)}return ma(lf);})();
2
+ "use strict";var Libp2PFloodsub=(()=>{var Ia=Object.create;var Br=Object.defineProperty;var Ba=Object.getOwnPropertyDescriptor;var La=Object.getOwnPropertyNames;var Da=Object.getPrototypeOf,_a=Object.prototype.hasOwnProperty;var Ta=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),pt=(e,t)=>{for(var r in t)Br(e,r,{get:t[r],enumerable:!0})},fi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of La(t))!_a.call(e,i)&&i!==r&&Br(e,i,{get:()=>t[i],enumerable:!(n=Ba(t,i))||n.enumerable});return e};var ka=(e,t,r)=>(r=e!=null?Ia(Da(e)):{},fi(t||!e||!e.__esModule?Br(r,"default",{value:e,enumerable:!0}):r,e)),Ca=e=>fi(Br({},"__esModule",{value:!0}),e);var ya=Ta((jm,si)=>{"use strict";var vf=Object.prototype.hasOwnProperty,dt="~";function br(){}Object.create&&(br.prototype=Object.create(null),new br().__proto__||(dt=!1));function Af(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function ba(e,t,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new Af(r,n||e,i),o=dt?dt+t:t;return e._events[o]?e._events[o].fn?e._events[o]=[e._events[o],s]:e._events[o].push(s):(e._events[o]=s,e._eventsCount++),e}function on(e,t){--e._eventsCount===0?e._events=new br:delete e._events[t]}function lt(){this._events=new br,this._eventsCount=0}lt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)vf.call(r,n)&&t.push(dt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};lt.prototype.listeners=function(t){var r=dt?dt+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,o=new Array(s);i<s;i++)o[i]=n[i].fn;return o};lt.prototype.listenerCount=function(t){var r=dt?dt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};lt.prototype.emit=function(t,r,n,i,s,o){var c=dt?dt+t:t;if(!this._events[c])return!1;var a=this._events[c],u=arguments.length,f,l;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),u){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,r),!0;case 3:return a.fn.call(a.context,r,n),!0;case 4:return a.fn.call(a.context,r,n,i),!0;case 5:return a.fn.call(a.context,r,n,i,s),!0;case 6:return a.fn.call(a.context,r,n,i,s,o),!0}for(l=1,f=new Array(u-1);l<u;l++)f[l-1]=arguments[l];a.fn.apply(a.context,f)}else{var h=a.length,d;for(l=0;l<h;l++)switch(a[l].once&&this.removeListener(t,a[l].fn,void 0,!0),u){case 1:a[l].fn.call(a[l].context);break;case 2:a[l].fn.call(a[l].context,r);break;case 3:a[l].fn.call(a[l].context,r,n);break;case 4:a[l].fn.call(a[l].context,r,n,i);break;default:if(!f)for(d=1,f=new Array(u-1);d<u;d++)f[d-1]=arguments[d];a[l].fn.apply(a[l].context,f)}}return!0};lt.prototype.on=function(t,r,n){return ba(this,t,r,n,!1)};lt.prototype.once=function(t,r,n){return ba(this,t,r,n,!0)};lt.prototype.removeListener=function(t,r,n,i){var s=dt?dt+t:t;if(!this._events[s])return this;if(!r)return on(this,s),this;var o=this._events[s];if(o.fn)o.fn===r&&(!i||o.once)&&(!n||o.context===n)&&on(this,s);else{for(var c=0,a=[],u=o.length;c<u;c++)(o[c].fn!==r||i&&!o[c].once||n&&o[c].context!==n)&&a.push(o[c]);a.length?this._events[s]=a.length===1?a[0]:a:on(this,s)}return this};lt.prototype.removeAllListeners=function(t){var r;return t?(r=dt?dt+t:t,this._events[r]&&on(this,r)):(this._events=new br,this._eventsCount=0),this};lt.prototype.off=lt.prototype.removeListener;lt.prototype.addListener=lt.prototype.on;lt.prefixed=dt;lt.EventEmitter=lt;typeof si<"u"&&(si.exports=lt)});var Rf={};pt(Rf,{StrictNoSign:()=>Tf,StrictSign:()=>_f,TopicValidatorResult:()=>Me,floodsub:()=>Cf,isPubSub:()=>kf,protocol:()=>ai,pubSubSymbol:()=>qe});var qe=Symbol.for("@libp2p/pubsub");var $=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Lr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Q=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Dr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ie=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var fn=Symbol.for("@libp2p/peer-id");function Ra(e){return typeof e?.handleEvent=="function"}function Na(e){return(e!==!0&&e!==!1&&e?.once)??!1}var Ee=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){let i=Na(n);super.addEventListener(t,o=>{if(i){let c=this.#t.get(o.type);c!=null&&(c=c.filter(({callback:a})=>a!==r),this.#t.set(o.type,c))}Ra(r)?r.handleEvent(o):r(o)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:i})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let i=this.#t.get(t);i!=null&&(i=i.filter(({callback:s})=>s!==r),this.#t.set(t,i))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var li=Symbol.for("@libp2p/service-capabilities"),hi=Symbol.for("@libp2p/service-dependencies");var mn={};pt(mn,{base58btc:()=>Z,base58flickr:()=>Ha});var fl=new Uint8Array(0);function di(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Nt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function pi(e){return new TextEncoder().encode(e)}function mi(e){return new TextDecoder().decode(e)}function Pa(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<e.length;i++){var s=e.charAt(i),o=s.charCodeAt(0);if(r[o]!==255)throw new TypeError(s+" is ambiguous");r[o]=i}var c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var E=0,v=0,b=0,I=p.length;b!==I&&p[b]===0;)b++,E++;for(var x=(I-b)*f+1>>>0,B=new Uint8Array(x);b!==I;){for(var R=p[b],K=0,O=x-1;(R!==0||K<v)&&O!==-1;O--,K++)R+=256*B[O]>>>0,B[O]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");v=K,b++}for(var S=x-v;S!==x&&B[S]===0;)S++;for(var w=a.repeat(E);S<x;++S)w+=e.charAt(B[S]);return w}function h(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var E=0;if(p[E]!==" "){for(var v=0,b=0;p[E]===a;)v++,E++;for(var I=(p.length-E)*u+1>>>0,x=new Uint8Array(I);p[E];){var B=r[p.charCodeAt(E)];if(B===255)return;for(var R=0,K=I-1;(B!==0||R<b)&&K!==-1;K--,R++)B+=c*x[K]>>>0,x[K]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");b=R,E++}if(p[E]!==" "){for(var O=I-b;O!==I&&x[O]===0;)O++;for(var S=new Uint8Array(v+(I-O)),w=v;O!==I;)S[w++]=x[O++];return S}}}function d(p){var E=h(p);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:h,decode:d}}var Ua=Pa,Ka=Ua,yi=Ka;var ln=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},hn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,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 gi(this,t)}},dn=class{decoders;constructor(t){this.decoders=t}or(t){return gi(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function gi(e,t){return new dn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var pn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,i){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new ln(t,r,n),this.decoder=new hn(t,r,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Se({name:e,prefix:t,encode:r,decode:n}){return new pn(e,t,r,n)}function Zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:i}=yi(r,e);return Se({prefix:t,name:e,encode:n,decode:s=>Nt(i(s))})}function Oa(e,t,r,n){let i=e.length;for(;e[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),o=0,c=0,a=0;for(let u=0;u<i;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|f,o+=r,o>=8&&(o-=8,s[a++]=255&c>>o)}if(o>=r||(255&c<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ma(e,t,r){let n=t[t.length-1]==="=",i=(1<<r)-1,s="",o=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],o+=8;o>r;)o-=r,s+=t[i&c>>o];if(o!==0&&(s+=t[i&c<<r-o]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function qa(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function J({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let i=qa(n);return Se({prefix:t,name:e,encode(s){return Ma(s,n,r)},decode(s){return Oa(s,i,r,e)}})}var Z=Zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ha=Zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var bn={};pt(bn,{base32:()=>ve,base32hex:()=>za,base32hexpad:()=>Za,base32hexpadupper:()=>Ya,base32hexupper:()=>Ga,base32pad:()=>Fa,base32padupper:()=>$a,base32upper:()=>Va,base32z:()=>ja});var ve=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Va=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Fa=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),$a=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),za=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ga=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Za=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ya=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ja=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yn={};pt(yn,{base36:()=>He,base36upper:()=>Xa});var He=Zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Xa=Zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Wa=Ei,xi=128,Ja=127,Qa=~Ja,tc=Math.pow(2,31);function Ei(e,t,r){t=t||[],r=r||0;for(var n=r;e>=tc;)t[r++]=e&255|xi,e/=128;for(;e&Qa;)t[r++]=e&255|xi,e>>>=7;return t[r]=e|0,Ei.bytes=r-n+1,t}var ec=gn,rc=128,wi=127;function gn(e,n){var r=0,n=n||0,i=0,s=n,o,c=e.length;do{if(s>=c)throw gn.bytes=0,new RangeError("Could not decode varint");o=e[s++],r+=i<28?(o&wi)<<i:(o&wi)*Math.pow(2,i),i+=7}while(o>=rc);return gn.bytes=s-n,r}var nc=Math.pow(2,7),sc=Math.pow(2,14),ic=Math.pow(2,21),oc=Math.pow(2,28),ac=Math.pow(2,35),cc=Math.pow(2,42),uc=Math.pow(2,49),fc=Math.pow(2,56),lc=Math.pow(2,63),hc=function(e){return e<nc?1:e<sc?2:e<ic?3:e<oc?4:e<ac?5:e<cc?6:e<uc?7:e<fc?8:e<lc?9:10},dc={encode:Wa,decode:ec,encodingLength:hc},pc=dc,Ve=pc;function Fe(e,t=0){return[Ve.decode(e,t),Ve.decode.bytes]}function Ae(e,t,r=0){return Ve.encode(e,t,r),t}function Ie(e){return Ve.encodingLength(e)}function Tt(e,t){let r=t.byteLength,n=Ie(e),i=n+Ie(r),s=new Uint8Array(i+r);return Ae(e,s,0),Ae(r,s,n),s.set(t,i),new Be(e,r,t,s)}function Yt(e){let t=Nt(e),[r,n]=Fe(t),[i,s]=Fe(t.subarray(n)),o=t.subarray(n+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new Be(r,i,o,t)}function Si(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&di(e.bytes,r.bytes)}}var Be=class{code;size;digest;bytes;constructor(t,r,n,i){this.code=t,this.size=r,this.digest=n,this.bytes=i}};function vi(e,t){let{bytes:r,version:n}=e;return n===0?bc(r,xn(e),t??Z.encoder):yc(r,xn(e),t??ve.encoder)}var Ai=new WeakMap;function xn(e){let t=Ai.get(e);if(t==null){let r=new Map;return Ai.set(e,r),r}return t}var ct=class e{code;version;multihash;bytes;"/";constructor(t,r,n,i){this.code=r,this.version=t,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==$e)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==gc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Tt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Si(t.multihash,n.multihash)}toString(t){return vi(this,t)}toJSON(){return{"/":vi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:s,bytes:o}=r;return new e(n,i,s,o??Ii(n,i,s.bytes))}else if(r[xc]===!0){let{version:n,multihash:i,code:s}=r,o=Yt(i);return e.create(n,s,o)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==$e)throw new Error(`Version 0 CID must use dag-pb (code: ${$e}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let i=Ii(t,r,n.bytes);return new e(t,r,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,$e,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,i=Nt(t.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=i.subarray(r.multihashSize-r.digestSize),o=new Be(r.multihashCode,r.digestSize,s,i);return[r.version===0?e.createV0(o):e.createV1(r.codec,o),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,h]=Fe(t.subarray(r));return r+=h,l},i=n(),s=$e;if(i===18?(i=0,r=0):s=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let o=r,c=n(),a=n(),u=r+a,f=u-o;return{version:i,codec:s,multihashCode:c,digestSize:a,multihashSize:f,size:u}}static parse(t,r){let[n,i]=mc(t,r),s=e.decode(i);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return xn(s).set(n,t),s}};function mc(e,t){switch(e[0]){case"Q":{let r=t??Z;return[Z.prefix,r.decode(`${Z.prefix}${e}`)]}case Z.prefix:{let r=t??Z;return[Z.prefix,r.decode(e)]}case ve.prefix:{let r=t??ve;return[ve.prefix,r.decode(e)]}case He.prefix:{let r=t??He;return[He.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function bc(e,t,r){let{prefix:n}=r;if(n!==Z.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=t.get(n);if(i==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return i}function yc(e,t,r){let{prefix:n}=r,i=t.get(n);if(i==null){let s=r.encode(e);return t.set(n,s),s}else return i}var $e=112,gc=18;function Ii(e,t,r){let n=Ie(e),i=n+Ie(t),s=new Uint8Array(i+r.byteLength);return Ae(e,s,0),Ae(t,s,n),s.set(r,i),s}var xc=Symbol.for("@ipld/js-cid/CID");var wn={};pt(wn,{identity:()=>It});var Bi=0,wc="identity",Li=Nt;function Ec(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Tt(Bi,Li(e))}var It={code:Bi,name:wc,encode:Li,digest:Ec};function mt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Pt(e=0){return new Uint8Array(e)}function bt(e=0){return new Uint8Array(e)}function oe(e,t){t==null&&(t=e.reduce((i,s)=>i+s.length,0));let r=bt(t),n=0;for(let i of e)r.set(i,n),n+=i.length;return r}var _i=Symbol.for("@achingbrain/uint8arraylist");function Di(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let i=r+n.byteLength;if(t<i)return{buf:n,index:t-r};r=i}throw new RangeError("index is out of bounds")}function Tr(e){return!!e?.[_i]}var rt=class e{bufs;length;[_i]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Tr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Tr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Di(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Di(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Tr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:i}=this._subList(t,r);return oe(n,i)}subarray(t,r){let{bufs:n,length:i}=this._subList(t,r);return n.length===1?n[0]:oe(n,i)}sublist(t,r){let{bufs:n,length:i}=this._subList(t,r),s=new e;return s.length=i,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let s=0;s<this.bufs.length;s++){let o=this.bufs[s],c=i,a=c+o.byteLength;if(i=a,t>=a)continue;let u=t>=c&&t<a,f=r>c&&r<=a;if(u&&f){if(t===c&&r===a){n.push(o);break}let l=t-c;n.push(o.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(o);continue}n.push(o.subarray(t-c));continue}if(f){if(r===a){n.push(o);break}n.push(o.subarray(0,r-c));break}n.push(o)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Tr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let s=256,o=new Int32Array(s);for(let l=0;l<s;l++)o[l]=-1;for(let l=0;l<i;l++)o[n[l]]=l;let c=o,a=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=a;l+=f){f=0;for(let h=u;h>=0;h--){let d=this.get(l+h);if(n[h]!==d){f=Math.max(1,h-c[d]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let i=Pt(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,r,n),this.write(i,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let i=Pt(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,r,n),this.write(i,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let i=Pt(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,r,n),this.write(i,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let i=Pt(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,r,n),this.write(i,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let i=Pt(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,r,n),this.write(i,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let i=Pt(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,r,n),this.write(i,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let i=Pt(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,r,n),this.write(i,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let i=Pt(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,r,n),this.write(i,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!mt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((i,s)=>i+s.byteLength,0)),n.length=r,n}};var En={};pt(En,{base10:()=>Sc});var Sc=Zt({prefix:"9",name:"base10",alphabet:"0123456789"});var Sn={};pt(Sn,{base16:()=>vc,base16upper:()=>Ac});var vc=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ac=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var vn={};pt(vn,{base2:()=>Ic});var Ic=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var An={};pt(An,{base256emoji:()=>Tc});var Ti=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}"),Bc=Ti.reduce((e,t,r)=>(e[r]=t,e),[]),Lc=Ti.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Dc(e){return e.reduce((t,r)=>(t+=Bc[r],t),"")}function _c(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=Lc[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(i)}return new Uint8Array(t)}var Tc=Se({prefix:"\u{1F680}",name:"base256emoji",encode:Dc,decode:_c});var In={};pt(In,{base64:()=>kc,base64pad:()=>Cc,base64url:()=>Rc,base64urlpad:()=>Nc});var kc=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Cc=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Rc=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Nc=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Bn={};pt(Bn,{base8:()=>Pc});var Pc=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ln={};pt(Ln,{identity:()=>Uc});var Uc=Se({prefix:"\0",name:"identity",encode:e=>mi(e),decode:e=>pi(e)});var Zl=new TextEncoder,Yl=new TextDecoder;var Tn={};pt(Tn,{sha256:()=>ae,sha512:()=>qc});var Mc=20;function _n({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:i}){return new Dn(e,t,r,n,i)}var Dn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,i,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=i??Mc,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?ki(n,this.code,r?.truncate):n.then(i=>ki(i,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ki(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Tt(t,e)}function Ri(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ae=_n({name:"sha2-256",code:18,encode:Ri("SHA-256")}),qc=_n({name:"sha2-512",code:19,encode:Ri("SHA-512")});var kn={...Ln,...vn,...Bn,...En,...Sn,...bn,...yn,...mn,...In,...An},oh={...Tn,...wn};function Pi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ni=Pi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Cn=Pi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=bt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Hc={utf8:Ni,"utf-8":Ni,hex:kn.base16,latin1:Cn,ascii:Cn,binary:Cn,...kn},kr=Hc;function F(e,t="utf8"){let r=kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function V(e,t="utf8"){let r=kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Vc=parseInt("11111",2),Rn=parseInt("10000000",2),Fc=parseInt("01111111",2),Ui={0:ze,1:ze,2:$c,3:Zc,4:Yc,5:Gc,6:zc,16:ze,22:ze,48:ze};function Ut(e,t={offset:0}){let r=e[t.offset]&Vc;if(t.offset++,Ui[r]!=null)return Ui[r](e,t);throw new Error("No decoder for tag "+r)}function Ge(e,t){let r=0;if((e[t.offset]&Rn)===Rn){let n=e[t.offset]&Fc,i="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)i+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(i,16)}else r=e[t.offset],t.offset++;return r}function ze(e,t){Ge(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Ut(e,t);if(n===null)break;r.push(n)}return r}function $c(e,t){let r=Ge(e,t),n=t.offset,i=t.offset+r,s=[];for(let o=n;o<i;o++)o===n&&e[o]===0||s.push(e[o]);return t.offset+=r,Uint8Array.from(s)}function zc(e,t){let r=Ge(e,t),n=t.offset+r,i=e[t.offset];t.offset++;let s=0,o=0;i<40?(s=0,o=i):i<80?(s=1,o=i-40):(s=2,o=i-80);let c=`${s}.${o}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let f=0;for(let l=0;l<a.length;l++)f+=a[l]<<l*7;c+=`.${f}`,a=[]}}return c}function Gc(e,t){return t.offset++,null}function Zc(e,t){let r=Ge(e,t),n=e[t.offset];t.offset++;let i=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return i}function Yc(e,t){let r=Ge(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function jc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new rt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Nn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=jc(e.byteLength);return new rt(Uint8Array.from([t.byteLength|Rn]),t)}function yt(e){let t=new rt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new rt(Uint8Array.from([2]),Nn(t),t)}function Cr(e){let t=Uint8Array.from([0]),r=new rt(t,e);return new rt(Uint8Array.from([3]),Nn(r),r)}function Xt(e,t=48){let r=new rt;for(let n of e)r.append(n);return new rt(Uint8Array.from([t]),Nn(r),r)}async function Ki(e,t,r,n){let i=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,t,r.subarray());return n?.signal?.throwIfAborted(),s}var Xc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Wc=Uint8Array.from([6,5,43,129,4,0,34]),Jc=Uint8Array.from([6,5,43,129,4,0,35]),Qc={ext:!0,kty:"EC",crv:"P-256"},tu={ext:!0,kty:"EC",crv:"P-384"},eu={ext:!0,kty:"EC",crv:"P-521"},Pn=32,Un=48,Kn=66;function On(e){let t=Ut(e);return Oi(t)}function Oi(e){let t=e[1][1][0],r=1,n,i;if(t.byteLength===Pn*2+1)return n=V(t.subarray(r,r+Pn),"base64url"),i=V(t.subarray(r+Pn),"base64url"),new Le({...Qc,key_ops:["verify"],x:n,y:i});if(t.byteLength===Un*2+1)return n=V(t.subarray(r,r+Un),"base64url"),i=V(t.subarray(r+Un),"base64url"),new Le({...tu,key_ops:["verify"],x:n,y:i});if(t.byteLength===Kn*2+1)return n=V(t.subarray(r,r+Kn),"base64url"),i=V(t.subarray(r+Kn),"base64url"),new Le({...eu,key_ops:["verify"],x:n,y:i});throw new $(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Mi(e){return Xt([yt(Uint8Array.from([1])),Xt([ru(e.crv)],160),Xt([Cr(new rt(Uint8Array.from([4]),F(e.x??"","base64url"),F(e.y??"","base64url")))],161)]).subarray()}function ru(e){if(e==="P-256")return Xc;if(e==="P-384")return Wc;if(e==="P-521")return Jc;throw new $(`Invalid curve ${e}`)}var Le=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Mi(this.jwk)),this._raw}toMultihash(){return It.digest(Kt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}async verify(t,r,n){return Ki(this.jwk,r,t,n)}};function ce(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function kt(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function U(e,t,r=""){let n=ce(e),i=e?.length,s=t!==void 0;if(!n||s&&i!==t){let o=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${i}`:`type=${typeof e}`;throw new Error(o+"expected Uint8Array"+c+", got "+a)}return e}function Rr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");kt(e.outputLen),kt(e.blockLen)}function De(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Hi(e,t){U(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Mt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Nr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Bt(e,t){return e<<32-t|e>>>t}var Vi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",nu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function qt(e){if(U(e),Vi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=nu[e[r]];return t}var Ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function qi(e){if(e>=Ot._0&&e<=Ot._9)return e-Ot._0;if(e>=Ot.A&&e<=Ot.F)return e-(Ot.A-10);if(e>=Ot.a&&e<=Ot.f)return e-(Ot.a-10)}function Ht(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Vi)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let i=0,s=0;i<r;i++,s+=2){let o=qi(e.charCodeAt(s)),c=qi(e.charCodeAt(s+1));if(o===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[i]=o*16+c}return n}function gt(...e){let t=0;for(let n=0;n<e.length;n++){let i=e[n];U(i),t+=i.length}let r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){let s=e[n];r.set(s,i),i+=s.length}return r}function Mn(e,t={}){let r=(i,s)=>e(s).update(i).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=i=>e(i),Object.assign(r,t),Object.freeze(r)}function _e(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var qn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Fi(e,t,r){return e&t^~e&r}function $i(e,t,r){return e&t^e&r^t&r}var Ze=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,i){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(t),this.view=Nr(this.buffer)}update(t){De(this),U(t);let{view:r,buffer:n,blockLen:i}=this,s=t.length;for(let o=0;o<s;){let c=Math.min(i-this.pos,s-o);if(c===i){let a=Nr(t);for(;i<=s-o;o+=i)this.process(a,o);continue}n.set(t.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){De(this),Hi(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:s}=this,{pos:o}=this;r[o++]=128,Mt(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(n,0),o=0);for(let l=o;l<i;l++)r[l]=0;n.setBigUint64(i-8,BigInt(this.length*8),s),this.process(n,0);let c=Nr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:c}=this;return t.destroyed=o,t.finished=s,t.length=i,t.pos=c,i%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Vt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Pr=BigInt(4294967295),zi=BigInt(32);function su(e,t=!1){return t?{h:Number(e&Pr),l:Number(e>>zi&Pr)}:{h:Number(e>>zi&Pr)|0,l:Number(e&Pr)|0}}function Gi(e,t=!1){let r=e.length,n=new Uint32Array(r),i=new Uint32Array(r);for(let s=0;s<r;s++){let{h:o,l:c}=su(e[s],t);[n[s],i[s]]=[o,c]}return[n,i]}var Hn=(e,t,r)=>e>>>r,Vn=(e,t,r)=>e<<32-r|t>>>r,ue=(e,t,r)=>e>>>r|t<<32-r,fe=(e,t,r)=>e<<32-r|t>>>r,Ye=(e,t,r)=>e<<64-r|t>>>r-32,je=(e,t,r)=>e>>>r-32|t<<64-r;function Ct(e,t,r,n){let i=(t>>>0)+(n>>>0);return{h:e+r+(i/2**32|0)|0,l:i|0}}var Zi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Yi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ji=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Xi=(e,t,r,n,i)=>t+r+n+i+(e/2**32|0)|0,Wi=(e,t,r,n,i)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(i>>>0),Ji=(e,t,r,n,i,s)=>t+r+n+i+s+(e/2**32|0)|0;var ou=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]),Wt=new Uint32Array(64),Fn=class extends Ze{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:i,E:s,F:o,G:c,H:a}=this;return[t,r,n,i,s,o,c,a]}set(t,r,n,i,s,o,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)Wt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let h=Wt[l-15],d=Wt[l-2],p=Bt(h,7)^Bt(h,18)^h>>>3,E=Bt(d,17)^Bt(d,19)^d>>>10;Wt[l]=E+Wt[l-7]+p+Wt[l-16]|0}let{A:n,B:i,C:s,D:o,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let h=Bt(c,6)^Bt(c,11)^Bt(c,25),d=f+h+Fi(c,a,u)+ou[l]+Wt[l]|0,E=(Bt(n,2)^Bt(n,13)^Bt(n,22))+$i(n,i,s)|0;f=u,u=a,a=c,c=o+d|0,o=s,s=i,i=n,n=d+E|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,s,o,c,a,u,f)}roundClean(){Mt(Wt)}destroy(){this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}},$n=class extends Fn{A=Vt[0]|0;B=Vt[1]|0;C=Vt[2]|0;D=Vt[3]|0;E=Vt[4]|0;F=Vt[5]|0;G=Vt[6]|0;H=Vt[7]|0;constructor(){super(32)}};var Qi=Gi(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),au=Qi[0],cu=Qi[1],Jt=new Uint32Array(80),Qt=new Uint32Array(80),zn=class extends Ze{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:i,Ch:s,Cl:o,Dh:c,Dl:a,Eh:u,El:f,Fh:l,Fl:h,Gh:d,Gl:p,Hh:E,Hl:v}=this;return[t,r,n,i,s,o,c,a,u,f,l,h,d,p,E,v]}set(t,r,n,i,s,o,c,a,u,f,l,h,d,p,E,v){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=p|0,this.Hh=E|0,this.Hl=v|0}process(t,r){for(let x=0;x<16;x++,r+=4)Jt[x]=t.getUint32(r),Qt[x]=t.getUint32(r+=4);for(let x=16;x<80;x++){let B=Jt[x-15]|0,R=Qt[x-15]|0,K=ue(B,R,1)^ue(B,R,8)^Hn(B,R,7),O=fe(B,R,1)^fe(B,R,8)^Vn(B,R,7),S=Jt[x-2]|0,w=Qt[x-2]|0,N=ue(S,w,19)^Ye(S,w,61)^Hn(S,w,6),M=fe(S,w,19)^je(S,w,61)^Vn(S,w,6),T=ji(O,M,Qt[x-7],Qt[x-16]),y=Xi(T,K,N,Jt[x-7],Jt[x-16]);Jt[x]=y|0,Qt[x]=T|0}let{Ah:n,Al:i,Bh:s,Bl:o,Ch:c,Cl:a,Dh:u,Dl:f,Eh:l,El:h,Fh:d,Fl:p,Gh:E,Gl:v,Hh:b,Hl:I}=this;for(let x=0;x<80;x++){let B=ue(l,h,14)^ue(l,h,18)^Ye(l,h,41),R=fe(l,h,14)^fe(l,h,18)^je(l,h,41),K=l&d^~l&E,O=h&p^~h&v,S=Wi(I,R,O,cu[x],Qt[x]),w=Ji(S,b,B,K,au[x],Jt[x]),N=S|0,M=ue(n,i,28)^Ye(n,i,34)^Ye(n,i,39),T=fe(n,i,28)^je(n,i,34)^je(n,i,39),y=n&s^n&c^s&c,g=i&o^i&a^o&a;b=E|0,I=v|0,E=d|0,v=p|0,d=l|0,p=h|0,{h:l,l:h}=Ct(u|0,f|0,w|0,N|0),u=c|0,f=a|0,c=s|0,a=o|0,s=n|0,o=i|0;let m=Zi(N,T,g);n=Yi(m,w,M,y),i=m|0}({h:n,l:i}=Ct(this.Ah|0,this.Al|0,n|0,i|0)),{h:s,l:o}=Ct(this.Bh|0,this.Bl|0,s|0,o|0),{h:c,l:a}=Ct(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=Ct(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=Ct(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:p}=Ct(this.Fh|0,this.Fl|0,d|0,p|0),{h:E,l:v}=Ct(this.Gh|0,this.Gl|0,E|0,v|0),{h:b,l:I}=Ct(this.Hh|0,this.Hl|0,b|0,I|0),this.set(n,i,s,o,c,a,u,f,l,h,d,p,E,v,b,I)}roundClean(){Mt(Jt,Qt)}destroy(){Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Gn=class extends zn{Ah=ot[0]|0;Al=ot[1]|0;Bh=ot[2]|0;Bl=ot[3]|0;Ch=ot[4]|0;Cl=ot[5]|0;Dh=ot[6]|0;Dl=ot[7]|0;Eh=ot[8]|0;El=ot[9]|0;Fh=ot[10]|0;Fl=ot[11]|0;Gh=ot[12]|0;Gl=ot[13]|0;Hh=ot[14]|0;Hl=ot[15]|0;constructor(){super(64)}};var to=Mn(()=>new $n,qn(1));var eo=Mn(()=>new Gn,qn(3));var Yn=BigInt(0),Zn=BigInt(1);function Ft(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function ro(e){if(typeof e=="bigint"){if(!Ur(e))throw new Error("positive bigint expected, got "+e)}else kt(e);return e}function Xe(e){let t=ro(e).toString(16);return t.length&1?"0"+t:t}function no(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Yn:BigInt("0x"+e)}function Te(e){return no(qt(e))}function le(e){return no(qt(Or(U(e)).reverse()))}function Kr(e,t){kt(t),e=ro(e);let r=Ht(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function jn(e,t){return Kr(e,t).reverse()}function Or(e){return Uint8Array.from(e)}var Ur=e=>typeof e=="bigint"&&Yn<=e;function uu(e,t,r){return Ur(e)&&Ur(t)&&Ur(r)&&t<=e&&e<r}function We(e,t,r,n){if(!uu(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Xn(e){let t;for(t=0;e>Yn;e>>=Zn,t+=1);return t}var Je=e=>(Zn<<BigInt(e))-Zn;function so(e,t,r){if(kt(e,"hashLen"),kt(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=v=>new Uint8Array(v),i=Uint8Array.of(),s=Uint8Array.of(0),o=Uint8Array.of(1),c=1e3,a=n(e),u=n(e),f=0,l=()=>{a.fill(1),u.fill(0),f=0},h=(...v)=>r(u,gt(a,...v)),d=(v=i)=>{u=h(s,v),a=h(),v.length!==0&&(u=h(o,v),a=h())},p=()=>{if(f++>=c)throw new Error("drbg: tried max amount of iterations");let v=0,b=[];for(;v<t;){a=h();let I=a.slice();b.push(I),v+=a.length}return gt(...b)};return(v,b)=>{l(),d(v);let I;for(;!(I=b(p()));)d();return l(),I}}function te(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,o,c){let a=e[s];if(c&&a===void 0)return;let u=typeof a;if(u!==o||a===null)throw new Error(`param "${s}" is invalid: expected ${o}, got ${u}`)}let i=(s,o)=>Object.entries(s).forEach(([c,a])=>n(c,a,o));i(t,!1),i(r,!0)}function ke(e){let t=new WeakMap;return(r,...n)=>{let i=t.get(r);if(i!==void 0)return i;let s=e(r,...n);return t.set(r,s),s}}var ht=BigInt(0),nt=BigInt(1),he=BigInt(2),ao=BigInt(3),co=BigInt(4),uo=BigInt(5),fu=BigInt(7),fo=BigInt(8),lu=BigInt(9),lo=BigInt(16);function tt(e,t){let r=e%t;return r>=ht?r:t+r}function G(e,t,r){let n=e;for(;t-- >ht;)n*=n,n%=r;return n}function io(e,t){if(e===ht)throw new Error("invert: expected non-zero number");if(t<=ht)throw new Error("invert: expected positive modulus, got "+t);let r=tt(e,t),n=t,i=ht,s=nt,o=nt,c=ht;for(;r!==ht;){let u=n/r,f=n%r,l=i-o*u,h=s-c*u;n=r,r=f,i=o,s=c,o=l,c=h}if(n!==nt)throw new Error("invert: does not exist");return tt(i,t)}function Jn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function ho(e,t){let r=(e.ORDER+nt)/co,n=e.pow(t,r);return Jn(e,n,t),n}function hu(e,t){let r=(e.ORDER-uo)/fo,n=e.mul(t,he),i=e.pow(n,r),s=e.mul(t,i),o=e.mul(e.mul(s,he),i),c=e.mul(s,e.sub(o,e.ONE));return Jn(e,c,t),c}function du(e){let t=Ce(e),r=po(e),n=r(t,t.neg(t.ONE)),i=r(t,n),s=r(t,t.neg(n)),o=(e+fu)/lo;return(c,a)=>{let u=c.pow(a,o),f=c.mul(u,n),l=c.mul(u,i),h=c.mul(u,s),d=c.eql(c.sqr(f),a),p=c.eql(c.sqr(l),a);u=c.cmov(u,f,d),f=c.cmov(h,l,p);let E=c.eql(c.sqr(f),a),v=c.cmov(u,f,E);return Jn(c,v,a),v}}function po(e){if(e<ao)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%he===ht;)t/=he,r++;let n=he,i=Ce(e);for(;oo(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ho;let s=i.pow(n,t),o=(t+nt)/he;return function(a,u){if(a.is0(u))return u;if(oo(a,u)!==1)throw new Error("Cannot find square root");let f=r,l=a.mul(a.ONE,s),h=a.pow(u,t),d=a.pow(u,o);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let p=1,E=a.sqr(h);for(;!a.eql(E,a.ONE);)if(p++,E=a.sqr(E),p===f)throw new Error("Cannot find square root");let v=nt<<BigInt(f-p-1),b=a.pow(l,v);f=p,l=a.sqr(b),h=a.mul(h,l),d=a.mul(d,b)}return d}}function pu(e){return e%co===ao?ho:e%fo===uo?hu:e%lo===lu?du(e):po(e)}var mo=(e,t)=>(tt(e,t)&nt)===nt,mu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Qn(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=mu.reduce((n,i)=>(n[i]="function",n),t);return te(e,r),e}function bu(e,t,r){if(r<ht)throw new Error("invalid exponent, negatives unsupported");if(r===ht)return e.ONE;if(r===nt)return t;let n=e.ONE,i=t;for(;r>ht;)r&nt&&(n=e.mul(n,i)),i=e.sqr(i),r>>=nt;return n}function Qe(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),i=t.reduce((o,c,a)=>e.is0(c)?o:(n[a]=o,e.mul(o,c)),e.ONE),s=e.inv(i);return t.reduceRight((o,c,a)=>e.is0(c)?o:(n[a]=e.mul(o,n[a]),e.mul(o,c)),s),n}function oo(e,t){let r=(e.ORDER-nt)/he,n=e.pow(t,r),i=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),o=e.eql(n,e.neg(e.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function yu(e,t){t!==void 0&&kt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Wn=class{ORDER;BITS;BYTES;isLE;ZERO=ht;ONE=nt;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=ht)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:i,nByteLength:s}=yu(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=i,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return tt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return ht<=t&&t<this.ORDER}is0(t){return t===ht}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&nt)===nt}neg(t){return tt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return tt(t*t,this.ORDER)}add(t,r){return tt(t+r,this.ORDER)}sub(t,r){return tt(t-r,this.ORDER)}mul(t,r){return tt(t*r,this.ORDER)}pow(t,r){return bu(this,t,r)}div(t,r){return tt(t*io(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return io(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=pu(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?jn(t,this.BYTES):Kr(t,this.BYTES)}fromBytes(t,r=!1){U(t);let{_lengths:n,BYTES:i,isLE:s,ORDER:o,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>i)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(i);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+t.length);let a=s?le(t):Te(t);if(c&&(a=tt(a,o)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(t){return Qe(this,t)}cmov(t,r,n){return n?r:t}};function Ce(e,t={}){return new Wn(e,t)}function bo(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function ts(e){let t=bo(e);return t+Math.ceil(t/2)}function es(e,t,r=!1){U(e);let n=e.length,i=bo(t),s=ts(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let o=r?le(e):Te(e),c=tt(o,t-nt)+nt;return r?jn(c,i):Kr(c,i)}var Re=BigInt(0),de=BigInt(1);function tr(e,t){let r=t.negate();return e?r:t}function pe(e,t){let r=Qe(e.Fp,t.map(n=>n.Z));return t.map((n,i)=>e.fromAffine(n.toAffine(r[i])))}function wo(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function rs(e,t){wo(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),i=2**e,s=Je(e),o=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:i,shiftBy:o}}function yo(e,t,r){let{windowSize:n,mask:i,maxNumber:s,shiftBy:o}=r,c=Number(e&i),a=e>>o;c>n&&(c-=s,a+=de);let u=t*n,f=u+Math.abs(c)-1,l=c===0,h=c<0,d=t%2!==0;return{nextN:a,offset:f,isZero:l,isNeg:h,isNegF:d,offsetF:u}}var ns=new WeakMap,Eo=new WeakMap;function ss(e){return Eo.get(e)||1}function go(e){if(e!==Re)throw new Error("invalid wNAF")}var Ne=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let i=t;for(;r>Re;)r&de&&(n=n.add(i)),i=i.double(),r>>=de;return n}precomputeWindow(t,r){let{windows:n,windowSize:i}=rs(r,this.bits),s=[],o=t,c=o;for(let a=0;a<n;a++){c=o,s.push(c);for(let u=1;u<i;u++)c=c.add(o),s.push(c);o=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE,o=rs(t,this.bits);for(let c=0;c<o.windows;c++){let{nextN:a,offset:u,isZero:f,isNeg:l,isNegF:h,offsetF:d}=yo(n,c,o);n=a,f?s=s.add(tr(h,r[d])):i=i.add(tr(l,r[u]))}return go(n),{p:i,f:s}}wNAFUnsafe(t,r,n,i=this.ZERO){let s=rs(t,this.bits);for(let o=0;o<s.windows&&n!==Re;o++){let{nextN:c,offset:a,isZero:u,isNeg:f}=yo(n,o,s);if(n=c,!u){let l=r[a];i=i.add(f?l.negate():l)}}return go(n),i}getPrecomputes(t,r,n){let i=ns.get(r);return i||(i=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(i=n(i)),ns.set(r,i))),i}cached(t,r,n){let i=ss(t);return this.wNAF(i,this.getPrecomputes(i,t,n),r)}unsafe(t,r,n,i){let s=ss(t);return s===1?this._unsafeLadder(t,r,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,i)}createCache(t,r){wo(r,this.bits),Eo.set(t,r),ns.delete(t)}hasCache(t){return ss(t)!==1}};function So(e,t,r,n){let i=t,s=e.ZERO,o=e.ZERO;for(;r>Re||n>Re;)r&de&&(s=s.add(i)),n&de&&(o=o.add(i)),i=i.double(),r>>=de,n>>=de;return{p1:s,p2:o}}function xo(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Qn(t),t}else return Ce(e,{isLE:r})}function Mr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>Re))throw new Error(`CURVE.${a} must be positive bigint`)}let i=xo(t.p,r.Fp,n),s=xo(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!i.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:s}}function qr(e,t){return function(n){let i=e(n);return{secretKey:i,publicKey:t(i)}}}var ee=BigInt(0),st=BigInt(1),is=BigInt(2),gu=BigInt(8);function xu(e,t,r,n){let i=e.sqr(r),s=e.sqr(n),o=e.add(e.mul(t.a,i),s),c=e.add(e.ONE,e.mul(t.d,e.mul(i,s)));return e.eql(o,c)}function vo(e,t={}){let r=Mr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:i}=r,s=r.CURVE,{h:o}=s;te(t,{},{uvRatio:"function"});let c=is<<BigInt(i.BYTES*8)-st,a=v=>n.create(v),u=t.uvRatio||((v,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(v,b))}}catch{return{isValid:!1,value:ee}}});if(!xu(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function f(v,b,I=!1){let x=I?st:ee;return We("coordinate "+v,b,x,c),b}function l(v){if(!(v instanceof p))throw new Error("EdwardsPoint expected")}let h=ke((v,b)=>{let{X:I,Y:x,Z:B}=v,R=v.is0();b==null&&(b=R?gu:n.inv(B));let K=a(I*b),O=a(x*b),S=n.mul(B,b);if(R)return{x:ee,y:st};if(S!==st)throw new Error("invZ was invalid");return{x:K,y:O}}),d=ke(v=>{let{a:b,d:I}=s;if(v.is0())throw new Error("bad point: ZERO");let{X:x,Y:B,Z:R,T:K}=v,O=a(x*x),S=a(B*B),w=a(R*R),N=a(w*w),M=a(O*b),T=a(w*a(M+S)),y=a(N+a(I*a(O*S)));if(T!==y)throw new Error("bad point: equation left != right (1)");let g=a(x*B),m=a(R*K);if(g!==m)throw new Error("bad point: equation left != right (2)");return!0});class p{static BASE=new p(s.Gx,s.Gy,st,a(s.Gx*s.Gy));static ZERO=new p(ee,st,st,ee);static Fp=n;static Fn=i;X;Y;Z;T;constructor(b,I,x,B){this.X=f("x",b),this.Y=f("y",I),this.Z=f("z",x,!0),this.T=f("t",B),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof p)throw new Error("extended point not allowed");let{x:I,y:x}=b||{};return f("x",I),f("y",x),new p(I,x,st,a(I*x))}static fromBytes(b,I=!1){let x=n.BYTES,{a:B,d:R}=s;b=Or(U(b,x,"point")),Ft(I,"zip215");let K=Or(b),O=b[x-1];K[x-1]=O&-129;let S=le(K),w=I?c:n.ORDER;We("point.y",S,ee,w);let N=a(S*S),M=a(N-st),T=a(R*N-B),{isValid:y,value:g}=u(M,T);if(!y)throw new Error("bad point: invalid y coordinate");let m=(g&st)===st,A=(O&128)!==0;if(!I&&g===ee&&A)throw new Error("bad point: x=0 and x_0=1");return A!==m&&(g=a(-g)),p.fromAffine({x:g,y:S})}static fromHex(b,I=!1){return p.fromBytes(Ht(b),I)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,I=!0){return E.createCache(this,b),I||this.multiply(is),this}assertValidity(){d(this)}equals(b){l(b);let{X:I,Y:x,Z:B}=this,{X:R,Y:K,Z:O}=b,S=a(I*O),w=a(R*B),N=a(x*O),M=a(K*B);return S===w&&N===M}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:b}=s,{X:I,Y:x,Z:B}=this,R=a(I*I),K=a(x*x),O=a(is*a(B*B)),S=a(b*R),w=I+x,N=a(a(w*w)-R-K),M=S+K,T=M-O,y=S-K,g=a(N*T),m=a(M*y),A=a(N*y),L=a(T*M);return new p(g,m,L,A)}add(b){l(b);let{a:I,d:x}=s,{X:B,Y:R,Z:K,T:O}=this,{X:S,Y:w,Z:N,T:M}=b,T=a(B*S),y=a(R*w),g=a(O*x*M),m=a(K*N),A=a((B+R)*(S+w)-T-y),L=m-g,_=m+g,k=a(y-I*T),D=a(A*L),C=a(_*k),P=a(A*k),j=a(L*_);return new p(D,C,j,P)}subtract(b){return this.add(b.negate())}multiply(b){if(!i.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:I,f:x}=E.cached(this,b,B=>pe(p,B));return pe(p,[I,x])[0]}multiplyUnsafe(b,I=p.ZERO){if(!i.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===ee?p.ZERO:this.is0()||b===st?this:E.unsafe(this,b,x=>pe(p,x),I)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(b){return h(this,b)}clearCofactor(){return o===st?this:this.multiplyUnsafe(o)}toBytes(){let{x:b,y:I}=this.toAffine(),x=n.toBytes(I);return x[x.length-1]|=b&st?128:0,x}toHex(){return qt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let E=new Ne(p,i.BITS);return p.BASE.precompute(8),p}function Ao(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');te(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:i,Fp:s,Fn:o}=e,c=r.randomBytes||_e,a=r.adjustScalarBytes||(S=>S),u=r.domain||((S,w,N)=>{if(Ft(N,"phflag"),w.length||N)throw new Error("Contexts/pre-hash are not supported");return S});function f(S){return o.create(le(S))}function l(S){let w=x.secretKey;U(S,x.secretKey,"secretKey");let N=U(t(S),2*w,"hashedSecretKey"),M=a(N.slice(0,w)),T=N.slice(w,2*w),y=f(M);return{head:M,prefix:T,scalar:y}}function h(S){let{head:w,prefix:N,scalar:M}=l(S),T=i.multiply(M),y=T.toBytes();return{head:w,prefix:N,scalar:M,point:T,pointBytes:y}}function d(S){return h(S).pointBytes}function p(S=Uint8Array.of(),...w){let N=gt(...w);return f(t(u(N,U(S,void 0,"context"),!!n)))}function E(S,w,N={}){S=U(S,void 0,"message"),n&&(S=n(S));let{prefix:M,scalar:T,pointBytes:y}=h(w),g=p(N.context,M,S),m=i.multiply(g).toBytes(),A=p(N.context,m,y,S),L=o.create(g+A*T);if(!o.isValid(L))throw new Error("sign failed: invalid s");let _=gt(m,o.toBytes(L));return U(_,x.signature,"result")}let v={zip215:!0};function b(S,w,N,M=v){let{context:T,zip215:y}=M,g=x.signature;S=U(S,g,"signature"),w=U(w,void 0,"message"),N=U(N,x.publicKey,"publicKey"),y!==void 0&&Ft(y,"zip215"),n&&(w=n(w));let m=g/2,A=S.subarray(0,m),L=le(S.subarray(m,g)),_,k,D;try{_=e.fromBytes(N,y),k=e.fromBytes(A,y),D=i.multiplyUnsafe(L)}catch{return!1}if(!y&&_.isSmallOrder())return!1;let C=p(T,k.toBytes(),_.toBytes(),w);return k.add(_.multiplyUnsafe(C)).subtract(D).clearCofactor().is0()}let I=s.BYTES,x={secretKey:I,publicKey:I,signature:2*I,seed:I};function B(S=c(x.seed)){return U(S,x.seed,"seed")}function R(S){return ce(S)&&S.length===o.BYTES}function K(S,w){try{return!!e.fromBytes(S,w)}catch{return!1}}let O={getExtendedPublicKey:h,randomSecretKey:B,isValidSecretKey:R,isValidPublicKey:K,toMontgomery(S){let{y:w}=e.fromBytes(S),N=x.publicKey,M=N===32;if(!M&&N!==57)throw new Error("only defined for 25519 and 448");let T=M?s.div(st+w,st-w):s.div(w-st,w+st);return s.toBytes(T)},toMontgomerySecret(S){let w=x.secretKey;U(S,w);let N=t(S.subarray(0,w));return a(N).subarray(0,w)}};return Object.freeze({keygen:qr(B,d),getPublicKey:d,sign:E,verify:b,utils:O,Point:e,lengths:x})}var wu=BigInt(1),Io=BigInt(2);var Eu=BigInt(5),Su=BigInt(8),os=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),vu={p:os,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Su,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Au(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),i=BigInt(80),s=os,c=e*e%s*e%s,a=G(c,Io,s)*c%s,u=G(a,wu,s)*e%s,f=G(u,Eu,s)*u%s,l=G(f,t,s)*f%s,h=G(l,r,s)*l%s,d=G(h,n,s)*h%s,p=G(d,i,s)*d%s,E=G(p,i,s)*d%s,v=G(E,t,s)*f%s;return{pow_p_5_8:G(v,Io,s)*e%s,b2:c}}function Iu(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Bo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Bu(e,t){let r=os,n=tt(t*t*t,r),i=tt(n*n*t,r),s=Au(e*i).pow_p_5_8,o=tt(e*n*s,r),c=tt(t*o*o,r),a=o,u=tt(o*Bo,r),f=c===e,l=c===tt(-e,r),h=c===tt(-e*Bo,r);return f&&(o=a),(l||h)&&(o=u),mo(o,r)&&(o=tt(-o,r)),{isValid:f||l,value:o}}var Lu=vo(vu,{uvRatio:Bu});function Du(e){return Ao(Lu,eo,Object.assign({adjustScalarBytes:Iu},e))}var Lo=Du({});var er=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Hr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Do={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Hr("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 At=Do;var Vr=32;var as,_u=(async()=>{try{return await At.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Tu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await At.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await At.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ku(e,t,r){return Lo.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function _o(e,t,r){return as==null&&(as=await _u),as?Tu(e,t,r):ku(e,t,r)}function Fr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var $r=class{type="Ed25519";raw;constructor(t){this.raw=cs(t,Vr)}toMultihash(){return It.digest(Kt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let i=_o(this.raw,r,t);return Fr(i)?i.then(s=>(n?.signal?.throwIfAborted(),s)):i}};function us(e){return e=cs(e,Vr),new $r(e)}function cs(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new $(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Ru=Math.pow(2,7),Nu=Math.pow(2,14),Pu=Math.pow(2,21),fs=Math.pow(2,28),ls=Math.pow(2,35),hs=Math.pow(2,42),ds=Math.pow(2,49),H=128,ut=127;function $t(e){if(e<Ru)return 1;if(e<Nu)return 2;if(e<Pu)return 3;if(e<fs)return 4;if(e<ls)return 5;if(e<hs)return 6;if(e<ds)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ps(e,t,r=0){switch($t(e)){case 8:t[r++]=e&255|H,e/=128;case 7:t[r++]=e&255|H,e/=128;case 6:t[r++]=e&255|H,e/=128;case 5:t[r++]=e&255|H,e/=128;case 4:t[r++]=e&255|H,e>>>=7;case 3:t[r++]=e&255|H,e>>>=7;case 2:t[r++]=e&255|H,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Uu(e,t,r=0){switch($t(e)){case 8:t.set(r++,e&255|H),e/=128;case 7:t.set(r++,e&255|H),e/=128;case 6:t.set(r++,e&255|H),e/=128;case 5:t.set(r++,e&255|H),e/=128;case 4:t.set(r++,e&255|H),e>>>=7;case 3:t.set(r++,e&255|H),e>>>=7;case 2:t.set(r++,e&255|H),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function ms(e,t){let r=e[t],n=0;if(n+=r&ut,r<H||(r=e[t+1],n+=(r&ut)<<7,r<H)||(r=e[t+2],n+=(r&ut)<<14,r<H)||(r=e[t+3],n+=(r&ut)<<21,r<H)||(r=e[t+4],n+=(r&ut)*fs,r<H)||(r=e[t+5],n+=(r&ut)*ls,r<H)||(r=e[t+6],n+=(r&ut)*hs,r<H)||(r=e[t+7],n+=(r&ut)*ds,r<H))return n;throw new RangeError("Could not decode varint")}function Ku(e,t){let r=e.get(t),n=0;if(n+=r&ut,r<H||(r=e.get(t+1),n+=(r&ut)<<7,r<H)||(r=e.get(t+2),n+=(r&ut)<<14,r<H)||(r=e.get(t+3),n+=(r&ut)<<21,r<H)||(r=e.get(t+4),n+=(r&ut)*fs,r<H)||(r=e.get(t+5),n+=(r&ut)*ls,r<H)||(r=e.get(t+6),n+=(r&ut)*hs,r<H)||(r=e.get(t+7),n+=(r&ut)*ds,r<H))return n;throw new RangeError("Could not decode varint")}function ko(e,t,r=0){return t==null&&(t=bt($t(e))),t instanceof Uint8Array?ps(e,t,r):Uu(e,t,r)}function Co(e,t=0){return e instanceof Uint8Array?ms(e,t):Ku(e,t)}var bs=new Float32Array([-0]),re=new Uint8Array(bs.buffer);function Ro(e,t,r){bs[0]=e,t[r]=re[0],t[r+1]=re[1],t[r+2]=re[2],t[r+3]=re[3]}function No(e,t){return re[0]=e[t],re[1]=e[t+1],re[2]=e[t+2],re[3]=e[t+3],bs[0]}var ys=new Float64Array([-0]),ft=new Uint8Array(ys.buffer);function Po(e,t,r){ys[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function Uo(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],ys[0]}var Mu=BigInt(Number.MAX_SAFE_INTEGER),qu=BigInt(Number.MIN_SAFE_INTEGER),vt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return me;if(t<Mu&&t>qu)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,i=t-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>Ko&&(i=0n,++n>Ko&&(n=0n))),new e(Number(i),Number(n))}static fromNumber(t){if(t===0)return me;let r=t<0;r&&(t=-t);let n=t>>>0,i=(t-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new e(n,i)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):me}},me=new vt(0,0);me.toBigInt=function(){return 0n};me.zzEncode=me.zzDecode=function(){return this};me.length=function(){return 1};var Ko=4294967296n;function Oo(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Mo(e,t,r){if(r-t<1)return"";let i,s=[],o=0,c;for(;t<r;)c=e[t++],c<128?s[o++]=c:c>191&&c<224?s[o++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[o++]=55296+(c>>10),s[o++]=56320+(c&1023)):s[o++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,o>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,s)),o=0);return i!=null?(o>0&&i.push(String.fromCharCode.apply(String,s.slice(0,o))),i.join("")):String.fromCharCode.apply(String,s.slice(0,o))}function gs(e,t,r){let n=r,i,s;for(let o=0;o<e.length;++o)i=e.charCodeAt(o),i<128?t[r++]=i:i<2048?(t[r++]=i>>6|192,t[r++]=i&63|128):(i&64512)===55296&&((s=e.charCodeAt(o+1))&64512)===56320?(i=65536+((i&1023)<<10)+(s&1023),++o,t[r++]=i>>18|240,t[r++]=i>>12&63|128,t[r++]=i>>6&63|128,t[r++]=i&63|128):(t[r++]=i>>12|224,t[r++]=i>>6&63|128,t[r++]=i&63|128);return r-n}function Lt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function zr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var xs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Lt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Lt(this,4);return zr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return zr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=No(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=Uo(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Lt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Mo(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new vt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Lt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Lt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Lt(this,8);let t=zr(this.buf,this.pos+=4),r=zr(this.buf,this.pos+=4);return new vt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ms(this.buf,this.pos);return this.pos+=$t(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 rr(e){return new xs(e instanceof Uint8Array?e:e.subarray())}function xt(e,t,r){let n=rr(e);return t.decode(n,void 0,r)}function ws(e){let t=e??8192,r=t>>>1,n,i=t;return function(o){if(o<1||o>r)return bt(o);i+o>t&&(n=bt(t),i=0);let c=n.subarray(i,i+=o);return(i&7)!==0&&(i=(i|7)+1),c}}var be=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Es(){}var vs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Hu=ws();function Vu(e){return globalThis.Buffer!=null?bt(e):Hu(e)}var sr=class{len;head;tail;states;constructor(){this.len=0,this.head=new be(Es,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new be(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new As((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(Gr,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=vt.fromBigInt(t);return this._push(Gr,r.length(),r)}uint64Number(t){return this._push(ps,$t(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=vt.fromBigInt(t).zzEncode();return this._push(Gr,r.length(),r)}sint64Number(t){let r=vt.fromNumber(t).zzEncode();return this._push(Gr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ss,1,t?1:0)}fixed32(t){return this._push(nr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=vt.fromBigInt(t);return this._push(nr,4,r.lo)._push(nr,4,r.hi)}fixed64Number(t){let r=vt.fromNumber(t);return this._push(nr,4,r.lo)._push(nr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ro,4,t)}double(t){return this._push(Po,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ss,1,0):this.uint32(r)._push($u,r,t)}string(t){let r=Oo(t);return r!==0?this.uint32(r)._push(gs,r,t):this._push(Ss,1,0)}fork(){return this.states=new vs(this),this.head=this.tail=new be(Es,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 be(Es,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Vu(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ss(e,t,r){t[r]=e&255}function Fu(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var As=class extends be{next;constructor(t,r){super(Fu,t,r),this.next=void 0}};function Gr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function nr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function $u(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(sr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(zu,t,e),this},sr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Gu,t,e),this});function zu(e,t,r){t.set(e,r)}function Gu(e,t,r){e.length<40?gs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(F(e),r)}function Is(){return new sr}function wt(e,t){let r=Is();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Et(e,t,r){let n=rr(e);yield*t.stream(n,void 0,"$",r)}var Zr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Yr(e,t,r,n,i){return{name:e,type:t,encode:r,decode:n,stream:i}}function Bs(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(o,c){let a=t(o);c.int32(a)},n=function(o){let c=o.int32();return t(c)},i=function*(o){let c=o.int32();yield t(c)};return Yr("enum",Zr.VARINT,r,n,i)}function St(e,t,r){return Yr("message",Zr.LENGTH_DELIMITED,e,t,r)}var et=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Y;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Y||(Y={}));var Ls;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ls||(Ls={}));(function(e){e.codec=()=>Bs(Ls)})(Y||(Y={}));var Rt;(function(e){let t;e.codec=()=>(t==null&&(t=St((s,o,c={})=>{c.lengthDelimited!==!1&&o.fork(),s.Type!=null&&(o.uint32(8),Y.codec().encode(s.Type,o)),s.Data!=null&&(o.uint32(18),o.bytes(s.Data)),c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.Type=Y.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.Type`,value:Y.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return wt(s,e.codec())}e.encode=r;function n(s,o){return xt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(Rt||(Rt={}));var Ds;(function(e){let t;e.codec=()=>(t==null&&(t=St((s,o,c={})=>{c.lengthDelimited!==!1&&o.fork(),s.Type!=null&&(o.uint32(8),Y.codec().encode(s.Type,o)),s.Data!=null&&(o.uint32(18),o.bytes(s.Data)),c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.Type=Y.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.Type`,value:Y.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return wt(s,e.codec())}e.encode=r;function n(s,o){return xt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(Ds||(Ds={}));function Zu(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Yu(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function _s(e,t,r=""){let n=Zu(e),i=e?.length,s=t!==void 0;if(!n||s&&i!==t){let o=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${i}`:`type=${typeof e}`,u=o+"expected Uint8Array"+c+", got "+a;throw n?new RangeError(u):new TypeError(u)}return e}function Ts(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Vo(e,t){_s(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function ir(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function jr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Dt(e,t){return e<<32-t|e>>>t}function Fo(e,t={}){let r=(i,s)=>e(s).update(i).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=i=>e(i),Object.assign(r,t),Object.freeze(r)}function $o(e=32){Yu(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var zo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Xr(e){if(isNaN(e)||e<=0)throw new $("random bytes length must be a Number bigger than 0");return $o(e)}var ar={};pt(ar,{MAX_RSA_KEY_SIZE:()=>Rs,generateRSAKeyPair:()=>Wo,jwkToJWKKeyPair:()=>Jo,jwkToPkcs1:()=>Qu,jwkToPkix:()=>Ks,jwkToRSAPrivateKey:()=>Hs,pkcs1MessageToJwk:()=>Ps,pkcs1MessageToRSAPrivateKey:()=>Os,pkcs1ToJwk:()=>Ju,pkcs1ToRSAPrivateKey:()=>Xo,pkixMessageToJwk:()=>Us,pkixMessageToRSAPublicKey:()=>qs,pkixToJwk:()=>tf,pkixToRSAPublicKey:()=>Ms});function Go(e,t,r){return e&t^~e&r}function Zo(e,t,r){return e&t^e&r^t&r}var Wr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,i){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(t),this.view=jr(this.buffer)}update(t){Ts(this),_s(t);let{view:r,buffer:n,blockLen:i}=this,s=t.length;for(let o=0;o<s;){let c=Math.min(i-this.pos,s-o);if(c===i){let a=jr(t);for(;i<=s-o;o+=i)this.process(a,o);continue}n.set(t.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ts(this),Vo(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:s}=this,{pos:o}=this;r[o++]=128,ir(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(n,0),o=0);for(let l=o;l<i;l++)r[l]=0;n.setBigUint64(i-8,BigInt(this.length*8),s),this.process(n,0);let c=jr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:c}=this;return t.destroyed=o,t.finished=s,t.length=i,t.pos=c,i%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ju=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]),ne=new Uint32Array(64),ks=class extends Wr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:i,E:s,F:o,G:c,H:a}=this;return[t,r,n,i,s,o,c,a]}set(t,r,n,i,s,o,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)ne[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let h=ne[l-15],d=ne[l-2],p=Dt(h,7)^Dt(h,18)^h>>>3,E=Dt(d,17)^Dt(d,19)^d>>>10;ne[l]=E+ne[l-7]+p+ne[l-16]|0}let{A:n,B:i,C:s,D:o,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let h=Dt(c,6)^Dt(c,11)^Dt(c,25),d=f+h+Go(c,a,u)+ju[l]+ne[l]|0,E=(Dt(n,2)^Dt(n,13)^Dt(n,22))+Zo(n,i,s)|0;f=u,u=a,a=c,c=o+d|0,o=s,s=i,i=n,n=d+E|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,s,o,c,a,u,f)}roundClean(){ir(ne)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ir(this.buffer)}},Cs=class extends ks{A=zt[0]|0;B=zt[1]|0;C=zt[2]|0;D=zt[3]|0;E=zt[4]|0;F=zt[5]|0;G=zt[6]|0;H=zt[7]|0;constructor(){super(32)}};var Jr=Fo(()=>new Cs,zo(1));var Pe=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=ar.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ct.createV1(114,this._multihash)}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,r,n){return jo(this.jwk,r,t,n)}},or=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=ar.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}sign(t,r){return Yo(this.jwk,t,r)}};var Rs=8192,Ns=18,Xu=1062,Wu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ju(e){let t=Ut(e);return Ps(t)}function Ps(e){return{n:V(e[1],"base64url"),e:V(e[2],"base64url"),d:V(e[3],"base64url"),p:V(e[4],"base64url"),q:V(e[5],"base64url"),dp:V(e[6],"base64url"),dq:V(e[7],"base64url"),qi:V(e[8],"base64url"),kty:"RSA"}}function Qu(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new $("JWK was missing components");return Xt([yt(Uint8Array.from([0])),yt(F(e.n,"base64url")),yt(F(e.e,"base64url")),yt(F(e.d,"base64url")),yt(F(e.p,"base64url")),yt(F(e.q,"base64url")),yt(F(e.dp,"base64url")),yt(F(e.dq,"base64url")),yt(F(e.qi,"base64url"))]).subarray()}function tf(e){let t=Ut(e,{offset:0});return Us(t)}function Us(e){let t=Ut(e[1],{offset:0});return{kty:"RSA",n:V(t[0],"base64url"),e:V(t[1],"base64url")}}function Ks(e){if(e.n==null||e.e==null)throw new $("JWK was missing components");return Xt([Wu,Cr(Xt([yt(F(e.n,"base64url")),yt(F(e.e,"base64url"))]))]).subarray()}function Xo(e){let t=Ut(e);return Os(t)}function Os(e){let t=Ps(e);return Hs(t)}function Ms(e,t){if(e.byteLength>=Xu)throw new we("Key size is too large");let r=Ut(e,{offset:0});return qs(r,e,t)}function qs(e,t,r){let n=Us(e);if(r==null){let i=Jr(Rt.encode({Type:Y.RSA,Data:t}));r=Tt(Ns,i)}return new Pe(n,r)}function Hs(e){if(ta(e)>Rs)throw new $("Key size is too large");let t=Jo(e),r=Jr(Rt.encode({Type:Y.RSA,Data:Ks(t.publicKey)})),n=Tt(Ns,r);return new or(t.privateKey,new Pe(t.publicKey,n))}async function Wo(e){if(e>Rs)throw new $("Key size is too large");let t=await Qo(e),r=Jr(Rt.encode({Type:Y.RSA,Data:Ks(t.publicKey)})),n=Tt(Ns,r);return new or(t.privateKey,new Pe(t.publicKey,n))}function Jo(e){if(e==null)throw new $("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Qo(e,t){let r=await At.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await ef(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Yo(e,t,r){let n=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let i=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(i,0,i.byteLength)}async function jo(e,t,r,n){let i=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},i,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function ef(e,t){if(e.privateKey==null||e.publicKey==null)throw new $("Private and public key are required");let r=await Promise.all([At.get().subtle.exportKey("jwk",e.privateKey),At.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function ta(e){if(e.kty!=="RSA")throw new $("invalid key type");if(e.n==null)throw new $("invalid key modulus");return F(e.n,"base64url").length*8}var Qr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(Rr(t),U(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=t.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),Mt(i)}update(t){return De(this),this.iHash.update(t),this}digestInto(t){De(this),U(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:i,destroyed:s,blockLen:o,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=s,t.blockLen=o,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Vs=(e,t,r)=>new Qr(e,t).update(r).digest();Vs.create=(e,t)=>new Qr(e,t);var ea=(e,t)=>(e+(e>=0?t:-t)/ra)/t;function rf(e,t,r){let[[n,i],[s,o]]=t,c=ea(o*e,r),a=ea(-i*e,r),u=e-c*n-a*s,f=-c*i-a*o,l=u<Gt,h=f<Gt;l&&(u=-u),h&&(f=-f);let d=Je(Math.ceil(Xn(r)/2))+Ue;if(u<Gt||u>=d||f<Gt||f>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:h,k2:f}}function $s(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Fs(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Ft(r.lowS,"lowS"),Ft(r.prehash,"prehash"),r.format!==void 0&&$s(r.format),r}var zs=class extends Error{constructor(t=""){super(t)}},se={Err:zs,_tlv:{encode:(e,t)=>{let{Err:r}=se;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,i=Xe(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Xe(i.length/2|128):"";return Xe(e)+s+i+t},decode(e,t){let{Err:r}=se,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let i=t[n++],s=!!(i&128),o=0;if(!s)o=i;else{let a=i&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)o=o<<8|f;if(n+=a,o<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+o);if(c.length!==o)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+o)}}},_int:{encode(e){let{Err:t}=se;if(e<Gt)throw new t("integer: negative integers are not allowed");let r=Xe(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=se;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Te(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=se,i=U(e,void 0,"signature"),{v:s,l:o}=n.decode(48,i);if(o.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l:f}=n.decode(2,a);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=se,n=t.encode(2,r.encode(e.r)),i=t.encode(2,r.encode(e.s)),s=n+i;return t.encode(48,s)}},Gt=BigInt(0),Ue=BigInt(1),ra=BigInt(2),tn=BigInt(3),nf=BigInt(4);function na(e,t={}){let r=Mr("weierstrass",e,t),{Fp:n,Fn:i}=r,s=r.CURVE,{h:o,n:c}=s;te(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=ia(n,i);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(T,y,g){let{x:m,y:A}=y.toAffine(),L=n.toBytes(m);if(Ft(g,"isCompressed"),g){f();let _=!n.isOdd(A);return gt(sa(_),L)}else return gt(Uint8Array.of(4),L,n.toBytes(A))}function h(T){U(T,void 0,"Point");let{publicKey:y,publicKeyUncompressed:g}=u,m=T.length,A=T[0],L=T.subarray(1);if(m===y&&(A===2||A===3)){let _=n.fromBytes(L);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let k=E(_),D;try{D=n.sqrt(k)}catch(j){let z=j instanceof Error?": "+j.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}f();let C=n.isOdd(D);return(A&1)===1!==C&&(D=n.neg(D)),{x:_,y:D}}else if(m===g&&A===4){let _=n.BYTES,k=n.fromBytes(L.subarray(0,_)),D=n.fromBytes(L.subarray(_,_*2));if(!v(k,D))throw new Error("bad point: is not on curve");return{x:k,y:D}}else throw new Error(`bad point: got length ${m}, expected compressed=${y} or uncompressed=${g}`)}let d=t.toBytes||l,p=t.fromBytes||h;function E(T){let y=n.sqr(T),g=n.mul(y,T);return n.add(n.add(g,n.mul(T,s.a)),s.b)}function v(T,y){let g=n.sqr(y),m=E(T);return n.eql(g,m)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,tn),nf),I=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,I)))throw new Error("bad curve params: a or b");function x(T,y,g=!1){if(!n.isValid(y)||g&&n.is0(y))throw new Error(`bad point coordinate ${T}`);return y}function B(T){if(!(T instanceof w))throw new Error("Weierstrass Point expected")}function R(T){if(!a||!a.basises)throw new Error("no endo");return rf(T,a.basises,i.ORDER)}let K=ke((T,y)=>{let{X:g,Y:m,Z:A}=T;if(n.eql(A,n.ONE))return{x:g,y:m};let L=T.is0();y==null&&(y=L?n.ONE:n.inv(A));let _=n.mul(g,y),k=n.mul(m,y),D=n.mul(A,y);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(D,n.ONE))throw new Error("invZ was invalid");return{x:_,y:k}}),O=ke(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:y,y:g}=T.toAffine();if(!n.isValid(y)||!n.isValid(g))throw new Error("bad point: x or y not field elements");if(!v(y,g))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function S(T,y,g,m,A){return g=new w(n.mul(g.X,T),g.Y,g.Z),y=tr(m,y),g=tr(A,g),y.add(g)}class w{static BASE=new w(s.Gx,s.Gy,n.ONE);static ZERO=new w(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=i;X;Y;Z;constructor(y,g,m){this.X=x("x",y),this.Y=x("y",g,!0),this.Z=x("z",m),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x:g,y:m}=y||{};if(!y||!n.isValid(g)||!n.isValid(m))throw new Error("invalid affine point");if(y instanceof w)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(m)?w.ZERO:new w(g,m,n.ONE)}static fromBytes(y){let g=w.fromAffine(p(U(y,void 0,"point")));return g.assertValidity(),g}static fromHex(y){return w.fromBytes(Ht(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,g=!0){return M.createCache(this,y),g||this.multiply(tn),this}assertValidity(){O(this)}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){B(y);let{X:g,Y:m,Z:A}=this,{X:L,Y:_,Z:k}=y,D=n.eql(n.mul(g,k),n.mul(L,A)),C=n.eql(n.mul(m,k),n.mul(_,A));return D&&C}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b:g}=s,m=n.mul(g,tn),{X:A,Y:L,Z:_}=this,k=n.ZERO,D=n.ZERO,C=n.ZERO,P=n.mul(A,A),j=n.mul(L,L),z=n.mul(_,_),q=n.mul(A,L);return q=n.add(q,q),C=n.mul(A,_),C=n.add(C,C),k=n.mul(y,C),D=n.mul(m,z),D=n.add(k,D),k=n.sub(j,D),D=n.add(j,D),D=n.mul(k,D),k=n.mul(q,k),C=n.mul(m,C),z=n.mul(y,z),q=n.sub(P,z),q=n.mul(y,q),q=n.add(q,C),C=n.add(P,P),P=n.add(C,P),P=n.add(P,z),P=n.mul(P,q),D=n.add(D,P),z=n.mul(L,_),z=n.add(z,z),P=n.mul(z,q),k=n.sub(k,P),C=n.mul(z,j),C=n.add(C,C),C=n.add(C,C),new w(k,D,C)}add(y){B(y);let{X:g,Y:m,Z:A}=this,{X:L,Y:_,Z:k}=y,D=n.ZERO,C=n.ZERO,P=n.ZERO,j=s.a,z=n.mul(s.b,tn),q=n.mul(g,L),X=n.mul(m,_),it=n.mul(A,k),_t=n.add(g,m),W=n.add(L,_);_t=n.mul(_t,W),W=n.add(q,X),_t=n.sub(_t,W),W=n.add(g,A);let at=n.add(L,k);return W=n.mul(W,at),at=n.add(q,it),W=n.sub(W,at),at=n.add(m,A),D=n.add(_,k),at=n.mul(at,D),D=n.add(X,it),at=n.sub(at,D),P=n.mul(j,W),D=n.mul(z,it),P=n.add(D,P),D=n.sub(X,P),P=n.add(X,P),C=n.mul(D,P),X=n.add(q,q),X=n.add(X,q),it=n.mul(j,it),W=n.mul(z,W),X=n.add(X,it),it=n.sub(q,it),it=n.mul(j,it),W=n.add(W,it),q=n.mul(X,W),C=n.add(C,q),q=n.mul(at,W),D=n.mul(_t,D),D=n.sub(D,q),q=n.mul(_t,X),P=n.mul(at,P),P=n.add(P,q),new w(D,C,P)}subtract(y){return this.add(y.negate())}is0(){return this.equals(w.ZERO)}multiply(y){let{endo:g}=t;if(!i.isValidNot0(y))throw new Error("invalid scalar: out of range");let m,A,L=_=>M.cached(this,_,k=>pe(w,k));if(g){let{k1neg:_,k1:k,k2neg:D,k2:C}=R(y),{p:P,f:j}=L(k),{p:z,f:q}=L(C);A=j.add(q),m=S(g.beta,P,z,_,D)}else{let{p:_,f:k}=L(y);m=_,A=k}return pe(w,[m,A])[0]}multiplyUnsafe(y){let{endo:g}=t,m=this;if(!i.isValid(y))throw new Error("invalid scalar: out of range");if(y===Gt||m.is0())return w.ZERO;if(y===Ue)return m;if(M.hasCache(this))return this.multiply(y);if(g){let{k1neg:A,k1:L,k2neg:_,k2:k}=R(y),{p1:D,p2:C}=So(w,m,L,k);return S(g.beta,D,C,A,_)}else return M.unsafe(m,y)}toAffine(y){return K(this,y)}isTorsionFree(){let{isTorsionFree:y}=t;return o===Ue?!0:y?y(w,this):M.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:y}=t;return o===Ue?this:y?y(w,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(y=!0){return Ft(y,"isCompressed"),this.assertValidity(),d(w,this,y)}toHex(y=!0){return qt(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=i.BITS,M=new Ne(w,t.endo?Math.ceil(N/2):N);return w.BASE.precompute(8),w}function sa(e){return Uint8Array.of(e?2:3)}function ia(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function sf(e,t={}){let{Fn:r}=e,n=t.randomBytes||_e,i=Object.assign(ia(e.Fp,r),{seed:ts(r.ORDER)});function s(d){try{let p=r.fromBytes(d);return r.isValidNot0(p)}catch{return!1}}function o(d,p){let{publicKey:E,publicKeyUncompressed:v}=i;try{let b=d.length;return p===!0&&b!==E||p===!1&&b!==v?!1:!!e.fromBytes(d)}catch{return!1}}function c(d=n(i.seed)){return es(U(d,i.seed,"seed"),r.ORDER)}function a(d,p=!0){return e.BASE.multiply(r.fromBytes(d)).toBytes(p)}function u(d){let{secretKey:p,publicKey:E,publicKeyUncompressed:v}=i;if(!ce(d)||"_lengths"in r&&r._lengths||p===E)return;let b=U(d,void 0,"key").length;return b===E||b===v}function f(d,p,E=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(p)===!1)throw new Error("second arg must be public key");let v=r.fromBytes(d);return e.fromBytes(p).multiply(v).toBytes(E)}let l={isValidSecretKey:s,isValidPublicKey:o,randomSecretKey:c},h=qr(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:f,keygen:h,Point:e,utils:l,lengths:i})}function oa(e,t,r={}){Rr(t),te(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||_e,i=r.hmac||((g,m)=>Vs(t,g,m)),{Fp:s,Fn:o}=e,{ORDER:c,BITS:a}=o,{keygen:u,getPublicKey:f,getSharedSecret:l,utils:h,lengths:d}=sf(e,r),p={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},E=c*ra<s.ORDER;function v(g){let m=c>>Ue;return g>m}function b(g,m){if(!o.isValidNot0(m))throw new Error(`invalid signature ${g}: out of range 1..Point.Fn.ORDER`);return m}function I(){if(E)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function x(g,m){$s(m);let A=d.signature,L=m==="compact"?A:m==="recovered"?A+1:void 0;return U(g,L)}class B{r;s;recovery;constructor(m,A,L){if(this.r=b("r",m),this.s=b("s",A),L!=null){if(I(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(m,A=p.format){x(m,A);let L;if(A==="der"){let{r:C,s:P}=se.toSig(U(m));return new B(C,P)}A==="recovered"&&(L=m[0],A="compact",m=m.subarray(1));let _=d.signature/2,k=m.subarray(0,_),D=m.subarray(_,_*2);return new B(o.fromBytes(k),o.fromBytes(D),L)}static fromHex(m,A){return this.fromBytes(Ht(m),A)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new B(this.r,this.s,m)}recoverPublicKey(m){let{r:A,s:L}=this,_=this.assertRecovery(),k=_===2||_===3?A+c:A;if(!s.isValid(k))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=s.toBytes(k),C=e.fromBytes(gt(sa((_&1)===0),D)),P=o.inv(k),j=K(U(m,void 0,"msgHash")),z=o.create(-j*P),q=o.create(L*P),X=e.BASE.multiplyUnsafe(z).add(C.multiplyUnsafe(q));if(X.is0())throw new Error("invalid recovery: point at infinify");return X.assertValidity(),X}hasHighS(){return v(this.s)}toBytes(m=p.format){if($s(m),m==="der")return Ht(se.hexFromSig(this));let{r:A,s:L}=this,_=o.toBytes(A),k=o.toBytes(L);return m==="recovered"?(I(),gt(Uint8Array.of(this.assertRecovery()),_,k)):gt(_,k)}toHex(m){return qt(this.toBytes(m))}}let R=r.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let A=Te(m),L=m.length*8-a;return L>0?A>>BigInt(L):A},K=r.bits2int_modN||function(m){return o.create(R(m))},O=Je(a);function S(g){return We("num < 2^"+a,g,Gt,O),o.toBytes(g)}function w(g,m){return U(g,void 0,"message"),m?U(t(g),void 0,"prehashed message"):g}function N(g,m,A){let{lowS:L,prehash:_,extraEntropy:k}=Fs(A,p);g=w(g,_);let D=K(g),C=o.fromBytes(m);if(!o.isValidNot0(C))throw new Error("invalid private key");let P=[S(C),S(D)];if(k!=null&&k!==!1){let X=k===!0?n(d.secretKey):k;P.push(U(X,void 0,"extraEntropy"))}let j=gt(...P),z=D;function q(X){let it=R(X);if(!o.isValidNot0(it))return;let _t=o.inv(it),W=e.BASE.multiply(it).toAffine(),at=o.create(W.x);if(at===Gt)return;let Ir=o.create(_t*o.create(z+at*C));if(Ir===Gt)return;let ci=(W.x===at?0:2)|Number(W.y&Ue),ui=Ir;return L&&v(Ir)&&(ui=o.neg(Ir),ci^=1),new B(at,ui,E?void 0:ci)}return{seed:j,k2sig:q}}function M(g,m,A={}){let{seed:L,k2sig:_}=N(g,m,A);return so(t.outputLen,o.BYTES,i)(L,_).toBytes(A.format)}function T(g,m,A,L={}){let{lowS:_,prehash:k,format:D}=Fs(L,p);if(A=U(A,void 0,"publicKey"),m=w(m,k),!ce(g)){let C=g instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+C)}x(g,D);try{let C=B.fromBytes(g,D),P=e.fromBytes(A);if(_&&C.hasHighS())return!1;let{r:j,s:z}=C,q=K(m),X=o.inv(z),it=o.create(q*X),_t=o.create(j*X),W=e.BASE.multiplyUnsafe(it).add(P.multiplyUnsafe(_t));return W.is0()?!1:o.create(W.x)===j}catch{return!1}}function y(g,m,A={}){let{prehash:L}=Fs(A,p);return m=w(m,L),B.fromBytes(g,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:l,utils:h,lengths:d,Point:e,sign:M,verify:T,recoverPublicKey:y,Signature:B,hash:t})}var Zs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},of={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var aa=BigInt(2);function af(e){let t=Zs.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=G(f,r,t)*f%t,h=G(l,r,t)*f%t,d=G(h,aa,t)*u%t,p=G(d,i,t)*d%t,E=G(p,s,t)*p%t,v=G(E,c,t)*E%t,b=G(v,a,t)*v%t,I=G(b,c,t)*E%t,x=G(I,r,t)*f%t,B=G(x,o,t)*p%t,R=G(B,n,t)*u%t,K=G(R,aa,t);if(!Gs.eql(Gs.sqr(K),e))throw new Error("Cannot find square root");return K}var Gs=Ce(Zs.p,{sqrt:af}),cf=na(Zs,{Fp:Gs,endo:of}),Ke=oa(cf,to);function ca(e,t,r,n){let i=ae.digest(r instanceof Uint8Array?r:r.subarray());if(Fr(i))return i.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ke.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new er(String(s))});try{return n?.signal?.throwIfAborted(),Ke.verify(t,i.digest,e,{prehash:!1,format:"der"})}catch(s){throw new er(String(s))}}var en=class{type="secp256k1";raw;_key;constructor(t){this._key=fa(t),this.raw=ua(this._key)}toMultihash(){return It.digest(Kt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,r,n){return ca(this._key,r,t,n)}};function Ys(e){return new en(e)}function ua(e){return Ke.Point.fromBytes(e).toBytes()}function fa(e){try{return Ke.Point.fromBytes(e),e}catch(t){throw new we(String(t))}}function js(e,t){let{Type:r,Data:n}=Rt.decode(e),i=n??new Uint8Array;switch(r){case Y.RSA:return Ms(i,t);case Y.Ed25519:return us(i);case Y.secp256k1:return Ys(i);case Y.ECDSA:return On(i);default:throw new ie}}function la(e){let{Type:t,Data:r}=Rt.decode(e.digest),n=r??new Uint8Array;switch(t){case Y.Ed25519:return us(n);case Y.secp256k1:return Ys(n);case Y.ECDSA:return On(n);default:throw new ie}}function Kt(e){return Rt.encode({Type:Y[e.type],Data:e.raw})}var ha=Symbol.for("nodejs.util.inspect.custom"),uf=114,cr=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()})`}[fn]=!0;toString(){return this.string==null&&(this.string=Z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(uf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return mt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return mt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ha](){return`PeerId(${this.toString()})`}},ur=class extends cr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},fr=class extends cr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},lr=class extends cr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ff=2336,rn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=It.digest(F(this.url))}[ha](){return`PeerId(${this.url})`}[fn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(ff,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=V(t)),t.toString()===this.toString())}};function Xs(e){if(e.type==="Ed25519")return new fr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new lr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new ur({multihash:e.toCID().multihash,publicKey:e});throw new ie}function da(e){return Xs(e.publicKey)}function hr(e){if(hf(e))return new ur({multihash:e});if(lf(e))try{let t=la(e);if(t.type==="Ed25519")return new fr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new lr({multihash:e,publicKey:t})}catch{let r=V(e.digest);return new rn(new URL(r))}throw new Lr("Supplied PeerID Multihash is invalid")}function lf(e){return e.code===It.code}function hf(e){return e.code===ae.code}function ye(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),i=n.value;return n.done===!0||i==null?{done:!0,value:void 0}:{done:!1,value:t(i)}}};return r}function nn(e){let t=Yt(Z.decode(`z${e}`));return hr(t)}var dr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return ye(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return ye(this.map.values(),t=>t.key)}values(){return ye(this.map.values(),t=>t.value)}get size(){return this.map.size}};var pr=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.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 ye(this.set.entries(),t=>{let r=nn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=nn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return ye(this.set.values(),t=>nn(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};var Ws=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},pa=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function mr(e,t){let{milliseconds:r,fallback:n,message:i,customTimers:s={setTimeout,clearTimeout},signal:o}=t,c,a,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(o?.aborted){h(pa(o));return}if(o&&(a=()=>{h(pa(o))},o.addEventListener("abort",a,{once:!0})),e.then(l,h),r===Number.POSITIVE_INFINITY)return;let d=new Ws;c=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(p){h(p)}return}typeof e.cancel=="function"&&e.cancel(),i===!1?l():i instanceof Error?h(i):(d.message=i??`Promise timed out after ${r} milliseconds`,h(d))},r)}).finally(()=>{f.clear(),a&&o&&o.removeEventListener("abort",a)});return f.clear=()=>{s.clearTimeout.call(void 0,c),c=void 0},f}var df=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function pf(e,t,r){let n,i=new Promise((s,o)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let c=[t].flat(),a=[],{addListener:u,removeListener:f}=df(e),l=async(...d)=>{let p=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(p))return}catch(E){n(),o(E);return}a.push(p),r.count===a.length&&(n(),s(a))},h=(...d)=>{n(),o(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of c)f(d,l);for(let d of r.rejectionEvents)c.includes(d)||f(d,h)};for(let d of c)u(d,l);for(let d of r.rejectionEvents)c.includes(d)||u(d,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(a)});if(i.cancel=n,typeof r.timeout=="number"){let s=mr(i,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return i}function ma(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=pf(e,t,r),i=n.then(s=>s[0]);return i.cancel=n.cancel,i}var ge=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function mf(e){return e.reason}async function Js(e,t,r){if(t==null)return e;let n=r?.translateError??mf;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let i;try{return await Promise.race([e,new Promise((s,o)=>{i=()=>{o(n(t))},t.addEventListener("abort",i)})])}finally{i!=null&&t.removeEventListener("abort",i)}}var yf=4194304,sn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ti=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ei=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ri=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function gf(e){return typeof e?.closeRead=="function"}function xf(e){return typeof e?.close=="function"}function Qs(e){return gf(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:xf(e)?e.status!=="open":!1}function wf(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Ef(e,t){let r=t?.maxBufferSize??yf,n=new rt,i,s=!1;if(!wf(e))throw new $("Argument should be a Stream or a Multiaddr");let o=f=>{if(n.append(f.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),i?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}i?.resolve()};e.addEventListener("message",o);let c=f=>{f.error!=null?i?.reject(f.error):i?.resolve()};e.addEventListener("close",c);let a=()=>{i?.resolve()};e.addEventListener("remoteCloseWrite",a);let u={readBuffer:n,async read(f){if(s===!0)throw new sn("Stream was unwrapped");if(Qs(e)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new ge(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(i=Promise.withResolvers();;){if(n.byteLength>=l){i.resolve();break}if(await Js(i.promise,f?.signal),Qs(e)){if(n.byteLength===0&&f?.bytes==null)return null;break}i=Promise.withResolvers()}let h=f?.bytes??n.byteLength;if(n.byteLength<h){if(Qs(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,h),new ge(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return u.read(f)}let d=n.sublist(0,h);return n.consume(h),d},async write(f,l){if(s===!0)throw new sn("Stream was unwrapped");e.send(f)||await ma(e,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",o),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return u}function Sf(e,t={}){let r=Ef(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=$t(t.maxDataLength));let n=t?.lengthDecoder??Co,i=t?.lengthEncoder??ko;return{async read(o){let c=-1,a=new rt;for(;;){let f=await r.read({...o,bytes:1});if(f==null)break;a.append(f);try{c=n(a)}catch(l){if(l instanceof RangeError)continue;throw l}if(c<0)throw new ti("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new ri(`Message length length too long - ${a.byteLength} > ${t.maxLengthLength}`);if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new ei(`Message length too long - ${c} > ${t.maxDataLength}`);let u=await r.read({...o,bytes:c});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",c),new ge(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(u.byteLength!==c)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,c),new ge(`Unexpected EOF - read ${u.byteLength}/${c} bytes before the stream closed`);return u},async write(o,c){await r.write(new rt(i(o.byteLength),o),c)},async writeV(o,c){let a=new rt(...o.flatMap(u=>[i(u.byteLength),u]));await r.write(a,c)},unwrap(){return r.unwrap()}}}function ni(e,t){let r=Sf(e,t),n={read:async(i,s)=>{let o=await r.read(s);return i.decode(o)},write:async(i,s,o)=>{await r.write(s.encode(i),o)},writeV:async(i,s,o)=>{await r.writeV(i.map(c=>s.encode(c)),o)},pb:i=>({read:async s=>n.read(i,s),write:async(s,o)=>n.write(s,i,o),writeV:async(s,o)=>n.writeV(s,i,o),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var ii=ka(ya(),1);function oi(e,t,r){let n=0,i=e.length;for(;i>0;){let s=Math.trunc(i/2),o=n+s;r(e[o],t)<=0?(n=++o,i-=s+1):i=s}return n}var Oe=class{#t=[];enqueue(t,r){let{priority:n=0,id:i}=r??{},s={priority:n,id:i,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(s);return}let o=oi(this.#t,s,(c,a)=>a.priority-c.priority);this.#t.splice(o,0,s)}setPriority(t,r){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[i]=this.#t.splice(n,1);this.enqueue(i.run,{priority:r,id:t})}remove(t){let r=this.#t.findIndex(n=>typeof t=="string"?n.id===t:n.run===t);r!==-1&&this.#t.splice(r,1)}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#t.length}};var yr=class extends ii.default{#t;#o;#a=0;#d;#m=!1;#x=!1;#c;#L=0;#w=0;#u;#f;#i;#s=[];#n=0;#e;#D;#r=0;#b;#l;#R=1n;#y=new Map;#E=new Set;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Oe,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.#D=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.#H()}#S(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)}#N(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--}#v(){return this.#s.length-this.#n}get#U(){return this.#o?!0:this.#i?this.#v()<this.#d:this.#a<this.#d}get#K(){return this.#r<this.#b}#O(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#M(){this.#f=void 0,this.#k(),this.#T()}#q(t){if(this.#i){if(this.#S(t),this.#v()>=this.#d){let n=this.#s[this.#n],i=this.#c-(t-n);return this.#A(i),!0}return!1}if(this.#u===void 0){let r=this.#L-t;if(r<0){if(this.#w>0){let n=t-this.#w;if(n<this.#c)return this.#A(this.#c-n),!0}this.#a=this.#t?this.#r:0}else return this.#A(r),!0}return!1}#A(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#M()},t))}#I(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#_(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#g(){if(this.#e.size===0){if(this.#I(),this.emit("empty"),this.#r===0){if(this.#_(),this.#i&&this.#n>0){let r=Date.now();this.#S(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#q(r);if(this.#U&&this.#K){let i=this.#e.dequeue();this.#o||(this.#N(r),this.#p()),this.emit("active"),i(),n&&this.#T(),t=!0}}return t}#T(){this.#o||this.#u!==void 0||this.#i||(this.#u=setInterval(()=>{this.#k()},this.#c),this.#L=Date.now()+this.#c)}#k(){this.#i||(this.#a===0&&this.#r===0&&this.#u&&this.#I(),this.#a=this.#t?this.#r:0),this.#B(),this.#p()}#B(){for(;this.#g(););}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.#B()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#e.setPriority(t,r)}async add(t,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#R++).toString()},new Promise((n,i)=>{let s=Symbol(`task-${r.id}`),o=()=>{},c=async()=>{o(),this.#r++,this.#y.set(s,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(h){throw this.#V(),this.#y.delete(s),h}this.#w=Date.now();let f=t({signal:r.signal});if(r.timeout&&(f=mr(Promise.resolve(f),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#r} running, ${this.#e.size} waiting)`})),r.signal){let{signal:h}=r;f=Promise.race([f,new Promise((d,p)=>{u=()=>{p(h.reason)},h.addEventListener("abort",u,{once:!0})})])}let l=await f;n(l),this.emit("completed",l)}catch(f){i(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#y.delete(s),queueMicrotask(()=>{this.#O()})}};this.#e.enqueue(c,r);let a=()=>{if(this.#e instanceof Oe){this.#e.remove(c);return}this.#e.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{o(),a(),i(u.reason),this.#g(),this.emit("next")};if(o=()=>{u.removeEventListener("abort",f),this.#E.delete(o)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(o)}this.emit("add"),this.#g()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#B(),this):this}pause(){this.#l=!0}clear(){for(let t of this.#E)t();this.#e=new this.#D,this.#I(),this.#C(),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,r)=>{let n=i=>{this.off("error",n),r(i)};this.on("error",n)})}async#h(t,r){return new Promise(n=>{let i=()=>{r&&!r()||(this.off(t,i),n())};this.on(t,i)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#r}get isPaused(){return this.#l}#H(){this.#o||(this.on("add",()=>{this.#e.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#o||this.#x||(this.#x=!0,queueMicrotask(()=>{this.#x=!1,this.#C()}))}#V(){this.#o||(this.#P(),this.#p())}#C(){let t=this.#m;if(this.#o||this.#e.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#i){let i=Date.now();this.#S(i),r=this.#v()}else r=this.#a;let n=r>=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 an=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,r){this.entries.set(t,{value:r,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[r,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(r);else break}}has(t){return this.entries.has(t)}get(t){let r=this.entries.get(t);return r!=null&&r.validUntilMs>=Date.now()?r.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var xe;(function(e){let t;(function(c){let a;c.codec=()=>(a==null&&(a=St((h,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),h.subscribe!=null&&(d.uint32(8),d.bool(h.subscribe)),h.topic!=null&&(d.uint32(18),d.string(h.topic)),p.lengthDelimited!==!1&&d.ldelim()},(h,d,p={})=>{let E={},v=d==null?h.len:h.pos+d;for(;h.pos<v;){let b=h.uint32();switch(b>>>3){case 1:{E.subscribe=h.bool();break}case 2:{E.topic=h.string();break}default:{h.skipType(b&7);break}}}return E},function*(h,d,p,E={}){let v=d==null?h.len:h.pos+d;for(;h.pos<v;){let b=h.uint32();switch(b>>>3){case 1:{yield{field:`${p}.subscribe`,value:h.bool()};break}case 2:{yield{field:`${p}.topic`,value:h.string()};break}default:{h.skipType(b&7);break}}}})),a);function u(h){return wt(h,c.codec())}c.encode=u;function f(h,d){return xt(h,c.codec(),d)}c.decode=f;function l(h,d){return Et(h,c.codec(),d)}c.stream=l})(t=e.SubOpts||(e.SubOpts={}));let r;(function(c){let a;c.codec=()=>(a==null&&(a=St((h,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),h.from!=null&&(d.uint32(10),d.bytes(h.from)),h.data!=null&&(d.uint32(18),d.bytes(h.data)),h.sequenceNumber!=null&&(d.uint32(26),d.bytes(h.sequenceNumber)),h.topic!=null&&(d.uint32(34),d.string(h.topic)),h.signature!=null&&(d.uint32(42),d.bytes(h.signature)),h.key!=null&&(d.uint32(50),d.bytes(h.key)),p.lengthDelimited!==!1&&d.ldelim()},(h,d,p={})=>{let E={},v=d==null?h.len:h.pos+d;for(;h.pos<v;){let b=h.uint32();switch(b>>>3){case 1:{E.from=h.bytes();break}case 2:{E.data=h.bytes();break}case 3:{E.sequenceNumber=h.bytes();break}case 4:{E.topic=h.string();break}case 5:{E.signature=h.bytes();break}case 6:{E.key=h.bytes();break}default:{h.skipType(b&7);break}}}return E},function*(h,d,p,E={}){let v=d==null?h.len:h.pos+d;for(;h.pos<v;){let b=h.uint32();switch(b>>>3){case 1:{yield{field:`${p}.from`,value:h.bytes()};break}case 2:{yield{field:`${p}.data`,value:h.bytes()};break}case 3:{yield{field:`${p}.sequenceNumber`,value:h.bytes()};break}case 4:{yield{field:`${p}.topic`,value:h.string()};break}case 5:{yield{field:`${p}.signature`,value:h.bytes()};break}case 6:{yield{field:`${p}.key`,value:h.bytes()};break}default:{h.skipType(b&7);break}}}})),a);function u(h){return wt(h,c.codec())}c.encode=u;function f(h,d){return xt(h,c.codec(),d)}c.decode=f;function l(h,d){return Et(h,c.codec(),d)}c.stream=l})(r=e.Message||(e.Message={}));let n;e.codec=()=>(n==null&&(n=St((c,a,u={})=>{if(u.lengthDelimited!==!1&&a.fork(),c.subscriptions!=null&&c.subscriptions.length>0)for(let f of c.subscriptions)a.uint32(10),e.SubOpts.codec().encode(f,a);if(c.messages!=null&&c.messages.length>0)for(let f of c.messages)a.uint32(18),e.Message.codec().encode(f,a);c.control!=null&&(a.uint32(26),gr.codec().encode(c.control,a)),u.lengthDelimited!==!1&&a.ldelim()},(c,a,u={})=>{let f={subscriptions:[],messages:[]},l=a==null?c.len:c.pos+a;for(;c.pos<l;){let h=c.uint32();switch(h>>>3){case 1:{if(u.limits?.subscriptions!=null&&f.subscriptions.length===u.limits.subscriptions)throw new et('Decode error - repeated field "subscriptions" had too many elements');f.subscriptions.push(e.SubOpts.codec().decode(c,c.uint32(),{limits:u.limits?.subscriptions$}));break}case 2:{if(u.limits?.messages!=null&&f.messages.length===u.limits.messages)throw new et('Decode error - repeated field "messages" had too many elements');f.messages.push(e.Message.codec().decode(c,c.uint32(),{limits:u.limits?.messages$}));break}case 3:{f.control=gr.codec().decode(c,c.uint32(),{limits:u.limits?.control});break}default:{c.skipType(h&7);break}}}return f},function*(c,a,u,f={}){let l={subscriptions:0,messages:0},h=a==null?c.len:c.pos+a;for(;c.pos<h;){let d=c.uint32();switch(d>>>3){case 1:{if(f.limits?.subscriptions!=null&&l.subscriptions===f.limits.subscriptions)throw new et('Streaming decode error - repeated field "subscriptions" had too many elements');for(let p of e.SubOpts.codec().stream(c,c.uint32(),`${u}.subscriptions[]`,{limits:f.limits?.subscriptions$}))yield{...p,index:l.subscriptions};l.subscriptions++;break}case 2:{if(f.limits?.messages!=null&&l.messages===f.limits.messages)throw new et('Streaming decode error - repeated field "messages" had too many elements');for(let p of e.Message.codec().stream(c,c.uint32(),`${u}.messages[]`,{limits:f.limits?.messages$}))yield{...p,index:l.messages};l.messages++;break}case 3:{yield*gr.codec().stream(c,c.uint32(),`${u}.control`,{limits:f.limits?.control});break}default:{c.skipType(d&7);break}}}})),n);function i(c){return wt(c,e.codec())}e.encode=i;function s(c,a){return xt(c,e.codec(),a)}e.decode=s;function o(c,a){return Et(c,e.codec(),a)}e.stream=o})(xe||(xe={}));var gr;(function(e){let t;e.codec=()=>(t==null&&(t=St((s,o,c={})=>{if(c.lengthDelimited!==!1&&o.fork(),s.ihave!=null&&s.ihave.length>0)for(let a of s.ihave)o.uint32(10),xr.codec().encode(a,o);if(s.iwant!=null&&s.iwant.length>0)for(let a of s.iwant)o.uint32(18),wr.codec().encode(a,o);if(s.graft!=null&&s.graft.length>0)for(let a of s.graft)o.uint32(26),Er.codec().encode(a,o);if(s.prune!=null&&s.prune.length>0)for(let a of s.prune)o.uint32(34),Sr.codec().encode(a,o);c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={ihave:[],iwant:[],graft:[],prune:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(c.limits?.ihave!=null&&a.ihave.length===c.limits.ihave)throw new et('Decode error - repeated field "ihave" had too many elements');a.ihave.push(xr.codec().decode(s,s.uint32(),{limits:c.limits?.ihave$}));break}case 2:{if(c.limits?.iwant!=null&&a.iwant.length===c.limits.iwant)throw new et('Decode error - repeated field "iwant" had too many elements');a.iwant.push(wr.codec().decode(s,s.uint32(),{limits:c.limits?.iwant$}));break}case 3:{if(c.limits?.graft!=null&&a.graft.length===c.limits.graft)throw new et('Decode error - repeated field "graft" had too many elements');a.graft.push(Er.codec().decode(s,s.uint32(),{limits:c.limits?.graft$}));break}case 4:{if(c.limits?.prune!=null&&a.prune.length===c.limits.prune)throw new et('Decode error - repeated field "prune" had too many elements');a.prune.push(Sr.codec().decode(s,s.uint32(),{limits:c.limits?.prune$}));break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u={ihave:0,iwant:0,graft:0,prune:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{if(a.limits?.ihave!=null&&u.ihave===a.limits.ihave)throw new et('Streaming decode error - repeated field "ihave" had too many elements');for(let h of xr.codec().stream(s,s.uint32(),`${c}.ihave[]`,{limits:a.limits?.ihave$}))yield{...h,index:u.ihave};u.ihave++;break}case 2:{if(a.limits?.iwant!=null&&u.iwant===a.limits.iwant)throw new et('Streaming decode error - repeated field "iwant" had too many elements');for(let h of wr.codec().stream(s,s.uint32(),`${c}.iwant[]`,{limits:a.limits?.iwant$}))yield{...h,index:u.iwant};u.iwant++;break}case 3:{if(a.limits?.graft!=null&&u.graft===a.limits.graft)throw new et('Streaming decode error - repeated field "graft" had too many elements');for(let h of Er.codec().stream(s,s.uint32(),`${c}.graft[]`,{limits:a.limits?.graft$}))yield{...h,index:u.graft};u.graft++;break}case 4:{if(a.limits?.prune!=null&&u.prune===a.limits.prune)throw new et('Streaming decode error - repeated field "prune" had too many elements');for(let h of Sr.codec().stream(s,s.uint32(),`${c}.prune[]`,{limits:a.limits?.prune$}))yield{...h,index:u.prune};u.prune++;break}default:{s.skipType(l&7);break}}}})),t);function r(s){return wt(s,e.codec())}e.encode=r;function n(s,o){return xt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(gr||(gr={}));var xr;(function(e){let t;e.codec=()=>(t==null&&(t=St((s,o,c={})=>{if(c.lengthDelimited!==!1&&o.fork(),s.topic!=null&&(o.uint32(10),o.string(s.topic)),s.messageIDs!=null&&s.messageIDs.length>0)for(let a of s.messageIDs)o.uint32(18),o.bytes(a);c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={messageIDs:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.topic=s.string();break}case 2:{if(c.limits?.messageIDs!=null&&a.messageIDs.length===c.limits.messageIDs)throw new et('Decode error - repeated field "messageIDs" had too many elements');a.messageIDs.push(s.bytes());break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u={messageIDs:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${c}.topic`,value:s.string()};break}case 2:{if(a.limits?.messageIDs!=null&&u.messageIDs===a.limits.messageIDs)throw new et('Streaming decode error - repeated field "messageIDs" had too many elements');yield{field:`${c}.messageIDs[]`,index:u.messageIDs,value:s.bytes()},u.messageIDs++;break}default:{s.skipType(l&7);break}}}})),t);function r(s){return wt(s,e.codec())}e.encode=r;function n(s,o){return xt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(xr||(xr={}));var wr;(function(e){let t;e.codec=()=>(t==null&&(t=St((s,o,c={})=>{if(c.lengthDelimited!==!1&&o.fork(),s.messageIDs!=null&&s.messageIDs.length>0)for(let a of s.messageIDs)o.uint32(10),o.bytes(a);c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={messageIDs:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(c.limits?.messageIDs!=null&&a.messageIDs.length===c.limits.messageIDs)throw new et('Decode error - repeated field "messageIDs" had too many elements');a.messageIDs.push(s.bytes());break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u={messageIDs:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{if(a.limits?.messageIDs!=null&&u.messageIDs===a.limits.messageIDs)throw new et('Streaming decode error - repeated field "messageIDs" had too many elements');yield{field:`${c}.messageIDs[]`,index:u.messageIDs,value:s.bytes()},u.messageIDs++;break}default:{s.skipType(l&7);break}}}})),t);function r(s){return wt(s,e.codec())}e.encode=r;function n(s,o){return xt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(wr||(wr={}));var Er;(function(e){let t;e.codec=()=>(t==null&&(t=St((s,o,c={})=>{c.lengthDelimited!==!1&&o.fork(),s.topic!=null&&(o.uint32(10),o.string(s.topic)),c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();f>>>3===1?a.topic=s.string():s.skipType(f&7)}return a},function*(s,o,c,a={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${c}.topic`,value:s.string()}:s.skipType(f&7)}})),t);function r(s){return wt(s,e.codec())}e.encode=r;function n(s,o){return xt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(Er||(Er={}));var Sr;(function(e){let t;e.codec=()=>(t==null&&(t=St((s,o,c={})=>{if(c.lengthDelimited!==!1&&o.fork(),s.topic!=null&&(o.uint32(10),o.string(s.topic)),s.peers!=null&&s.peers.length>0)for(let a of s.peers)o.uint32(18),vr.codec().encode(a,o);s.backoff!=null&&(o.uint32(24),o.uint64(s.backoff)),c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={peers:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.topic=s.string();break}case 2:{if(c.limits?.peers!=null&&a.peers.length===c.limits.peers)throw new et('Decode error - repeated field "peers" had too many elements');a.peers.push(vr.codec().decode(s,s.uint32(),{limits:c.limits?.peers$}));break}case 3:{a.backoff=s.uint64();break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u={peers:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${c}.topic`,value:s.string()};break}case 2:{if(a.limits?.peers!=null&&u.peers===a.limits.peers)throw new et('Streaming decode error - repeated field "peers" had too many elements');for(let h of vr.codec().stream(s,s.uint32(),`${c}.peers[]`,{limits:a.limits?.peers$}))yield{...h,index:u.peers};u.peers++;break}case 3:{yield{field:`${c}.backoff`,value:s.uint64()};break}default:{s.skipType(l&7);break}}}})),t);function r(s){return wt(s,e.codec())}e.encode=r;function n(s,o){return xt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(Sr||(Sr={}));var vr;(function(e){let t;e.codec=()=>(t==null&&(t=St((s,o,c={})=>{c.lengthDelimited!==!1&&o.fork(),s.peerID!=null&&(o.uint32(10),o.bytes(s.peerID)),s.signedPeerRecord!=null&&(o.uint32(18),o.bytes(s.signedPeerRecord)),c.lengthDelimited!==!1&&o.ldelim()},(s,o,c={})=>{let a={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.peerID=s.bytes();break}case 2:{a.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,o,c,a={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.peerID`,value:s.bytes()};break}case 2:{yield{field:`${c}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return wt(s,e.codec())}e.encode=r;function n(s,o){return xt(s,e.codec(),o)}e.decode=n;function i(s,o){return Et(s,e.codec(),o)}e.stream=i})(vr||(vr={}));var cn=class extends Ee{peerId;shutDownController;inboundPb;outboundPb;constructor(t){super(),this.peerId=t,this.shutDownController=new AbortController}attachInboundStream(t,r){this.inboundPb=ni(t,r).pb(xe),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,r){this.outboundPb=ni(t,r).pb(xe)}write(t){this.outboundPb!=null&&this.outboundPb.write(t,{signal:this.shutDownController.signal}).catch(r=>{this.outboundPb?.unwrap().unwrap().abort(r)})}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 ga(){return BigInt(`0x${V(Xr(8),"base16")}`)}var xa=(e,t)=>{let r=F(t.toString(16).padStart(16,"0"),"base16"),n=Kt(e),i=new Uint8Array(n.byteLength+r.length);return i.set(n,0),i.set(r,n.byteLength),i},wa=e=>ae.encode(e);var If=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=hr(Yt(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return Xs(js(r)).equals(t)}return!1},Ea=async e=>{if(e.from==null)throw new Q("RPC message was missing from");if(!await If(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=hr(Yt(e.from)),r=e.key??t.publicKey;if(r==null)throw new Q("RPC message was missing public key");return{type:"signed",from:t,topic:e.topic??"",sequenceNumber:Lf(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?js(r):r}},Ar=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:Bf(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Kt(e.key):void 0}:{data:e.data,topic:e.topic},Bf=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},Lf=e=>BigInt(`0x${V(e,"base16")}`);var Sa=F("libp2p-pubsub:");async function va(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:da(e)},i=oe([Sa,r(Ar(n)).subarray()]);return n.signature=await e.sign(i),n.key=e.publicKey,n}async function Aa(e,t){if(e.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(e.signature==null)throw new Error("Message must contain a signature to be verified");if(e.from==null)throw new Error("Message must contain a from property to be verified");let r=oe([Sa,t({...Ar(e),signature:void 0,key:void 0}).subarray()]);return Df(e).verify(r,e.signature)}function Df(e){if(e.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(e.from==null)throw new Error("Could not get the public key from the originator id");if(e.key!=null)return e.key;if(e.from.publicKey!=null)return e.from.publicKey;throw new Error("Could not get the public key from the originator id")}var un=class extends Ee{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;constructor(t,r){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocol=r.protocol??ai,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new dr,this.globalSignaturePolicy=r.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=r.canRelayMessage??!0,this.emitSelf=r.emitSelf??!1,this.topicValidators=new Map,this.queue=new yr({concurrency:r.messageProcessingConcurrency??10}),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.seenCache=new an({validityMs:r?.seenTTL??3e4}),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[qe]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[li]=["@libp2p/pubsub"];[hi]=["@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 r of this.peers.values())r.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t,r){this.addPeer(r.remotePeer,t).attachInboundStream(t)}async _onPeerConnected(t,r){if(this.log("connected %p",t),r.streams.find(s=>s.direction==="outbound"&&s.protocol===this.protocol)){this.log("outbound pubsub stream already present on connection from %p",t);return}let n=await r.newStream(this.protocol);this.addPeer(t,n).attachOutboundStream(n),this.send(t,{subscriptions:Array.from(this.subscriptions).map(s=>s.toString()),subscribe:!0})}_onPeerDisconnected(t,r){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,r){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let i=new cn(t);return this.peers.set(t,i),i.addEventListener("message",s=>{let o=s.detail,c=[];for(let a of o.messages??[]){if(a.from==null||a.data==null||a.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}c.push({from:a.from,data:a.data,topic:a.topic,sequenceNumber:a.sequenceNumber??void 0,signature:a.signature??void 0,key:a.key??void 0})}this.processRpc(i,{subscriptions:(o.subscriptions??[]).map(a=>({subscribe:!!a.subscribe,topic:a.topic??""})),messages:c}).catch(a=>{this.log(a)})}),i.addEventListener("close",()=>this._removePeer(t),{once:!0}),i}_removePeer(t){let r=this.peers.get(t);if(r!=null){r.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t)}}async processRpc(t,r){this.log("rpc from %p",t.peerId);let{subscriptions:n,messages:i}=r;return n!=null&&n.length>0&&(this.log("subscription update from %p",t.peerId),n.forEach(s=>{this.processRpcSubOpt(t.peerId,s)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:t.peerId,subscriptions:n.map(({topic:s,subscribe:o})=>({topic:`${s??""}`,subscribe:!!o}))}}))),i!=null&&i.length>0&&(this.log("messages from %p",t.peerId),this.queue.addAll(i.map(s=>async()=>{if(s.topic==null||!this.subscriptions.has(s.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let o=await Ea(s);await this.processMessage(t.peerId,o)}catch(o){this.log.error("failed to queue messages from %p - %e",t.peerId,o)}})).catch(s=>{this.log(s)})),!0}processRpcSubOpt(t,r){let n=r.topic;if(n==null)return;let i=this.topics.get(n);i==null&&(i=new pr,this.topics.set(n,i)),r.subscribe===!0?i.add(t):i.delete(t)}async processMessage(t,r){if(this.components.peerId.equals(t)&&!this.emitSelf)return;let n=await this.getMsgId(r),i=V(n,"base64");if(!this.seenCache.has(i)){this.seenCache.put(i,!0);try{await this.validate(t,r)}catch(s){this.log("Message is invalid, dropping it. %O",s);return}this.subscriptions.has(r.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:r})),await this.publishMessage(t,r)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new Q("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new Q("Need key when signature policy is StrictSign but it was missing");return xa(t.key,t.sequenceNumber);case"StrictNoSign":return wa(t.data);default:throw new Q("Cannot get message id: unhandled signature policy")}}encodeMessage(t){return xe.Message.encode(t)}send(t,r){let{messages:n,subscriptions:i,subscribe:s}=r;this.sendRpc(t,{subscriptions:(i??[]).map(o=>({topic:o,subscribe:!!s})),messages:(n??[]).map(Ar)})}sendRpc(t,r){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(r)}async validate(t,r){switch(this.globalSignaturePolicy){case"StrictNoSign":if(r.type!=="unsigned")throw new Q('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new Q("StrictNoSigning: signature should not be present");if(r.key!=null)throw new Q("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new Q("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new Q("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new Q("StrictSigning: Signing required and no sequenceNumber was present");if(!await Aa(r,this.encodeMessage.bind(this)))throw new Q("StrictSigning: Invalid message signature");break;default:throw new Q("Cannot validate message: unhandled signature policy")}let i=this.topicValidators.get(r.topic);if(i!=null){let s=await i(t,r);if(s===Me.Reject||s===Me.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return va(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new Q("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Dr("not started yet");if(t==null)throw new $("Topic is required");let r=this.topics.get(t.toString());return r==null?[]:Array.from(r.values())}async publish(t,r){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:r??new Uint8Array(0),sequenceNumber:ga()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let i=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:i})));let o=await this.publishMessage(this.components.peerId,i);return s&&(o.recipients=[...o.recipients,this.components.peerId]),o}async publishMessage(t,r){let n=this.getSubscribers(r.topic),i=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:i}):(n.forEach(s=>{if(this.components.peerId.equals(s)){this.log("not sending message on topic %s to myself",r.topic);return}if(s.equals(t)){this.log("not sending message on topic %s to sender %p",r.topic,s);return}this.log("publish msgs on topics %s %p",r.topic,s),i.push(s),this.send(s,{messages:[r]})}),{recipients:i})}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 r of this.peers.keys())this.send(r,{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 r of this.peers.keys())this.send(r,{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 ai="/floodsub/1.0.0",_f="StrictSign",Tf="StrictNoSign",Me;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(Me||(Me={}));function kf(e){return!!e?.[qe]}function Cf(e={}){return t=>new un(t,e)}return Ca(Rf);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/utils.js: