@libp2p/floodsub 11.0.14 → 11.0.15-2a3e54738

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 aa=Object.create;var br=Object.defineProperty;var ca=Object.getOwnPropertyDescriptor;var ua=Object.getOwnPropertyNames;var fa=Object.getPrototypeOf,la=Object.prototype.hasOwnProperty;var ha=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),dt=(r,t)=>{for(var e in t)br(r,e,{get:t[e],enumerable:!0})},Qs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ua(t))!la.call(r,s)&&s!==e&&br(r,s,{get:()=>t[s],enumerable:!(n=ca(t,s))||n.enumerable});return r};var da=(r,t,e)=>(e=r!=null?aa(fa(r)):{},Qs(t||!r||!r.__esModule?br(e,"default",{value:r,enumerable:!0}):e,r)),pa=r=>Qs(br({},"__esModule",{value:!0}),r);var Qo=ha((pm,Gs)=>{"use strict";var Qu=Object.prototype.hasOwnProperty,ht="~";function lr(){}Object.create&&(lr.prototype=Object.create(null),new lr().__proto__||(ht=!1));function tf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Jo(r,t,e,n,s){if(typeof e!="function")throw new TypeError("The listener must be a function");var i=new tf(e,n||r,s),o=ht?ht+t:t;return r._events[o]?r._events[o].fn?r._events[o]=[r._events[o],i]:r._events[o].push(i):(r._events[o]=i,r._eventsCount++),r}function $r(r,t){--r._eventsCount===0?r._events=new lr:delete r._events[t]}function ft(){this._events=new lr,this._eventsCount=0}ft.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Qu.call(e,n)&&t.push(ht?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};ft.prototype.listeners=function(t){var e=ht?ht+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,i=n.length,o=new Array(i);s<i;s++)o[s]=n[s].fn;return o};ft.prototype.listenerCount=function(t){var e=ht?ht+t:t,n=this._events[e];return n?n.fn?1:n.length:0};ft.prototype.emit=function(t,e,n,s,i,o){var a=ht?ht+t:t;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,f;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,s),!0;case 5:return c.fn.call(c.context,e,n,s,i),!0;case 6:return c.fn.call(c.context,e,n,s,i,o),!0}for(f=1,l=new Array(u-1);f<u;f++)l[f-1]=arguments[f];c.fn.apply(c.context,l)}else{var y=c.length,b;for(f=0;f<y;f++)switch(c[f].once&&this.removeListener(t,c[f].fn,void 0,!0),u){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,e);break;case 3:c[f].fn.call(c[f].context,e,n);break;case 4:c[f].fn.call(c[f].context,e,n,s);break;default:if(!l)for(b=1,l=new Array(u-1);b<u;b++)l[b-1]=arguments[b];c[f].fn.apply(c[f].context,l)}}return!0};ft.prototype.on=function(t,e,n){return Jo(this,t,e,n,!1)};ft.prototype.once=function(t,e,n){return Jo(this,t,e,n,!0)};ft.prototype.removeListener=function(t,e,n,s){var i=ht?ht+t:t;if(!this._events[i])return this;if(!e)return $r(this,i),this;var o=this._events[i];if(o.fn)o.fn===e&&(!s||o.once)&&(!n||o.context===n)&&$r(this,i);else{for(var a=0,c=[],u=o.length;a<u;a++)(o[a].fn!==e||s&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[i]=c.length===1?c[0]:c:$r(this,i)}return this};ft.prototype.removeAllListeners=function(t){var e;return t?(e=ht?ht+t:t,this._events[e]&&$r(this,e)):(this._events=new lr,this._eventsCount=0),this};ft.prototype.off=ft.prototype.removeListener;ft.prototype.addListener=ft.prototype.on;ft.prefixed=ht;ft.EventEmitter=ft;typeof Gs<"u"&&(Gs.exports=ft)});var ff={};dt(ff,{StrictNoSign:()=>af,StrictSign:()=>of,TopicValidatorResult:()=>Ke,floodsub:()=>uf,isPubSub:()=>cf,protocol:()=>Xs,pubSubSymbol:()=>Ue});var Ue=Symbol.for("@libp2p/pubsub");var z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ye=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var yr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var J=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var gr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var re=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var en=Symbol.for("@libp2p/peer-id");var ge=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let s=this.#t.get(t);s!=null&&(s=s.filter(({callback:i})=>i!==e),this.#t.set(t,s))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:s})=>!s),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var ti=Symbol.for("@libp2p/service-capabilities"),ei=Symbol.for("@libp2p/service-dependencies");var an={};dt(an,{base58btc:()=>G,base58flickr:()=>Ea});var Vf=new Uint8Array(0);function ri(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function kt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ni(r){return new TextEncoder().encode(r)}function si(r){return new TextDecoder().decode(r)}function ma(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var I=0,S=0,g=0,A=d.length;g!==A&&d[g]===0;)g++,I++;for(var w=(A-g)*l+1>>>0,B=new Uint8Array(w);g!==A;){for(var C=d[g],U=0,M=w-1;(C!==0||U<S)&&M!==-1;M--,U++)C+=256*B[M]>>>0,B[M]=C%a>>>0,C=C/a>>>0;if(C!==0)throw new Error("Non-zero carry");S=U,g++}for(var E=w-S;E!==w&&B[E]===0;)E++;for(var x=c.repeat(I);E<w;++E)x+=r.charAt(B[E]);return x}function y(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var I=0;if(d[I]!==" "){for(var S=0,g=0;d[I]===c;)S++,I++;for(var A=(d.length-I)*u+1>>>0,w=new Uint8Array(A);d[I];){var B=e[d.charCodeAt(I)];if(B===255)return;for(var C=0,U=A-1;(B!==0||C<g)&&U!==-1;U--,C++)B+=a*w[U]>>>0,w[U]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");g=C,I++}if(d[I]!==" "){for(var M=A-g;M!==A&&w[M]===0;)M++;for(var E=new Uint8Array(S+(A-M)),x=S;M!==A;)E[x++]=w[M++];return E}}}function b(d){var I=y(d);if(I)return I;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:y,decode:b}}var ba=ma,ya=ba,oi=ya;var rn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},nn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let s=e.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ai(this,t)}},sn=class{decoders;constructor(t){this.decoders=t}or(t){return ai(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ai(r,t){return new sn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var on=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new rn(t,e,n),this.decoder=new nn(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function we({name:r,prefix:t,encode:e,decode:n}){return new on(r,t,e,n)}function zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=oi(e,r);return we({prefix:t,name:r,encode:n,decode:i=>kt(s(i))})}function ga(r,t,e,n){let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),o=0,a=0,c=0;for(let u=0;u<s;++u){let l=t[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,o+=e,o>=8&&(o-=8,i[c++]=255&a>>o)}if(o>=e||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function wa(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>e;)o-=e,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<e-o]),n)for(;(i.length*e&7)!==0;)i+="=";return i}function xa(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function W({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let s=xa(n);return we({prefix:t,name:r,encode(i){return wa(i,n,e)},decode(i){return ga(i,s,e,r)}})}var G=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ea=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var cn={};dt(cn,{base32:()=>xe,base32hex:()=>Ia,base32hexpad:()=>La,base32hexpadupper:()=>_a,base32hexupper:()=>Ba,base32pad:()=>Sa,base32padupper:()=>Aa,base32upper:()=>va,base32z:()=>Da});var xe=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),va=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Sa=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Aa=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ia=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ba=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),La=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),_a=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Da=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var un={};dt(un,{base36:()=>Me,base36upper:()=>Ta});var Me=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ta=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ra=fi,ci=128,ka=127,Ca=~ka,Pa=Math.pow(2,31);function fi(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Pa;)t[e++]=r&255|ci,r/=128;for(;r&Ca;)t[e++]=r&255|ci,r>>>=7;return t[e]=r|0,fi.bytes=e-n+1,t}var Na=fn,Ka=128,ui=127;function fn(r,n){var e=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw fn.bytes=0,new RangeError("Could not decode varint");o=r[i++],e+=s<28?(o&ui)<<s:(o&ui)*Math.pow(2,s),s+=7}while(o>=Ka);return fn.bytes=i-n,e}var Ua=Math.pow(2,7),Ma=Math.pow(2,14),Oa=Math.pow(2,21),qa=Math.pow(2,28),Va=Math.pow(2,35),Ha=Math.pow(2,42),Fa=Math.pow(2,49),za=Math.pow(2,56),$a=Math.pow(2,63),Za=function(r){return r<Ua?1:r<Ma?2:r<Oa?3:r<qa?4:r<Va?5:r<Ha?6:r<Fa?7:r<za?8:r<$a?9:10},Ga={encode:Ra,decode:Na,encodingLength:Za},Ya=Ga,Oe=Ya;function qe(r,t=0){return[Oe.decode(r,t),Oe.decode.bytes]}function Ee(r,t,e=0){return Oe.encode(r,t,e),t}function ve(r){return Oe.encodingLength(r)}function _t(r,t){let e=t.byteLength,n=ve(r),s=n+ve(e),i=new Uint8Array(s+e);return Ee(r,i,0),Ee(e,i,n),i.set(t,s),new Se(r,e,t,i)}function $t(r){let t=kt(r),[e,n]=qe(t),[s,i]=qe(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new Se(e,s,o,t)}function li(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ri(r.bytes,e.bytes)}}var Se=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function hi(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Xa(e,ln(r),t??G.encoder);default:return Wa(e,ln(r),t??xe.encoder)}}var di=new WeakMap;function ln(r){let t=di.get(r);if(t==null){let e=new Map;return di.set(r,e),e}return t}var at=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Ve)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ja)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=_t(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&li(t.multihash,n.multihash)}toString(t){return hi(this,t)}toJSON(){return{"/":hi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:s,multihash:i,bytes:o}=e;return new r(n,s,i,o??pi(n,s,i.bytes))}else if(e[Qa]===!0){let{version:n,multihash:s,code:i}=e,o=$t(s);return r.create(n,i,o)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Ve)throw new Error(`Version 0 CID must use dag-pb (code: ${Ve}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=pi(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ve,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,s=kt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=s.subarray(e.multihashSize-e.digestSize),o=new Se(e.multihashCode,e.digestSize,i,s);return[e.version===0?r.createV0(o):r.createV1(e.codec,o),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,y]=qe(t.subarray(e));return e+=y,f},s=n(),i=Ve;if(s===18?(s=0,e=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=e,a=n(),c=n(),u=e+c,l=u-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,s]=ja(t,e),i=r.decode(s);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ln(i).set(n,t),i}};function ja(r,t){switch(r[0]){case"Q":{let e=t??G;return[G.prefix,e.decode(`${G.prefix}${r}`)]}case G.prefix:{let e=t??G;return[G.prefix,e.decode(r)]}case xe.prefix:{let e=t??xe;return[xe.prefix,e.decode(r)]}case Me.prefix:{let e=t??Me;return[Me.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Xa(r,t,e){let{prefix:n}=e;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return s}function Wa(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let i=e.encode(r);return t.set(n,i),i}else return s}var Ve=112,Ja=18;function pi(r,t,e){let n=ve(r),s=n+ve(t),i=new Uint8Array(s+e.byteLength);return Ee(r,i,0),Ee(t,i,n),i.set(e,s),i}var Qa=Symbol.for("@ipld/js-cid/CID");var hn={};dt(hn,{identity:()=>At});var mi=0,tc="identity",bi=kt;function ec(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return _t(mi,bi(r))}var At={code:mi,name:tc,encode:bi,digest:ec};function pt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ct(r=0){return new Uint8Array(r)}function mt(r=0){return new Uint8Array(r)}function ne(r,t){t==null&&(t=r.reduce((s,i)=>s+i.length,0));let e=mt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}var gi=Symbol.for("@achingbrain/uint8arraylist");function yi(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function xr(r){return!!r?.[gi]}var et=class r{bufs;length;[gi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(xr(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(xr(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=yi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=yi(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(xr(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:s}=this._subList(t,e);return ne(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:ne(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),i=new r;return i.length=s,i.bufs=[...n],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(o);break}let f=t-a;n.push(o.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(l){if(e===c){n.push(o);break}n.push(o.subarray(0,e-a));break}n.push(o)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!xr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let f=0;f<i;f++)o[f]=-1;for(let f=0;f<s;f++)o[n[f]]=f;let a=o,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=c;f+=l){l=0;for(let y=u;y>=0;y--){let b=this.get(f+y);if(n[y]!==b){l=Math.max(1,y-a[b]);break}}if(l===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let s=Ct(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let s=Ct(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let s=Ct(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let s=Ct(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let s=Ct(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let s=Ct(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let s=Ct(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let s=Ct(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!pt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((s,i)=>s+i.byteLength,0)),n.length=e,n}};var dn={};dt(dn,{base10:()=>rc});var rc=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var pn={};dt(pn,{base16:()=>nc,base16upper:()=>sc});var nc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),sc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var mn={};dt(mn,{base2:()=>ic});var ic=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var bn={};dt(bn,{base256emoji:()=>fc});var wi=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),oc=wi.reduce((r,t,e)=>(r[e]=t,r),[]),ac=wi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function cc(r){return r.reduce((t,e)=>(t+=oc[e],t),"")}function uc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=ac[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var fc=we({prefix:"\u{1F680}",name:"base256emoji",encode:cc,decode:uc});var yn={};dt(yn,{base64:()=>lc,base64pad:()=>hc,base64url:()=>dc,base64urlpad:()=>pc});var lc=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),hc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),dc=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pc=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var gn={};dt(gn,{base8:()=>mc});var mc=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wn={};dt(wn,{identity:()=>bc});var bc=we({prefix:"\0",name:"identity",encode:r=>si(r),decode:r=>ni(r)});var Al=new TextEncoder,Il=new TextDecoder;var vn={};dt(vn,{sha256:()=>se,sha512:()=>xc});var wc=20;function En({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:s}){return new xn(r,t,e,n,s)}var xn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,s,i){this.name=t,this.code=e,this.encode=n,this.minDigestLength=s??wc,this.maxDigestLength=i}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?xi(n,this.code,e?.truncate):n.then(s=>xi(s,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function xi(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return _t(t,r)}function vi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var se=En({name:"sha2-256",code:18,encode:vi("SHA-256")}),xc=En({name:"sha2-512",code:19,encode:vi("SHA-512")});var Sn={...wn,...mn,...gn,...dn,...pn,...cn,...un,...an,...yn,...bn},Ul={...vn,...hn};function Ai(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Si=Ai("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),An=Ai("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=mt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Ec={utf8:Si,"utf-8":Si,hex:Sn.base16,latin1:An,ascii:An,binary:An,...Sn},Er=Ec;function F(r,t="utf8"){let e=Er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function H(r,t="utf8"){let e=Er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var vc=parseInt("11111",2),In=parseInt("10000000",2),Sc=parseInt("01111111",2),Ii={0:He,1:He,2:Ac,3:Lc,4:_c,5:Bc,6:Ic,16:He,22:He,48:He};function Pt(r,t={offset:0}){let e=r[t.offset]&vc;if(t.offset++,Ii[e]!=null)return Ii[e](r,t);throw new Error("No decoder for tag "+e)}function Fe(r,t){let e=0;if((r[t.offset]&In)===In){let n=r[t.offset]&Sc,s="0x";t.offset++;for(let i=0;i<n;i++,t.offset++)s+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(s,16)}else e=r[t.offset],t.offset++;return e}function He(r,t){Fe(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Pt(r,t);if(n===null)break;e.push(n)}return e}function Ac(r,t){let e=Fe(r,t),n=t.offset,s=t.offset+e,i=[];for(let o=n;o<s;o++)o===n&&r[o]===0||i.push(r[o]);return t.offset+=e,Uint8Array.from(i)}function Ic(r,t){let e=Fe(r,t),n=t.offset+e,s=r[t.offset];t.offset++;let i=0,o=0;s<40?(i=0,o=s):s<80?(i=1,o=s-40):(i=2,o=s-80);let a=`${i}.${o}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let f=0;f<c.length;f++)l+=c[f]<<f*7;a+=`.${l}`,c=[]}}return a}function Bc(r,t){return t.offset++,null}function Lc(r,t){let e=Fe(r,t),n=r[t.offset];t.offset++;let s=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function _c(r,t){let e=Fe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Dc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new et;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Bn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Dc(r.byteLength);return new et(Uint8Array.from([t.byteLength|In]),t)}function bt(r){let t=new et,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new et(Uint8Array.from([2]),Bn(t),t)}function vr(r){let t=Uint8Array.from([0]),e=new et(t,r);return new et(Uint8Array.from([3]),Bn(e),e)}function Gt(r,t=48){let e=new et;for(let n of r)e.append(n);return new et(Uint8Array.from([t]),Bn(e),e)}async function Bi(r,t,e,n){let s=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,t,e.subarray());return n?.signal?.throwIfAborted(),i}var Tc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Rc=Uint8Array.from([6,5,43,129,4,0,34]),kc=Uint8Array.from([6,5,43,129,4,0,35]),Cc={ext:!0,kty:"EC",crv:"P-256"},Pc={ext:!0,kty:"EC",crv:"P-384"},Nc={ext:!0,kty:"EC",crv:"P-521"},Ln=32,_n=48,Dn=66;function Tn(r){let t=Pt(r);return Li(t)}function Li(r){let t=r[1][1][0],e=1,n,s;if(t.byteLength===Ln*2+1)return n=H(t.subarray(e,e+Ln),"base64url"),s=H(t.subarray(e+Ln),"base64url"),new Ae({...Cc,key_ops:["verify"],x:n,y:s});if(t.byteLength===_n*2+1)return n=H(t.subarray(e,e+_n),"base64url"),s=H(t.subarray(e+_n),"base64url"),new Ae({...Pc,key_ops:["verify"],x:n,y:s});if(t.byteLength===Dn*2+1)return n=H(t.subarray(e,e+Dn),"base64url"),s=H(t.subarray(e+Dn),"base64url"),new Ae({...Nc,key_ops:["verify"],x:n,y:s});throw new z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function _i(r){return Gt([bt(Uint8Array.from([1])),Gt([Kc(r.crv)],160),Gt([vr(new et(Uint8Array.from([4]),F(r.x??"","base64url"),F(r.y??"","base64url")))],161)]).subarray()}function Kc(r){if(r==="P-256")return Tc;if(r==="P-384")return Rc;if(r==="P-521")return kc;throw new z(`Invalid curve ${r}`)}var Ae=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=_i(this.jwk)),this._raw}toMultihash(){return At.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}async verify(t,e,n){return Bi(this.jwk,e,t,n)}};function ie(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Dt(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function K(r,t,e=""){let n=ie(r),s=r?.length,i=t!==void 0;if(!n||i&&s!==t){let o=e&&`"${e}" `,a=i?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof r}`;throw new Error(o+"expected Uint8Array"+a+", got "+c)}return r}function Sr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Dt(r.outputLen),Dt(r.blockLen)}function Ie(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Ti(r,t){K(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function Ut(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Ar(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function It(r,t){return r<<32-t|r>>>t}var Ri=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Uc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Mt(r){if(K(r),Ri)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Uc[r[e]];return t}var Kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Di(r){if(r>=Kt._0&&r<=Kt._9)return r-Kt._0;if(r>=Kt.A&&r<=Kt.F)return r-(Kt.A-10);if(r>=Kt.a&&r<=Kt.f)return r-(Kt.a-10)}function Ot(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Ri)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let s=0,i=0;s<e;s++,i+=2){let o=Di(r.charCodeAt(i)),a=Di(r.charCodeAt(i+1));if(o===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function yt(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];K(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let i=r[n];e.set(i,s),s+=i.length}return e}function Rn(r,t={}){let e=(s,i)=>r(i).update(s).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=s=>r(s),Object.assign(e,t),Object.freeze(e)}function Yt(r=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(r))}var kn=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function ki(r,t,e){return r&t^~r&e}function Ci(r,t,e){return r&t^r&e^t&e}var ze=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,s){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Ar(this.buffer)}update(t){Ie(this),K(t);let{view:e,buffer:n,blockLen:s}=this,i=t.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=Ar(t);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ie(this),Ti(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;e[o++]=128,Ut(this.buffer.subarray(o)),this.padOffset>s-o&&(this.process(n,0),o=0);for(let f=o;f<s;f++)e[f]=0;n.setBigUint64(s-8,BigInt(this.length*8),i),this.process(n,0);let a=Ar(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return t.destroyed=o,t.finished=i,t.length=s,t.pos=a,s%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},qt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var it=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ir=BigInt(4294967295),Pi=BigInt(32);function Mc(r,t=!1){return t?{h:Number(r&Ir),l:Number(r>>Pi&Ir)}:{h:Number(r>>Pi&Ir)|0,l:Number(r&Ir)|0}}function Ni(r,t=!1){let e=r.length,n=new Uint32Array(e),s=new Uint32Array(e);for(let i=0;i<e;i++){let{h:o,l:a}=Mc(r[i],t);[n[i],s[i]]=[o,a]}return[n,s]}var Cn=(r,t,e)=>r>>>e,Pn=(r,t,e)=>r<<32-e|t>>>e,oe=(r,t,e)=>r>>>e|t<<32-e,ae=(r,t,e)=>r<<32-e|t>>>e,$e=(r,t,e)=>r<<64-e|t>>>e-32,Ze=(r,t,e)=>r>>>e-32|t<<64-e;function Tt(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var Ki=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ui=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Mi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Oi=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,qi=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),Vi=(r,t,e,n,s,i)=>t+e+n+s+i+(r/2**32|0)|0;var qc=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),jt=new Uint32Array(64),Nn=class extends ze{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[t,e,n,s,i,o,a,c]}set(t,e,n,s,i,o,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)jt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let y=jt[f-15],b=jt[f-2],d=It(y,7)^It(y,18)^y>>>3,I=It(b,17)^It(b,19)^b>>>10;jt[f]=I+jt[f-7]+d+jt[f-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let y=It(a,6)^It(a,11)^It(a,25),b=l+y+ki(a,c,u)+qc[f]+jt[f]|0,I=(It(n,2)^It(n,13)^It(n,22))+Ci(n,s,i)|0;l=u,u=c,c=a,a=o+b|0,o=i,i=s,s=n,n=b+I|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,s,i,o,a,c,u,l)}roundClean(){Ut(jt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}},Kn=class extends Nn{A=qt[0]|0;B=qt[1]|0;C=qt[2]|0;D=qt[3]|0;E=qt[4]|0;F=qt[5]|0;G=qt[6]|0;H=qt[7]|0;constructor(){super(32)}};var Hi=Ni(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Vc=Hi[0],Hc=Hi[1],Xt=new Uint32Array(80),Wt=new Uint32Array(80),Un=class extends ze{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:y,Gh:b,Gl:d,Hh:I,Hl:S}=this;return[t,e,n,s,i,o,a,c,u,l,f,y,b,d,I,S]}set(t,e,n,s,i,o,a,c,u,l,f,y,b,d,I,S){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=y|0,this.Gh=b|0,this.Gl=d|0,this.Hh=I|0,this.Hl=S|0}process(t,e){for(let w=0;w<16;w++,e+=4)Xt[w]=t.getUint32(e),Wt[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let B=Xt[w-15]|0,C=Wt[w-15]|0,U=oe(B,C,1)^oe(B,C,8)^Cn(B,C,7),M=ae(B,C,1)^ae(B,C,8)^Pn(B,C,7),E=Xt[w-2]|0,x=Wt[w-2]|0,P=oe(E,x,19)^$e(E,x,61)^Cn(E,x,6),O=ae(E,x,19)^Ze(E,x,61)^Pn(E,x,6),T=Mi(M,O,Wt[w-7],Wt[w-16]),p=Oi(T,U,P,Xt[w-7],Xt[w-16]);Xt[w]=p|0,Wt[w]=T|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:y,Fh:b,Fl:d,Gh:I,Gl:S,Hh:g,Hl:A}=this;for(let w=0;w<80;w++){let B=oe(f,y,14)^oe(f,y,18)^$e(f,y,41),C=ae(f,y,14)^ae(f,y,18)^Ze(f,y,41),U=f&b^~f&I,M=y&d^~y&S,E=qi(A,C,M,Hc[w],Wt[w]),x=Vi(E,g,B,U,Vc[w],Xt[w]),P=E|0,O=oe(n,s,28)^$e(n,s,34)^$e(n,s,39),T=ae(n,s,28)^Ze(n,s,34)^Ze(n,s,39),p=n&i^n&a^i&a,m=s&o^s&c^o&c;g=I|0,A=S|0,I=b|0,S=d|0,b=f|0,d=y|0,{h:f,l:y}=Tt(u|0,l|0,x|0,P|0),u=a|0,l=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let h=Ki(P,T,m);n=Ui(h,x,O,p),s=h|0}({h:n,l:s}=Tt(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=Tt(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=Tt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Tt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:y}=Tt(this.Eh|0,this.El|0,f|0,y|0),{h:b,l:d}=Tt(this.Fh|0,this.Fl|0,b|0,d|0),{h:I,l:S}=Tt(this.Gh|0,this.Gl|0,I|0,S|0),{h:g,l:A}=Tt(this.Hh|0,this.Hl|0,g|0,A|0),this.set(n,s,i,o,a,c,u,l,f,y,b,d,I,S,g,A)}roundClean(){Ut(Xt,Wt)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Mn=class extends Un{Ah=it[0]|0;Al=it[1]|0;Bh=it[2]|0;Bl=it[3]|0;Ch=it[4]|0;Cl=it[5]|0;Dh=it[6]|0;Dl=it[7]|0;Eh=it[8]|0;El=it[9]|0;Fh=it[10]|0;Fl=it[11]|0;Gh=it[12]|0;Gl=it[13]|0;Hh=it[14]|0;Hl=it[15]|0;constructor(){super(64)}};var Be=Rn(()=>new Kn,kn(1));var Fi=Rn(()=>new Mn,kn(3));var qn=BigInt(0),On=BigInt(1);function Vt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function zi(r){if(typeof r=="bigint"){if(!Br(r))throw new Error("positive bigint expected, got "+r)}else Dt(r);return r}function Ge(r){let t=zi(r).toString(16);return t.length&1?"0"+t:t}function $i(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?qn:BigInt("0x"+r)}function Le(r){return $i(Mt(r))}function ce(r){return $i(Mt(_r(K(r)).reverse()))}function Lr(r,t){Dt(t),r=zi(r);let e=Ot(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function Vn(r,t){return Lr(r,t).reverse()}function _r(r){return Uint8Array.from(r)}var Br=r=>typeof r=="bigint"&&qn<=r;function Fc(r,t,e){return Br(r)&&Br(t)&&Br(e)&&t<=r&&r<e}function Ye(r,t,e,n){if(!Fc(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Hn(r){let t;for(t=0;r>qn;r>>=On,t+=1);return t}var je=r=>(On<<BigInt(r))-On;function Zi(r,t,e){if(Dt(r,"hashLen"),Dt(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=S=>new Uint8Array(S),s=Uint8Array.of(),i=Uint8Array.of(0),o=Uint8Array.of(1),a=1e3,c=n(r),u=n(r),l=0,f=()=>{c.fill(1),u.fill(0),l=0},y=(...S)=>e(u,yt(c,...S)),b=(S=s)=>{u=y(i,S),c=y(),S.length!==0&&(u=y(o,S),c=y())},d=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let S=0,g=[];for(;S<t;){c=y();let A=c.slice();g.push(A),S+=c.length}return yt(...g)};return(S,g)=>{f(),b(S);let A;for(;!(A=g(d()));)b();return f(),A}}function Jt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(i,o,a){let c=r[i];if(a&&c===void 0)return;let u=typeof c;if(u!==o||c===null)throw new Error(`param "${i}" is invalid: expected ${o}, got ${u}`)}let s=(i,o)=>Object.entries(i).forEach(([a,c])=>n(a,c,o));s(t,!1),s(e,!0)}function _e(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let i=r(e,...n);return t.set(e,i),i}}var lt=BigInt(0),rt=BigInt(1),ue=BigInt(2),ji=BigInt(3),Xi=BigInt(4),Wi=BigInt(5),zc=BigInt(7),Ji=BigInt(8),$c=BigInt(9),Qi=BigInt(16);function Q(r,t){let e=r%t;return e>=lt?e:t+e}function Z(r,t,e){let n=r;for(;t-- >lt;)n*=n,n%=e;return n}function Gi(r,t){if(r===lt)throw new Error("invert: expected non-zero number");if(t<=lt)throw new Error("invert: expected positive modulus, got "+t);let e=Q(r,t),n=t,s=lt,i=rt,o=rt,a=lt;for(;e!==lt;){let u=n/e,l=n%e,f=s-o*u,y=i-a*u;n=e,e=l,s=o,i=a,o=f,a=y}if(n!==rt)throw new Error("invert: does not exist");return Q(s,t)}function zn(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function to(r,t){let e=(r.ORDER+rt)/Xi,n=r.pow(t,e);return zn(r,n,t),n}function Zc(r,t){let e=(r.ORDER-Wi)/Ji,n=r.mul(t,ue),s=r.pow(n,e),i=r.mul(t,s),o=r.mul(r.mul(i,ue),s),a=r.mul(i,r.sub(o,r.ONE));return zn(r,a,t),a}function Gc(r){let t=De(r),e=eo(r),n=e(t,t.neg(t.ONE)),s=e(t,n),i=e(t,t.neg(n)),o=(r+zc)/Qi;return(a,c)=>{let u=a.pow(c,o),l=a.mul(u,n),f=a.mul(u,s),y=a.mul(u,i),b=a.eql(a.sqr(l),c),d=a.eql(a.sqr(f),c);u=a.cmov(u,l,b),l=a.cmov(y,f,d);let I=a.eql(a.sqr(l),c),S=a.cmov(u,l,I);return zn(a,S,c),S}}function eo(r){if(r<ji)throw new Error("sqrt is not defined for small field");let t=r-rt,e=0;for(;t%ue===lt;)t/=ue,e++;let n=ue,s=De(r);for(;Yi(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return to;let i=s.pow(n,t),o=(t+rt)/ue;return function(c,u){if(c.is0(u))return u;if(Yi(c,u)!==1)throw new Error("Cannot find square root");let l=e,f=c.mul(c.ONE,i),y=c.pow(u,t),b=c.pow(u,o);for(;!c.eql(y,c.ONE);){if(c.is0(y))return c.ZERO;let d=1,I=c.sqr(y);for(;!c.eql(I,c.ONE);)if(d++,I=c.sqr(I),d===l)throw new Error("Cannot find square root");let S=rt<<BigInt(l-d-1),g=c.pow(f,S);l=d,f=c.sqr(g),y=c.mul(y,f),b=c.mul(b,g)}return b}}function Yc(r){return r%Xi===ji?to:r%Ji===Wi?Zc:r%Qi===$c?Gc(r):eo(r)}var ro=(r,t)=>(Q(r,t)&rt)===rt,jc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function $n(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=jc.reduce((n,s)=>(n[s]="function",n),t);return Jt(r,e),r}function Xc(r,t,e){if(e<lt)throw new Error("invalid exponent, negatives unsupported");if(e===lt)return r.ONE;if(e===rt)return t;let n=r.ONE,s=t;for(;e>lt;)e&rt&&(n=r.mul(n,s)),s=r.sqr(s),e>>=rt;return n}function Xe(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),s=t.reduce((o,a,c)=>r.is0(a)?o:(n[c]=o,r.mul(o,a)),r.ONE),i=r.inv(s);return t.reduceRight((o,a,c)=>r.is0(a)?o:(n[c]=r.mul(o,n[c]),r.mul(o,a)),i),n}function Yi(r,t){let e=(r.ORDER-rt)/ue,n=r.pow(t,e),s=r.eql(n,r.ONE),i=r.eql(n,r.ZERO),o=r.eql(n,r.neg(r.ONE));if(!s&&!i&&!o)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Wc(r,t){t!==void 0&&Dt(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var Fn=class{ORDER;BITS;BYTES;isLE;ZERO=lt;ONE=rt;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=lt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:s,nByteLength:i}=Wc(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return Q(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return lt<=t&&t<this.ORDER}is0(t){return t===lt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&rt)===rt}neg(t){return Q(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Q(t*t,this.ORDER)}add(t,e){return Q(t+e,this.ORDER)}sub(t,e){return Q(t-e,this.ORDER)}mul(t,e){return Q(t*e,this.ORDER)}pow(t,e){return Xc(this,t,e)}div(t,e){return Q(t*Gi(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return Gi(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Yc(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Vn(t,this.BYTES):Lr(t,this.BYTES)}fromBytes(t,e=!1){K(t);let{_lengths:n,BYTES:s,isLE:i,ORDER:o,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(s);u.set(t,i?0:u.length-t.length),t=u}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=i?ce(t):Le(t);if(a&&(c=Q(c,o)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Xe(this,t)}cmov(t,e,n){return n?e:t}};function De(r,t={}){return new Fn(r,t)}function no(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function Zn(r){let t=no(r);return t+Math.ceil(t/2)}function Gn(r,t,e=!1){K(r);let n=r.length,s=no(t),i=Zn(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=e?ce(r):Le(r),a=Q(o,t-rt)+rt;return e?Vn(a,s):Lr(a,s)}var Te=BigInt(0),fe=BigInt(1);function We(r,t){let e=t.negate();return r?e:t}function le(r,t){let e=Xe(r.Fp,t.map(n=>n.Z));return t.map((n,s)=>r.fromAffine(n.toAffine(e[s])))}function ao(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Yn(r,t){ao(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),s=2**r,i=je(r),o=BigInt(r);return{windows:e,windowSize:n,mask:i,maxNumber:s,shiftBy:o}}function so(r,t,e){let{windowSize:n,mask:s,maxNumber:i,shiftBy:o}=e,a=Number(r&s),c=r>>o;a>n&&(a-=i,c+=fe);let u=t*n,l=u+Math.abs(a)-1,f=a===0,y=a<0,b=t%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:y,isNegF:b,offsetF:u}}var jn=new WeakMap,co=new WeakMap;function Xn(r){return co.get(r)||1}function io(r){if(r!==Te)throw new Error("invalid wNAF")}var Re=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let s=t;for(;e>Te;)e&fe&&(n=n.add(s)),s=s.double(),e>>=fe;return n}precomputeWindow(t,e){let{windows:n,windowSize:s}=Yn(e,this.bits),i=[],o=t,a=o;for(let c=0;c<n;c++){a=o,i.push(a);for(let u=1;u<s;u++)a=a.add(o),i.push(a);o=a.double()}return i}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,i=this.BASE,o=Yn(t,this.bits);for(let a=0;a<o.windows;a++){let{nextN:c,offset:u,isZero:l,isNeg:f,isNegF:y,offsetF:b}=so(n,a,o);n=c,l?i=i.add(We(y,e[b])):s=s.add(We(f,e[u]))}return io(n),{p:s,f:i}}wNAFUnsafe(t,e,n,s=this.ZERO){let i=Yn(t,this.bits);for(let o=0;o<i.windows&&n!==Te;o++){let{nextN:a,offset:c,isZero:u,isNeg:l}=so(n,o,i);if(n=a,!u){let f=e[c];s=s.add(l?f.negate():f)}}return io(n),s}getPrecomputes(t,e,n){let s=jn.get(e);return s||(s=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(s=n(s)),jn.set(e,s))),s}cached(t,e,n){let s=Xn(t);return this.wNAF(s,this.getPrecomputes(s,t,n),e)}unsafe(t,e,n,s){let i=Xn(t);return i===1?this._unsafeLadder(t,e,s):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),e,s)}createCache(t,e){ao(e,this.bits),co.set(t,e),jn.delete(t)}hasCache(t){return Xn(t)!==1}};function uo(r,t,e,n){let s=t,i=r.ZERO,o=r.ZERO;for(;e>Te||n>Te;)e&fe&&(i=i.add(s)),n&fe&&(o=o.add(s)),s=s.double(),e>>=fe,n>>=fe;return{p1:i,p2:o}}function oo(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return $n(t),t}else return De(r,{isLE:e})}function Dr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Te))throw new Error(`CURVE.${c} must be positive bigint`)}let s=oo(t.p,e.Fp,n),i=oo(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:i}}function Tr(r,t){return function(n){let s=r(n);return{secretKey:s,publicKey:t(s)}}}var Qt=BigInt(0),nt=BigInt(1),Wn=BigInt(2),Jc=BigInt(8);function Qc(r,t,e,n){let s=r.sqr(e),i=r.sqr(n),o=r.add(r.mul(t.a,s),i),a=r.add(r.ONE,r.mul(t.d,r.mul(s,i)));return r.eql(o,a)}function fo(r,t={}){let e=Dr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:s}=e,i=e.CURVE,{h:o}=i;Jt(t,{},{uvRatio:"function"});let a=Wn<<BigInt(s.BYTES*8)-nt,c=S=>n.create(S),u=t.uvRatio||((S,g)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,g))}}catch{return{isValid:!1,value:Qt}}});if(!Qc(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(S,g,A=!1){let w=A?nt:Qt;return Ye("coordinate "+S,g,w,a),g}function f(S){if(!(S instanceof d))throw new Error("EdwardsPoint expected")}let y=_e((S,g)=>{let{X:A,Y:w,Z:B}=S,C=S.is0();g==null&&(g=C?Jc:n.inv(B));let U=c(A*g),M=c(w*g),E=n.mul(B,g);if(C)return{x:Qt,y:nt};if(E!==nt)throw new Error("invZ was invalid");return{x:U,y:M}}),b=_e(S=>{let{a:g,d:A}=i;if(S.is0())throw new Error("bad point: ZERO");let{X:w,Y:B,Z:C,T:U}=S,M=c(w*w),E=c(B*B),x=c(C*C),P=c(x*x),O=c(M*g),T=c(x*c(O+E)),p=c(P+c(A*c(M*E)));if(T!==p)throw new Error("bad point: equation left != right (1)");let m=c(w*B),h=c(C*U);if(m!==h)throw new Error("bad point: equation left != right (2)");return!0});class d{static BASE=new d(i.Gx,i.Gy,nt,c(i.Gx*i.Gy));static ZERO=new d(Qt,nt,nt,Qt);static Fp=n;static Fn=s;X;Y;Z;T;constructor(g,A,w,B){this.X=l("x",g),this.Y=l("y",A),this.Z=l("z",w,!0),this.T=l("t",B),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof d)throw new Error("extended point not allowed");let{x:A,y:w}=g||{};return l("x",A),l("y",w),new d(A,w,nt,c(A*w))}static fromBytes(g,A=!1){let w=n.BYTES,{a:B,d:C}=i;g=_r(K(g,w,"point")),Vt(A,"zip215");let U=_r(g),M=g[w-1];U[w-1]=M&-129;let E=ce(U),x=A?a:n.ORDER;Ye("point.y",E,Qt,x);let P=c(E*E),O=c(P-nt),T=c(C*P-B),{isValid:p,value:m}=u(O,T);if(!p)throw new Error("bad point: invalid y coordinate");let h=(m&nt)===nt,v=(M&128)!==0;if(!A&&m===Qt&&v)throw new Error("bad point: x=0 and x_0=1");return v!==h&&(m=c(-m)),d.fromAffine({x:m,y:E})}static fromHex(g,A=!1){return d.fromBytes(Ot(g),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,A=!0){return I.createCache(this,g),A||this.multiply(Wn),this}assertValidity(){b(this)}equals(g){f(g);let{X:A,Y:w,Z:B}=this,{X:C,Y:U,Z:M}=g,E=c(A*M),x=c(C*B),P=c(w*M),O=c(U*B);return E===x&&P===O}is0(){return this.equals(d.ZERO)}negate(){return new d(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:g}=i,{X:A,Y:w,Z:B}=this,C=c(A*A),U=c(w*w),M=c(Wn*c(B*B)),E=c(g*C),x=A+w,P=c(c(x*x)-C-U),O=E+U,T=O-M,p=E-U,m=c(P*T),h=c(O*p),v=c(P*p),L=c(T*O);return new d(m,h,L,v)}add(g){f(g);let{a:A,d:w}=i,{X:B,Y:C,Z:U,T:M}=this,{X:E,Y:x,Z:P,T:O}=g,T=c(B*E),p=c(C*x),m=c(M*w*O),h=c(U*P),v=c((B+C)*(E+x)-T-p),L=h-m,D=h+m,R=c(p-A*T),_=c(v*L),k=c(D*R),N=c(v*R),Y=c(L*D);return new d(_,k,Y,N)}subtract(g){return this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=I.cached(this,g,B=>le(d,B));return le(d,[A,w])[0]}multiplyUnsafe(g,A=d.ZERO){if(!s.isValid(g))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return g===Qt?d.ZERO:this.is0()||g===nt?this:I.unsafe(this,g,w=>le(d,w),A)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return I.unsafe(this,i.n).is0()}toAffine(g){return y(this,g)}clearCofactor(){return o===nt?this:this.multiplyUnsafe(o)}toBytes(){let{x:g,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=g&nt?128:0,w}toHex(){return Mt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let I=new Re(d,s.BITS);return d.BASE.precompute(8),d}function lo(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');Jt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:s,Fp:i,Fn:o}=r,a=e.randomBytes||Yt,c=e.adjustScalarBytes||(E=>E),u=e.domain||((E,x,P)=>{if(Vt(P,"phflag"),x.length||P)throw new Error("Contexts/pre-hash are not supported");return E});function l(E){return o.create(ce(E))}function f(E){let x=w.secretKey;K(E,w.secretKey,"secretKey");let P=K(t(E),2*x,"hashedSecretKey"),O=c(P.slice(0,x)),T=P.slice(x,2*x),p=l(O);return{head:O,prefix:T,scalar:p}}function y(E){let{head:x,prefix:P,scalar:O}=f(E),T=s.multiply(O),p=T.toBytes();return{head:x,prefix:P,scalar:O,point:T,pointBytes:p}}function b(E){return y(E).pointBytes}function d(E=Uint8Array.of(),...x){let P=yt(...x);return l(t(u(P,K(E,void 0,"context"),!!n)))}function I(E,x,P={}){E=K(E,void 0,"message"),n&&(E=n(E));let{prefix:O,scalar:T,pointBytes:p}=y(x),m=d(P.context,O,E),h=s.multiply(m).toBytes(),v=d(P.context,h,p,E),L=o.create(m+v*T);if(!o.isValid(L))throw new Error("sign failed: invalid s");let D=yt(h,o.toBytes(L));return K(D,w.signature,"result")}let S={zip215:!0};function g(E,x,P,O=S){let{context:T,zip215:p}=O,m=w.signature;E=K(E,m,"signature"),x=K(x,void 0,"message"),P=K(P,w.publicKey,"publicKey"),p!==void 0&&Vt(p,"zip215"),n&&(x=n(x));let h=m/2,v=E.subarray(0,h),L=ce(E.subarray(h,m)),D,R,_;try{D=r.fromBytes(P,p),R=r.fromBytes(v,p),_=s.multiplyUnsafe(L)}catch{return!1}if(!p&&D.isSmallOrder())return!1;let k=d(T,R.toBytes(),D.toBytes(),x);return R.add(D.multiplyUnsafe(k)).subtract(_).clearCofactor().is0()}let A=i.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function B(E=a(w.seed)){return K(E,w.seed,"seed")}function C(E){return ie(E)&&E.length===o.BYTES}function U(E,x){try{return!!r.fromBytes(E,x)}catch{return!1}}let M={getExtendedPublicKey:y,randomSecretKey:B,isValidSecretKey:C,isValidPublicKey:U,toMontgomery(E){let{y:x}=r.fromBytes(E),P=w.publicKey,O=P===32;if(!O&&P!==57)throw new Error("only defined for 25519 and 448");let T=O?i.div(nt+x,nt-x):i.div(x-nt,x+nt);return i.toBytes(T)},toMontgomerySecret(E){let x=w.secretKey;K(E,x);let P=t(E.subarray(0,x));return c(P).subarray(0,x)}};return Object.freeze({keygen:Tr(B,b),getPublicKey:b,sign:I,verify:g,utils:M,Point:r,lengths:w})}var tu=BigInt(1),ho=BigInt(2);var eu=BigInt(5),ru=BigInt(8),Jn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),nu={p:Jn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:ru,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function su(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),i=Jn,a=r*r%i*r%i,c=Z(a,ho,i)*a%i,u=Z(c,tu,i)*r%i,l=Z(u,eu,i)*u%i,f=Z(l,t,i)*l%i,y=Z(f,e,i)*f%i,b=Z(y,n,i)*y%i,d=Z(b,s,i)*b%i,I=Z(d,s,i)*b%i,S=Z(I,t,i)*l%i;return{pow_p_5_8:Z(S,ho,i)*r%i,b2:a}}function iu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var po=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ou(r,t){let e=Jn,n=Q(t*t*t,e),s=Q(n*n*t,e),i=su(r*s).pow_p_5_8,o=Q(r*n*i,e),a=Q(t*o*o,e),c=o,u=Q(o*po,e),l=a===r,f=a===Q(-r,e),y=a===Q(-r*po,e);return l&&(o=c),(f||y)&&(o=u),ro(o,e)&&(o=Q(-o,e)),{isValid:l||f,value:o}}var au=fo(nu,{uvRatio:ou});function cu(r){return lo(au,Fi,Object.assign({adjustScalarBytes:iu},r))}var mo=cu({});var Je=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Rr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var bo={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Rr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var vt=bo;var kr=32;var Qn,uu=(async()=>{try{return await vt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function fu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await vt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await vt.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function lu(r,t,e){return mo.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function yo(r,t,e){return Qn==null&&(Qn=await uu),Qn?fu(r,t,e):lu(r,t,e)}function Cr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Pr=class{type="Ed25519";raw;constructor(t){this.raw=ts(t,kr)}toMultihash(){return At.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let s=yo(this.raw,e,t);return Cr(s)?s.then(i=>(n?.signal?.throwIfAborted(),i)):s}};function es(r){return r=ts(r,kr),new Pr(r)}function ts(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new z(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var du=Math.pow(2,7),pu=Math.pow(2,14),mu=Math.pow(2,21),rs=Math.pow(2,28),ns=Math.pow(2,35),ss=Math.pow(2,42),is=Math.pow(2,49),V=128,ct=127;function Ht(r){if(r<du)return 1;if(r<pu)return 2;if(r<mu)return 3;if(r<rs)return 4;if(r<ns)return 5;if(r<ss)return 6;if(r<is)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function os(r,t,e=0){switch(Ht(r)){case 8:t[e++]=r&255|V,r/=128;case 7:t[e++]=r&255|V,r/=128;case 6:t[e++]=r&255|V,r/=128;case 5:t[e++]=r&255|V,r/=128;case 4:t[e++]=r&255|V,r>>>=7;case 3:t[e++]=r&255|V,r>>>=7;case 2:t[e++]=r&255|V,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function bu(r,t,e=0){switch(Ht(r)){case 8:t.set(e++,r&255|V),r/=128;case 7:t.set(e++,r&255|V),r/=128;case 6:t.set(e++,r&255|V),r/=128;case 5:t.set(e++,r&255|V),r/=128;case 4:t.set(e++,r&255|V),r>>>=7;case 3:t.set(e++,r&255|V),r>>>=7;case 2:t.set(e++,r&255|V),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function as(r,t){let e=r[t],n=0;if(n+=e&ct,e<V||(e=r[t+1],n+=(e&ct)<<7,e<V)||(e=r[t+2],n+=(e&ct)<<14,e<V)||(e=r[t+3],n+=(e&ct)<<21,e<V)||(e=r[t+4],n+=(e&ct)*rs,e<V)||(e=r[t+5],n+=(e&ct)*ns,e<V)||(e=r[t+6],n+=(e&ct)*ss,e<V)||(e=r[t+7],n+=(e&ct)*is,e<V))return n;throw new RangeError("Could not decode varint")}function yu(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<V||(e=r.get(t+1),n+=(e&ct)<<7,e<V)||(e=r.get(t+2),n+=(e&ct)<<14,e<V)||(e=r.get(t+3),n+=(e&ct)<<21,e<V)||(e=r.get(t+4),n+=(e&ct)*rs,e<V)||(e=r.get(t+5),n+=(e&ct)*ns,e<V)||(e=r.get(t+6),n+=(e&ct)*ss,e<V)||(e=r.get(t+7),n+=(e&ct)*is,e<V))return n;throw new RangeError("Could not decode varint")}function wo(r,t,e=0){return t==null&&(t=mt(Ht(r))),t instanceof Uint8Array?os(r,t,e):bu(r,t,e)}function xo(r,t=0){return r instanceof Uint8Array?as(r,t):yu(r,t)}var cs=new Float32Array([-0]),te=new Uint8Array(cs.buffer);function Eo(r,t,e){cs[0]=r,t[e]=te[0],t[e+1]=te[1],t[e+2]=te[2],t[e+3]=te[3]}function vo(r,t){return te[0]=r[t],te[1]=r[t+1],te[2]=r[t+2],te[3]=r[t+3],cs[0]}var us=new Float64Array([-0]),ut=new Uint8Array(us.buffer);function So(r,t,e){us[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function Ao(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],us[0]}var wu=BigInt(Number.MAX_SAFE_INTEGER),xu=BigInt(Number.MIN_SAFE_INTEGER),Et=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return he;if(t<wu&&t>xu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>Io&&(s=0n,++n>Io&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return he;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):he}},he=new Et(0,0);he.toBigInt=function(){return 0n};he.zzEncode=he.zzDecode=function(){return this};he.length=function(){return 1};var Io=4294967296n;function Bo(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Lo(r,t,e){if(e-t<1)return"";let s,i=[],o=0,a;for(;t<e;)a=r[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function fs(r,t,e){let n=e,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function Bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Nr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ls=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Bt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Nr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Nr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=vo(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=Ao(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Bt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Lo(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Et(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Bt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Bt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Bt(this,8);let t=Nr(this.buf,this.pos+=4),e=Nr(this.buf,this.pos+=4);return new Et(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=as(this.buf,this.pos);return this.pos+=Ht(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function hs(r){return new ls(r instanceof Uint8Array?r:r.subarray())}function gt(r,t,e){let n=hs(r);return t.decode(n,void 0,e)}function ds(r){let t=r??8192,e=t>>>1,n,s=t;return function(o){if(o<1||o>e)return mt(o);s+o>t&&(n=mt(t),s=0);let a=n.subarray(s,s+=o);return(s&7)!==0&&(s=(s|7)+1),a}}var de=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function ps(){}var bs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Eu=ds();function vu(r){return globalThis.Buffer!=null?mt(r):Eu(r)}var tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(ps,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new de(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ys((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Kr,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Et.fromBigInt(t);return this._push(Kr,e.length(),e)}uint64Number(t){return this._push(os,Ht(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Et.fromBigInt(t).zzEncode();return this._push(Kr,e.length(),e)}sint64Number(t){let e=Et.fromNumber(t).zzEncode();return this._push(Kr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ms,1,t?1:0)}fixed32(t){return this._push(Qe,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Et.fromBigInt(t);return this._push(Qe,4,e.lo)._push(Qe,4,e.hi)}fixed64Number(t){let e=Et.fromNumber(t);return this._push(Qe,4,e.lo)._push(Qe,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Eo,4,t)}double(t){return this._push(So,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ms,1,0):this.uint32(e)._push(Au,e,t)}string(t){let e=Bo(t);return e!==0?this.uint32(e)._push(fs,e,t):this._push(ms,1,0)}fork(){return this.states=new bs(this),this.head=this.tail=new de(ps,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new de(ps,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=vu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ms(r,t,e){t[e]=r&255}function Su(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ys=class extends de{next;constructor(t,e){super(Su,t,e),this.next=void 0}};function Kr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Qe(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Au(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(tr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Iu,t,r),this},tr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Bu,t,r),this});function Iu(r,t,e){t.set(r,e)}function Bu(r,t,e){r.length<40?fs(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(F(r),e)}function gs(){return new tr}function wt(r,t){let e=gs();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ke;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(ke||(ke={}));function Ur(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ws(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,o){let a=t(i);o.int32(a)},n=function(i){let o=i.int32();return t(o)};return Ur("enum",ke.VARINT,e,n)}function xt(r,t){return Ur("message",ke.LENGTH_DELIMITED,r,t)}var St=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var xs;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(xs||(xs={}));(function(r){r.codec=()=>ws(xs)})(tt||(tt={}));var Rt;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.Type=tt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Rt||(Rt={}));var Es;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.Type=tt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Es||(Es={}));function Mr(r){if(isNaN(r)||r<=0)throw new z("random bytes length must be a Number bigger than 0");return Yt(r)}var rr={};dt(rr,{MAX_RSA_KEY_SIZE:()=>vs,generateRSAKeyPair:()=>Co,jwkToJWKKeyPair:()=>Po,jwkToPkcs1:()=>Tu,jwkToPkix:()=>Bs,jwkToRSAPrivateKey:()=>Ts,pkcs1MessageToJwk:()=>As,pkcs1MessageToRSAPrivateKey:()=>Ls,pkcs1ToJwk:()=>Du,pkcs1ToRSAPrivateKey:()=>ko,pkixMessageToJwk:()=>Is,pkixMessageToRSAPublicKey:()=>Ds,pkixToJwk:()=>Ru,pkixToRSAPublicKey:()=>_s});var Ce=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e,n){return Ro(this.jwk,e,t,n)}},er=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=rr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}sign(t,e){return To(this.jwk,t,e)}};var vs=8192,Ss=18,Lu=1062,_u=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Du(r){let t=Pt(r);return As(t)}function As(r){return{n:H(r[1],"base64url"),e:H(r[2],"base64url"),d:H(r[3],"base64url"),p:H(r[4],"base64url"),q:H(r[5],"base64url"),dp:H(r[6],"base64url"),dq:H(r[7],"base64url"),qi:H(r[8],"base64url"),kty:"RSA"}}function Tu(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new z("JWK was missing components");return Gt([bt(Uint8Array.from([0])),bt(F(r.n,"base64url")),bt(F(r.e,"base64url")),bt(F(r.d,"base64url")),bt(F(r.p,"base64url")),bt(F(r.q,"base64url")),bt(F(r.dp,"base64url")),bt(F(r.dq,"base64url")),bt(F(r.qi,"base64url"))]).subarray()}function Ru(r){let t=Pt(r,{offset:0});return Is(t)}function Is(r){let t=Pt(r[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function Bs(r){if(r.n==null||r.e==null)throw new z("JWK was missing components");return Gt([_u,vr(Gt([bt(F(r.n,"base64url")),bt(F(r.e,"base64url"))]))]).subarray()}function ko(r){let t=Pt(r);return Ls(t)}function Ls(r){let t=As(r);return Ts(t)}function _s(r,t){if(r.byteLength>=Lu)throw new ye("Key size is too large");let e=Pt(r,{offset:0});return Ds(e,r,t)}function Ds(r,t,e){let n=Is(r);if(e==null){let s=Be(Rt.encode({Type:tt.RSA,Data:t}));e=_t(Ss,s)}return new Ce(n,e)}function Ts(r){if(Ko(r)>vs)throw new z("Key size is too large");let t=Po(r),e=Be(Rt.encode({Type:tt.RSA,Data:Bs(t.publicKey)})),n=_t(Ss,e);return new er(t.privateKey,new Ce(t.publicKey,n))}async function Co(r){if(r>vs)throw new z("Key size is too large");let t=await No(r),e=Be(Rt.encode({Type:tt.RSA,Data:Bs(t.publicKey)})),n=_t(Ss,e);return new er(t.privateKey,new Ce(t.publicKey,n))}function Po(r){if(r==null)throw new z("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function No(r,t){let e=await vt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await ku(e,t);return{privateKey:n[0],publicKey:n[1]}}async function To(r,t,e){let n=await vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let s=await vt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function Ro(r,t,e,n){let s=await vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await vt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),i}async function ku(r,t){if(r.privateKey==null||r.publicKey==null)throw new z("Private and public key are required");let e=await Promise.all([vt.get().subtle.exportKey("jwk",r.privateKey),vt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Ko(r){if(r.kty!=="RSA")throw new z("invalid key type");if(r.n==null)throw new z("invalid key modulus");return F(r.n,"base64url").length*8}var Or=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Sr(t),K(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(e.length>n?t.create().update(e).digest():e);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Ut(s)}update(t){return Ie(this),this.iHash.update(t),this}digestInto(t){Ie(this),K(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=i,t.blockLen=o,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Rs=(r,t,e)=>new Or(r,t).update(e).digest();Rs.create=(r,t)=>new Or(r,t);var Uo=(r,t)=>(r+(r>=0?t:-t)/Mo)/t;function Cu(r,t,e){let[[n,s],[i,o]]=t,a=Uo(o*r,e),c=Uo(-s*r,e),u=r-a*n-c*i,l=-a*s-c*o,f=u<Ft,y=l<Ft;f&&(u=-u),y&&(l=-l);let b=je(Math.ceil(Hn(e)/2))+Pe;if(u<Ft||u>=b||l<Ft||l>=b)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:f,k1:u,k2neg:y,k2:l}}function Cs(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function ks(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Vt(e.lowS,"lowS"),Vt(e.prehash,"prehash"),e.format!==void 0&&Cs(e.format),e}var Ps=class extends Error{constructor(t=""){super(t)}},ee={Err:Ps,_tlv:{encode:(r,t)=>{let{Err:e}=ee;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,s=Ge(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let i=n>127?Ge(s.length/2|128):"";return Ge(r)+i+s+t},decode(r,t){let{Err:e}=ee,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let s=t[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)o=o<<8|l;if(n+=c,o<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+o);if(a.length!==o)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(r){let{Err:t}=ee;if(r<Ft)throw new t("integer: negative integers are not allowed");let e=Ge(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=ee;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Le(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=ee,s=K(r,void 0,"signature"),{v:i,l:o}=n.decode(48,s);if(o.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l}=n.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=ee,n=t.encode(2,e.encode(r.r)),s=t.encode(2,e.encode(r.s)),i=n+s;return t.encode(48,i)}},Ft=BigInt(0),Pe=BigInt(1),Mo=BigInt(2),qr=BigInt(3),Pu=BigInt(4);function Oo(r,t={}){let e=Dr("weierstrass",r,t),{Fp:n,Fn:s}=e,i=e.CURVE,{h:o,n:a}=i;Jt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Vo(n,s);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(T,p,m){let{x:h,y:v}=p.toAffine(),L=n.toBytes(h);if(Vt(m,"isCompressed"),m){l();let D=!n.isOdd(v);return yt(qo(D),L)}else return yt(Uint8Array.of(4),L,n.toBytes(v))}function y(T){K(T,void 0,"Point");let{publicKey:p,publicKeyUncompressed:m}=u,h=T.length,v=T[0],L=T.subarray(1);if(h===p&&(v===2||v===3)){let D=n.fromBytes(L);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let R=I(D),_;try{_=n.sqrt(R)}catch(Y){let $=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+$)}l();let k=n.isOdd(_);return(v&1)===1!==k&&(_=n.neg(_)),{x:D,y:_}}else if(h===m&&v===4){let D=n.BYTES,R=n.fromBytes(L.subarray(0,D)),_=n.fromBytes(L.subarray(D,D*2));if(!S(R,_))throw new Error("bad point: is not on curve");return{x:R,y:_}}else throw new Error(`bad point: got length ${h}, expected compressed=${p} or uncompressed=${m}`)}let b=t.toBytes||f,d=t.fromBytes||y;function I(T){let p=n.sqr(T),m=n.mul(p,T);return n.add(n.add(m,n.mul(T,i.a)),i.b)}function S(T,p){let m=n.sqr(p),h=I(T);return n.eql(m,h)}if(!S(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(i.a,qr),Pu),A=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(g,A)))throw new Error("bad curve params: a or b");function w(T,p,m=!1){if(!n.isValid(p)||m&&n.is0(p))throw new Error(`bad point coordinate ${T}`);return p}function B(T){if(!(T instanceof x))throw new Error("Weierstrass Point expected")}function C(T){if(!c||!c.basises)throw new Error("no endo");return Cu(T,c.basises,s.ORDER)}let U=_e((T,p)=>{let{X:m,Y:h,Z:v}=T;if(n.eql(v,n.ONE))return{x:m,y:h};let L=T.is0();p==null&&(p=L?n.ONE:n.inv(v));let D=n.mul(m,p),R=n.mul(h,p),_=n.mul(v,p);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:D,y:R}}),M=_e(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:p,y:m}=T.toAffine();if(!n.isValid(p)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!S(p,m))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function E(T,p,m,h,v){return m=new x(n.mul(m.X,T),m.Y,m.Z),p=We(h,p),m=We(v,m),p.add(m)}class x{static BASE=new x(i.Gx,i.Gy,n.ONE);static ZERO=new x(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(p,m,h){this.X=w("x",p),this.Y=w("y",m,!0),this.Z=w("z",h),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x:m,y:h}=p||{};if(!p||!n.isValid(m)||!n.isValid(h))throw new Error("invalid affine point");if(p instanceof x)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(h)?x.ZERO:new x(m,h,n.ONE)}static fromBytes(p){let m=x.fromAffine(d(K(p,void 0,"point")));return m.assertValidity(),m}static fromHex(p){return x.fromBytes(Ot(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,m=!0){return O.createCache(this,p),m||this.multiply(qr),this}assertValidity(){M(this)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){B(p);let{X:m,Y:h,Z:v}=this,{X:L,Y:D,Z:R}=p,_=n.eql(n.mul(m,R),n.mul(L,v)),k=n.eql(n.mul(h,R),n.mul(D,v));return _&&k}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:p,b:m}=i,h=n.mul(m,qr),{X:v,Y:L,Z:D}=this,R=n.ZERO,_=n.ZERO,k=n.ZERO,N=n.mul(v,v),Y=n.mul(L,L),$=n.mul(D,D),q=n.mul(v,L);return q=n.add(q,q),k=n.mul(v,D),k=n.add(k,k),R=n.mul(p,k),_=n.mul(h,$),_=n.add(R,_),R=n.sub(Y,_),_=n.add(Y,_),_=n.mul(R,_),R=n.mul(q,R),k=n.mul(h,k),$=n.mul(p,$),q=n.sub(N,$),q=n.mul(p,q),q=n.add(q,k),k=n.add(N,N),N=n.add(k,N),N=n.add(N,$),N=n.mul(N,q),_=n.add(_,N),$=n.mul(L,D),$=n.add($,$),N=n.mul($,q),R=n.sub(R,N),k=n.mul($,Y),k=n.add(k,k),k=n.add(k,k),new x(R,_,k)}add(p){B(p);let{X:m,Y:h,Z:v}=this,{X:L,Y:D,Z:R}=p,_=n.ZERO,k=n.ZERO,N=n.ZERO,Y=i.a,$=n.mul(i.b,qr),q=n.mul(m,L),j=n.mul(h,D),st=n.mul(v,R),Lt=n.add(m,h),X=n.add(L,D);Lt=n.mul(Lt,X),X=n.add(q,j),Lt=n.sub(Lt,X),X=n.add(m,v);let ot=n.add(L,R);return X=n.mul(X,ot),ot=n.add(q,st),X=n.sub(X,ot),ot=n.add(h,v),_=n.add(D,R),ot=n.mul(ot,_),_=n.add(j,st),ot=n.sub(ot,_),N=n.mul(Y,X),_=n.mul($,st),N=n.add(_,N),_=n.sub(j,N),N=n.add(j,N),k=n.mul(_,N),j=n.add(q,q),j=n.add(j,q),st=n.mul(Y,st),X=n.mul($,X),j=n.add(j,st),st=n.sub(q,st),st=n.mul(Y,st),X=n.add(X,st),q=n.mul(j,X),k=n.add(k,q),q=n.mul(ot,X),_=n.mul(Lt,_),_=n.sub(_,q),q=n.mul(Lt,j),N=n.mul(ot,N),N=n.add(N,q),new x(_,k,N)}subtract(p){return this.add(p.negate())}is0(){return this.equals(x.ZERO)}multiply(p){let{endo:m}=t;if(!s.isValidNot0(p))throw new Error("invalid scalar: out of range");let h,v,L=D=>O.cached(this,D,R=>le(x,R));if(m){let{k1neg:D,k1:R,k2neg:_,k2:k}=C(p),{p:N,f:Y}=L(R),{p:$,f:q}=L(k);v=Y.add(q),h=E(m.beta,N,$,D,_)}else{let{p:D,f:R}=L(p);h=D,v=R}return le(x,[h,v])[0]}multiplyUnsafe(p){let{endo:m}=t,h=this;if(!s.isValid(p))throw new Error("invalid scalar: out of range");if(p===Ft||h.is0())return x.ZERO;if(p===Pe)return h;if(O.hasCache(this))return this.multiply(p);if(m){let{k1neg:v,k1:L,k2neg:D,k2:R}=C(p),{p1:_,p2:k}=uo(x,h,L,R);return E(m.beta,_,k,v,D)}else return O.unsafe(h,p)}toAffine(p){return U(this,p)}isTorsionFree(){let{isTorsionFree:p}=t;return o===Pe?!0:p?p(x,this):O.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=t;return o===Pe?this:p?p(x,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(p=!0){return Vt(p,"isCompressed"),this.assertValidity(),b(x,this,p)}toHex(p=!0){return Mt(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=s.BITS,O=new Re(x,t.endo?Math.ceil(P/2):P);return x.BASE.precompute(8),x}function qo(r){return Uint8Array.of(r?2:3)}function Vo(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Nu(r,t={}){let{Fn:e}=r,n=t.randomBytes||Yt,s=Object.assign(Vo(r.Fp,e),{seed:Zn(e.ORDER)});function i(b){try{let d=e.fromBytes(b);return e.isValidNot0(d)}catch{return!1}}function o(b,d){let{publicKey:I,publicKeyUncompressed:S}=s;try{let g=b.length;return d===!0&&g!==I||d===!1&&g!==S?!1:!!r.fromBytes(b)}catch{return!1}}function a(b=n(s.seed)){return Gn(K(b,s.seed,"seed"),e.ORDER)}function c(b,d=!0){return r.BASE.multiply(e.fromBytes(b)).toBytes(d)}function u(b){let{secretKey:d,publicKey:I,publicKeyUncompressed:S}=s;if(!ie(b)||"_lengths"in e&&e._lengths||d===I)return;let g=K(b,void 0,"key").length;return g===I||g===S}function l(b,d,I=!0){if(u(b)===!0)throw new Error("first arg must be private key");if(u(d)===!1)throw new Error("second arg must be public key");let S=e.fromBytes(b);return r.fromBytes(d).multiply(S).toBytes(I)}let f={isValidSecretKey:i,isValidPublicKey:o,randomSecretKey:a},y=Tr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:y,Point:r,utils:f,lengths:s})}function Ho(r,t,e={}){Sr(t),Jt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||Yt,s=e.hmac||((m,h)=>Rs(t,m,h)),{Fp:i,Fn:o}=r,{ORDER:a,BITS:c}=o,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:y,lengths:b}=Nu(r,e),d={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},I=a*Mo<i.ORDER;function S(m){let h=a>>Pe;return m>h}function g(m,h){if(!o.isValidNot0(h))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return h}function A(){if(I)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(m,h){Cs(h);let v=b.signature,L=h==="compact"?v:h==="recovered"?v+1:void 0;return K(m,L)}class B{r;s;recovery;constructor(h,v,L){if(this.r=g("r",h),this.s=g("s",v),L!=null){if(A(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(h,v=d.format){w(h,v);let L;if(v==="der"){let{r:k,s:N}=ee.toSig(K(h));return new B(k,N)}v==="recovered"&&(L=h[0],v="compact",h=h.subarray(1));let D=b.signature/2,R=h.subarray(0,D),_=h.subarray(D,D*2);return new B(o.fromBytes(R),o.fromBytes(_),L)}static fromHex(h,v){return this.fromBytes(Ot(h),v)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new B(this.r,this.s,h)}recoverPublicKey(h){let{r:v,s:L}=this,D=this.assertRecovery(),R=D===2||D===3?v+a:v;if(!i.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let _=i.toBytes(R),k=r.fromBytes(yt(qo((D&1)===0),_)),N=o.inv(R),Y=U(K(h,void 0,"msgHash")),$=o.create(-Y*N),q=o.create(L*N),j=r.BASE.multiplyUnsafe($).add(k.multiplyUnsafe(q));if(j.is0())throw new Error("invalid recovery: point at infinify");return j.assertValidity(),j}hasHighS(){return S(this.s)}toBytes(h=d.format){if(Cs(h),h==="der")return Ot(ee.hexFromSig(this));let{r:v,s:L}=this,D=o.toBytes(v),R=o.toBytes(L);return h==="recovered"?(A(),yt(Uint8Array.of(this.assertRecovery()),D,R)):yt(D,R)}toHex(h){return Mt(this.toBytes(h))}}let C=e.bits2int||function(h){if(h.length>8192)throw new Error("input is too large");let v=Le(h),L=h.length*8-c;return L>0?v>>BigInt(L):v},U=e.bits2int_modN||function(h){return o.create(C(h))},M=je(c);function E(m){return Ye("num < 2^"+c,m,Ft,M),o.toBytes(m)}function x(m,h){return K(m,void 0,"message"),h?K(t(m),void 0,"prehashed message"):m}function P(m,h,v){let{lowS:L,prehash:D,extraEntropy:R}=ks(v,d);m=x(m,D);let _=U(m),k=o.fromBytes(h);if(!o.isValidNot0(k))throw new Error("invalid private key");let N=[E(k),E(_)];if(R!=null&&R!==!1){let j=R===!0?n(b.secretKey):R;N.push(K(j,void 0,"extraEntropy"))}let Y=yt(...N),$=_;function q(j){let st=C(j);if(!o.isValidNot0(st))return;let Lt=o.inv(st),X=r.BASE.multiply(st).toAffine(),ot=o.create(X.x);if(ot===Ft)return;let mr=o.create(Lt*o.create($+ot*k));if(mr===Ft)return;let Ws=(X.x===ot?0:2)|Number(X.y&Pe),Js=mr;return L&&S(mr)&&(Js=o.neg(mr),Ws^=1),new B(ot,Js,I?void 0:Ws)}return{seed:Y,k2sig:q}}function O(m,h,v={}){let{seed:L,k2sig:D}=P(m,h,v);return Zi(t.outputLen,o.BYTES,s)(L,D).toBytes(v.format)}function T(m,h,v,L={}){let{lowS:D,prehash:R,format:_}=ks(L,d);if(v=K(v,void 0,"publicKey"),h=x(h,R),!ie(m)){let k=m instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+k)}w(m,_);try{let k=B.fromBytes(m,_),N=r.fromBytes(v);if(D&&k.hasHighS())return!1;let{r:Y,s:$}=k,q=U(h),j=o.inv($),st=o.create(q*j),Lt=o.create(Y*j),X=r.BASE.multiplyUnsafe(st).add(N.multiplyUnsafe(Lt));return X.is0()?!1:o.create(X.x)===Y}catch{return!1}}function p(m,h,v={}){let{prehash:L}=ks(v,d);return h=x(h,L),B.fromBytes(m,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:y,lengths:b,Point:r,sign:O,verify:T,recoverPublicKey:p,Signature:B,hash:t})}var Ks={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ku={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Fo=BigInt(2);function Uu(r){let t=Ks.p,e=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=Z(l,e,t)*l%t,y=Z(f,e,t)*l%t,b=Z(y,Fo,t)*u%t,d=Z(b,s,t)*b%t,I=Z(d,i,t)*d%t,S=Z(I,a,t)*I%t,g=Z(S,c,t)*S%t,A=Z(g,a,t)*I%t,w=Z(A,e,t)*l%t,B=Z(w,o,t)*d%t,C=Z(B,n,t)*u%t,U=Z(C,Fo,t);if(!Ns.eql(Ns.sqr(U),r))throw new Error("Cannot find square root");return U}var Ns=De(Ks.p,{sqrt:Uu}),Mu=Oo(Ks,{Fp:Ns,endo:Ku}),Ne=Ho(Mu,Be);function zo(r,t,e,n){let s=se.digest(e instanceof Uint8Array?e:e.subarray());if(Cr(s))return s.then(({digest:i})=>(n?.signal?.throwIfAborted(),Ne.verify(t,i,r,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Je(String(i))});try{return n?.signal?.throwIfAborted(),Ne.verify(t,s.digest,r,{prehash:!1,format:"der"})}catch(i){throw new Je(String(i))}}var Vr=class{type="secp256k1";raw;_key;constructor(t){this._key=Zo(t),this.raw=$o(this._key)}toMultihash(){return At.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e,n){return zo(this._key,e,t,n)}};function Us(r){return new Vr(r)}function $o(r){return Ne.Point.fromBytes(r).toBytes()}function Zo(r){try{return Ne.Point.fromBytes(r),r}catch(t){throw new ye(String(t))}}function Ms(r,t){let{Type:e,Data:n}=Rt.decode(r),s=n??new Uint8Array;switch(e){case tt.RSA:return _s(s,t);case tt.Ed25519:return es(s);case tt.secp256k1:return Us(s);case tt.ECDSA:return Tn(s);default:throw new re}}function Go(r){let{Type:t,Data:e}=Rt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return es(n);case tt.secp256k1:return Us(n);case tt.ECDSA:return Tn(n);default:throw new re}}function Nt(r){return Rt.encode({Type:tt[r.type],Data:r.raw})}var Yo=Symbol.for("nodejs.util.inspect.custom"),Ou=114,nr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[en]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Ou,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return pt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return pt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Yo](){return`PeerId(${this.toString()})`}},sr=class extends nr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},ir=class extends nr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},or=class extends nr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},qu=2336,Hr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(F(this.url))}[Yo](){return`PeerId(${this.url})`}[en]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(qu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};function Os(r){if(r.type==="Ed25519")return new ir({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new or({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new sr({multihash:r.toCID().multihash,publicKey:r});throw new re}function jo(r){return Os(r.publicKey)}function ar(r){if(Hu(r))return new sr({multihash:r});if(Vu(r))try{let t=Go(r);if(t.type==="Ed25519")return new ir({multihash:r,publicKey:t});if(t.type==="secp256k1")return new or({multihash:r,publicKey:t})}catch{let e=H(r.digest);return new Hr(new URL(e))}throw new yr("Supplied PeerID Multihash is invalid")}function Vu(r){return r.code===At.code}function Hu(r){return r.code===se.code}function pe(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:t(s)}}};return e}function Fr(r){let t=$t(G.decode(`z${r}`));return ar(t)}var cr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return pe(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return pe(this.map.values(),t=>t.key)}values(){return pe(this.map.values(),t=>t.value)}get size(){return this.map.size}};var ur=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return pe(this.set.entries(),t=>{let e=Fr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Fr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return pe(this.set.values(),t=>Fr(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};var qs=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},Xo=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function fr(r,t){let{milliseconds:e,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=t,a,c,l=new Promise((f,y)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(o?.aborted){y(Xo(o));return}if(o&&(c=()=>{y(Xo(o))},o.addEventListener("abort",c,{once:!0})),r.then(f,y),e===Number.POSITIVE_INFINITY)return;let b=new qs;a=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){y(d)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?f():s instanceof Error?y(s):(b.message=s??`Promise timed out after ${e} milliseconds`,y(b))},e)}).finally(()=>{l.clear(),c&&o&&o.removeEventListener("abort",c)});return l.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},l}var Fu=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function zu(r,t,e){let n,s=new Promise((i,o)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:l}=Fu(r),f=async(...b)=>{let d=e.multiArgs?b:b[0];if(e.filter)try{if(!await e.filter(d))return}catch(I){n(),o(I);return}c.push(d),e.count===c.length&&(n(),i(c))},y=(...b)=>{n(),o(e.rejectionMultiArgs?b:b[0])};n=()=>{for(let b of a)l(b,f);for(let b of e.rejectionEvents)a.includes(b)||l(b,y)};for(let b of a)u(b,f);for(let b of e.rejectionEvents)a.includes(b)||u(b,y);e.signal&&e.signal.addEventListener("abort",()=>{y(e.signal.reason)},{once:!0}),e.resolveImmediately&&i(c)});if(s.cancel=n,typeof e.timeout=="number"){let i=fr(s,{milliseconds:e.timeout});return i.cancel=()=>{n(),i.clear()},i}return s}function Wo(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=zu(r,t,e),s=n.then(i=>i[0]);return s.cancel=n.cancel,s}var me=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function $u(r){return r.reason}async function Vs(r,t,e){if(t==null)return r;let n=e?.translateError??$u;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let s;try{return await Promise.race([r,new Promise((i,o)=>{s=()=>{o(n(t))},t.addEventListener("abort",s)})])}finally{s!=null&&t.removeEventListener("abort",s)}}var Gu=4194304,zr=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Fs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},zs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},$s=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Yu(r){return typeof r?.closeRead=="function"}function ju(r){return typeof r?.close=="function"}function Hs(r){return Yu(r)?r.remoteWriteStatus!=="writable"&&r.readBufferLength===0:ju(r)?r.status!=="open":!1}function Xu(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Wu(r,t){let e=t?.maxBufferSize??Gu,n=new et,s,i=!1;if(!Xu(r))throw new z("Argument should be a Stream or a Multiaddr");let o=l=>{if(n.append(l.data),n.byteLength>e){let f=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${f} > ${e}`))}s?.resolve()};r.addEventListener("message",o);let a=l=>{l.error!=null?s?.reject(l.error):s?.resolve()};r.addEventListener("close",a);let c=()=>{s?.resolve()};r.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(l){if(i===!0)throw new zr("Stream was unwrapped");if(Hs(r)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new me(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let f=l?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=f){s.resolve();break}if(await Vs(s.promise,l?.signal),Hs(r)){if(n.byteLength===0&&l?.bytes==null)return null;break}s=Promise.withResolvers()}let y=l?.bytes??n.byteLength;if(n.byteLength<y){if(Hs(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,y),new me(`Unexpected EOF - stream closed while reading ${n.byteLength}/${y} bytes`);return u.read(l)}let b=n.sublist(0,y);return n.consume(y),b},async write(l,f){if(i===!0)throw new zr("Stream was unwrapped");r.send(l)||await Wo(r,"drain",{signal:f?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,r.removeEventListener("message",o),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return u}function Ju(r,t={}){let e=Wu(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ht(t.maxDataLength));let n=t?.lengthDecoder??xo,s=t?.lengthEncoder??wo;return{async read(o){let a=-1,c=new et;for(;;){let l=await e.read({...o,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new Fs("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new $s(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new zs(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await e.read({...o,bytes:a});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new me(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new me(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(o,a){await e.write(new et(s(o.byteLength),o),a)},async writeV(o,a){let c=new et(...o.flatMap(u=>[s(u.byteLength),u]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function Zs(r,t){let e=Ju(r,t),n={read:async(s,i)=>{let o=await e.read(i);return s.decode(o)},write:async(s,i,o)=>{await e.write(i.encode(s),o)},writeV:async(s,i,o)=>{await e.writeV(s.map(a=>i.encode(a)),o)},pb:s=>({read:async i=>n.read(s,i),write:async(i,o)=>n.write(i,s,o),writeV:async(i,o)=>n.writeV(i,s,o),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Ys=da(Qo(),1);function js(r,t,e){let n=0,s=r.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;e(r[o],t)<=0?(n=++o,s-=i+1):s=i}return n}var hr=class{#t=[];enqueue(t,e){let{priority:n=0,id:s}=e??{},i={priority:n,id:s,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let o=js(this.#t,i,(a,c)=>c.priority-a.priority);this.#t.splice(o,0,i)}setPriority(t,e){let n=this.#t.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[s]=this.#t.splice(n,1);this.enqueue(s.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var dr=class extends Ys.default{#t;#o;#a=0;#d;#m=!1;#g=!1;#c;#B=0;#w=0;#u;#f;#i;#s=[];#n=0;#e;#L;#r=0;#b;#l;#k=1n;#y=new Map;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:hr,strict:!1,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#o=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#c=t.interval,this.#i=t.strict,this.#e=new t.queueClass,this.#L=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#q()}#x(t){for(;this.#n<this.#s.length;){let n=this.#s[this.#n];if(n!==void 0&&t-n>=this.#c)this.#n++;else break}(this.#n>100&&this.#n>this.#s.length/2||this.#n===this.#s.length)&&(this.#s=this.#s.slice(this.#n),this.#n=0)}#C(t){this.#i?this.#s.push(t):this.#a++}#P(){this.#i?this.#s.length>this.#n&&this.#s.pop():this.#a>0&&this.#a--}#E(){return this.#s.length-this.#n}get#N(){return this.#o?!0:this.#i?this.#E()<this.#d:this.#a<this.#d}get#K(){return this.#r<this.#b}#U(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#A(),this.emit("next")}#M(){this.#f=void 0,this.#T(),this.#D()}#O(t){if(this.#i){if(this.#x(t),this.#E()>=this.#d){let n=this.#s[this.#n],s=this.#c-(t-n);return this.#v(s),!0}return!1}if(this.#u===void 0){let e=this.#B-t;if(e<0){if(this.#w>0){let n=t-this.#w;if(n<this.#c)return this.#v(this.#c-n),!0}this.#a=this.#t?this.#r:0}else return this.#v(e),!0}return!1}#v(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#M()},t))}#S(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#_(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#A(){if(this.#e.size===0){if(this.#S(),this.emit("empty"),this.#r===0){if(this.#_(),this.#i&&this.#n>0){let e=Date.now();this.#x(e)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let e=Date.now(),n=!this.#O(e);if(this.#N&&this.#K){let s=this.#e.dequeue();this.#o||(this.#C(e),this.#p()),this.emit("active"),s(),n&&this.#D(),t=!0}}return t}#D(){this.#o||this.#u!==void 0||this.#i||(this.#u=setInterval(()=>{this.#T()},this.#c),this.#B=Date.now()+this.#c)}#T(){this.#i||(this.#a===0&&this.#r===0&&this.#u&&this.#S(),this.#a=this.#t?this.#r:0),this.#I(),this.#p()}#I(){for(;this.#A(););}get concurrency(){return this.#b}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#b=t,this.#I()}setPriority(t,e){if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${e}\` (${typeof e})`);this.#e.setPriority(t,e)}async add(t,e={}){return e={timeout:this.timeout,...e,id:e.id??(this.#k++).toString()},new Promise((n,s)=>{let i=Symbol(`task-${e.id}`);this.#e.enqueue(async()=>{this.#r++,this.#y.set(i,{id:e.id,priority:e.priority??0,startTime:Date.now(),timeout:e.timeout});let o;try{try{e.signal?.throwIfAborted()}catch(u){throw this.#V(),this.#y.delete(i),u}this.#w=Date.now();let a=t({signal:e.signal});if(e.timeout&&(a=fr(Promise.resolve(a),{milliseconds:e.timeout,message:`Task timed out after ${e.timeout}ms (queue has ${this.#r} running, ${this.#e.size} waiting)`})),e.signal){let{signal:u}=e;a=Promise.race([a,new Promise((l,f)=>{o=()=>{f(u.reason)},u.addEventListener("abort",o,{once:!0})})])}let c=await a;n(c),this.emit("completed",c)}catch(a){s(a),this.emit("error",a)}finally{o&&e.signal?.removeEventListener("abort",o),this.#y.delete(i),queueMicrotask(()=>{this.#U()})}},e),this.emit("add"),this.#A()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#l?(this.#l=!1,this.#I(),this):this}pause(){this.#l=!0}clear(){this.#e=new this.#L,this.#S(),this.#R(),this.emit("empty"),this.#r===0&&(this.#_(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#r===0&&this.#e.size===0||await this.#h("idle")}async onPendingZero(){this.#r!==0&&await this.#h("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#h("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#h("rateLimitCleared")}onError(){return new Promise((t,e)=>{let n=s=>{this.off("error",n),e(s)};this.on("error",n)})}async#h(t,e){return new Promise(n=>{let s=()=>{e&&!e()||(this.off(t,s),n())};this.on(t,s)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#r}get isPaused(){return this.#l}#q(){this.#o||(this.on("add",()=>{this.#e.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#o||this.#g||(this.#g=!0,queueMicrotask(()=>{this.#g=!1,this.#R()}))}#V(){this.#o||(this.#P(),this.#p())}#R(){let t=this.#m;if(this.#o||this.#e.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let e;if(this.#i){let s=Date.now();this.#x(s),e=this.#E()}else e=this.#a;let n=e>=this.#d;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#r===this.#b&&this.#e.size>0||this.isRateLimited&&this.#e.size>0}get runningTasks(){return[...this.#y.values()].map(t=>({...t}))}};var Zr=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,e){this.entries.set(t,{value:e,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[e,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(e);else break}}has(t){return this.entries.has(t)}get(t){let e=this.entries.get(t);return e!=null&&e.validUntilMs>=Date.now()?e.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var be;(function(r){let t;(function(s){let i;s.codec=()=>(i==null&&(i=xt((o,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),o.subscribe!=null&&(a.uint32(8),a.bool(o.subscribe)),o.topic!=null&&(a.uint32(18),a.string(o.topic)),c.lengthDelimited!==!1&&a.ldelim()},(o,a,c={})=>{let u={},l=a==null?o.len:o.pos+a;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{u.subscribe=o.bool();break}case 2:{u.topic=o.string();break}default:{o.skipType(f&7);break}}}return u})),i),s.encode=o=>wt(o,s.codec()),s.decode=(o,a)=>gt(o,s.codec(),a)})(t=r.SubOpts||(r.SubOpts={}));let e;(function(s){let i;s.codec=()=>(i==null&&(i=xt((o,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),o.from!=null&&(a.uint32(10),a.bytes(o.from)),o.data!=null&&(a.uint32(18),a.bytes(o.data)),o.sequenceNumber!=null&&(a.uint32(26),a.bytes(o.sequenceNumber)),o.topic!=null&&(a.uint32(34),a.string(o.topic)),o.signature!=null&&(a.uint32(42),a.bytes(o.signature)),o.key!=null&&(a.uint32(50),a.bytes(o.key)),c.lengthDelimited!==!1&&a.ldelim()},(o,a,c={})=>{let u={},l=a==null?o.len:o.pos+a;for(;o.pos<l;){let f=o.uint32();switch(f>>>3){case 1:{u.from=o.bytes();break}case 2:{u.data=o.bytes();break}case 3:{u.sequenceNumber=o.bytes();break}case 4:{u.topic=o.string();break}case 5:{u.signature=o.bytes();break}case 6:{u.key=o.bytes();break}default:{o.skipType(f&7);break}}}return u})),i),s.encode=o=>wt(o,s.codec()),s.decode=(o,a)=>gt(o,s.codec(),a)})(e=r.Message||(r.Message={}));let n;r.codec=()=>(n==null&&(n=xt((s,i,o={})=>{if(o.lengthDelimited!==!1&&i.fork(),s.subscriptions!=null)for(let a of s.subscriptions)i.uint32(10),r.SubOpts.codec().encode(a,i);if(s.messages!=null)for(let a of s.messages)i.uint32(18),r.Message.codec().encode(a,i);s.control!=null&&(i.uint32(26),Gr.codec().encode(s.control,i)),o.lengthDelimited!==!1&&i.ldelim()},(s,i,o={})=>{let a={subscriptions:[],messages:[]},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{if(o.limits?.subscriptions!=null&&a.subscriptions.length===o.limits.subscriptions)throw new St('Decode error - map field "subscriptions" had too many elements');a.subscriptions.push(r.SubOpts.codec().decode(s,s.uint32(),{limits:o.limits?.subscriptions$}));break}case 2:{if(o.limits?.messages!=null&&a.messages.length===o.limits.messages)throw new St('Decode error - map field "messages" had too many elements');a.messages.push(r.Message.codec().decode(s,s.uint32(),{limits:o.limits?.messages$}));break}case 3:{a.control=Gr.codec().decode(s,s.uint32(),{limits:o.limits?.control});break}default:{s.skipType(u&7);break}}}return a})),n),r.encode=s=>wt(s,r.codec()),r.decode=(s,i)=>gt(s,r.codec(),i)})(be||(be={}));var Gr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.ihave!=null)for(let i of e.ihave)n.uint32(10),Yr.codec().encode(i,n);if(e.iwant!=null)for(let i of e.iwant)n.uint32(18),jr.codec().encode(i,n);if(e.graft!=null)for(let i of e.graft)n.uint32(26),Xr.codec().encode(i,n);if(e.prune!=null)for(let i of e.prune)n.uint32(34),Wr.codec().encode(i,n);s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={ihave:[],iwant:[],graft:[],prune:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{if(s.limits?.ihave!=null&&i.ihave.length===s.limits.ihave)throw new St('Decode error - map field "ihave" had too many elements');i.ihave.push(Yr.codec().decode(e,e.uint32(),{limits:s.limits?.ihave$}));break}case 2:{if(s.limits?.iwant!=null&&i.iwant.length===s.limits.iwant)throw new St('Decode error - map field "iwant" had too many elements');i.iwant.push(jr.codec().decode(e,e.uint32(),{limits:s.limits?.iwant$}));break}case 3:{if(s.limits?.graft!=null&&i.graft.length===s.limits.graft)throw new St('Decode error - map field "graft" had too many elements');i.graft.push(Xr.codec().decode(e,e.uint32(),{limits:s.limits?.graft$}));break}case 4:{if(s.limits?.prune!=null&&i.prune.length===s.limits.prune)throw new St('Decode error - map field "prune" had too many elements');i.prune.push(Wr.codec().decode(e,e.uint32(),{limits:s.limits?.prune$}));break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Gr||(Gr={}));var Yr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.messageIDs!=null)for(let i of e.messageIDs)n.uint32(18),n.bytes(i);s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={messageIDs:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.topic=e.string();break}case 2:{if(s.limits?.messageIDs!=null&&i.messageIDs.length===s.limits.messageIDs)throw new St('Decode error - map field "messageIDs" had too many elements');i.messageIDs.push(e.bytes());break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Yr||(Yr={}));var jr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.messageIDs!=null)for(let i of e.messageIDs)n.uint32(10),n.bytes(i);s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={messageIDs:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{if(s.limits?.messageIDs!=null&&i.messageIDs.length===s.limits.messageIDs)throw new St('Decode error - map field "messageIDs" had too many elements');i.messageIDs.push(e.bytes());break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(jr||(jr={}));var Xr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.topic=e.string();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Xr||(Xr={}));var Wr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.peers!=null)for(let i of e.peers)n.uint32(18),Jr.codec().encode(i,n);e.backoff!=null&&(n.uint32(24),n.uint64(e.backoff)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={peers:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.topic=e.string();break}case 2:{if(s.limits?.peers!=null&&i.peers.length===s.limits.peers)throw new St('Decode error - map field "peers" had too many elements');i.peers.push(Jr.codec().decode(e,e.uint32(),{limits:s.limits?.peers$}));break}case 3:{i.backoff=e.uint64();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Wr||(Wr={}));var Jr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.peerID!=null&&(n.uint32(10),n.bytes(e.peerID)),e.signedPeerRecord!=null&&(n.uint32(18),n.bytes(e.signedPeerRecord)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.peerID=e.bytes();break}case 2:{i.signedPeerRecord=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Jr||(Jr={}));var Qr=class extends ge{peerId;shutDownController;inboundPb;outboundPb;constructor(t){super(),this.peerId=t,this.shutDownController=new AbortController}attachInboundStream(t,e){this.inboundPb=Zs(t,e).pb(be),Promise.resolve().then(async()=>{for(;;){if(this.inboundPb==null)return;let n=await this.inboundPb.read({signal:this.shutDownController.signal});this.safeDispatchEvent("message",{detail:n})}}).catch(n=>{this.inboundPb?.unwrap().unwrap().abort(n)})}attachOutboundStream(t,e){this.outboundPb=Zs(t,e).pb(be)}write(t){this.outboundPb!=null&&this.outboundPb.write(t,{signal:this.shutDownController.signal}).catch(e=>{this.outboundPb?.unwrap().unwrap().abort(e)})}close(){this.shutDownController.abort(),Promise.all([this.inboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)}),this.outboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)})]).finally(()=>{this.safeDispatchEvent("close")})}};function ta(){return BigInt(`0x${H(Mr(8),"base16")}`)}var ea=(r,t)=>{let e=F(t.toString(16).padStart(16,"0"),"base16"),n=Nt(r),s=new Uint8Array(n.byteLength+e.length);return s.set(n,0),s.set(e,n.byteLength),s},ra=r=>se.encode(r);var ef=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=ar($t(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return Os(Ms(e)).equals(t)}return!1},na=async r=>{if(r.from==null)throw new J("RPC message was missing from");if(!await ef(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=ar($t(r.from)),e=r.key??t.publicKey;if(e==null)throw new J("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:nf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?Ms(e):e}},pr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:rf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Nt(r.key):void 0}:{data:r.data,topic:r.topic},rf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},nf=r=>BigInt(`0x${H(r,"base16")}`);var sa=F("libp2p-pubsub:");async function ia(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:jo(r)},s=ne([sa,e(pr(n)).subarray()]);return n.signature=await r.sign(s),n.key=r.publicKey,n}async function oa(r,t){if(r.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(r.signature==null)throw new Error("Message must contain a signature to be verified");if(r.from==null)throw new Error("Message must contain a from property to be verified");let e=ne([sa,t({...pr(r),signature:void 0,key:void 0}).subarray()]);return sf(r).verify(e,r.signature)}function sf(r){if(r.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(r.from==null)throw new Error("Could not get the public key from the originator id");if(r.key!=null)return r.key;if(r.from.publicKey!=null)return r.from.publicKey;throw new Error("Could not get the public key from the originator id")}var tn=class extends ge{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocol=e.protocol??Xs,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new cr,this.globalSignaturePolicy=e.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=e.canRelayMessage??!0,this.emitSelf=e.emitSelf??!1,this.topicValidators=new Map,this.queue=new dr({concurrency:e.messageProcessingConcurrency??10}),this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.seenCache=new Zr({validityMs:e?.seenTTL??3e4}),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[Ue]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[ti]=["@libp2p/pubsub"];[ei]=["@libp2p/identify"];async start(){this.started||(this.log("starting"),await this.components.registrar.handle(this.protocol,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this._registrarTopologyId=await this.components.registrar.register(this.protocol,{onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected}),this.log("started"),this.started=!0)}async stop(){if(!this.started)return;let t=this.components.registrar;this._registrarTopologyId!=null&&t.unregister(this._registrarTopologyId),await t.unhandle(this.protocol),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t,e){this.addPeer(e.remotePeer,t).attachInboundStream(t)}async _onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(i=>i.direction==="outbound"&&i.protocol===this.protocol)){this.log("outbound pubsub stream already present on connection from %p",t);return}let n=await e.newStream(this.protocol);this.addPeer(t,n).attachOutboundStream(n),this.send(t,{subscriptions:Array.from(this.subscriptions).map(i=>i.toString()),subscribe:!0})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let s=new Qr(t);return this.peers.set(t,s),s.addEventListener("message",i=>{let o=i.detail,a=[];for(let c of o.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(s,{subscriptions:(o.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}),s.addEventListener("close",()=>this._removePeer(t),{once:!0}),s}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t)}}async processRpc(t,e){this.log("rpc from %p",t.peerId);let{subscriptions:n,messages:s}=e;return n!=null&&n.length>0&&(this.log("subscription update from %p",t.peerId),n.forEach(i=>{this.processRpcSubOpt(t.peerId,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:t.peerId,subscriptions:n.map(({topic:i,subscribe:o})=>({topic:`${i??""}`,subscribe:!!o}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t.peerId),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let o=await na(i);await this.processMessage(t.peerId,o)}catch(o){this.log.error("failed to queue messages from %p - %e",t.peerId,o)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let s=this.topics.get(n);s==null&&(s=new ur,this.topics.set(n,s)),e.subscribe===!0?s.add(t):s.delete(t)}async processMessage(t,e){if(this.components.peerId.equals(t)&&!this.emitSelf)return;let n=await this.getMsgId(e),s=H(n,"base64");if(!this.seenCache.has(s)){this.seenCache.put(s,!0);try{await this.validate(t,e)}catch(i){this.log("Message is invalid, dropping it. %O",i);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new J("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new J("Need key when signature policy is StrictSign but it was missing");return ea(t.key,t.sequenceNumber);case"StrictNoSign":return ra(t.data);default:throw new J("Cannot get message id: unhandled signature policy")}}encodeMessage(t){return be.Message.encode(t)}send(t,e){let{messages:n,subscriptions:s,subscribe:i}=e;this.sendRpc(t,{subscriptions:(s??[]).map(o=>({topic:o,subscribe:!!i})),messages:(n??[]).map(pr)})}sendRpc(t,e){let n=this.peers.get(t);if(n==null){this.log.error("cannot send RPC to %p as there are no streams to it available",t);return}n.write(e)}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new J('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new J("StrictNoSigning: signature should not be present");if(e.key!=null)throw new J("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new J("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new J("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new J("StrictSigning: Signing required and no sequenceNumber was present");if(!await oa(e,this.encodeMessage.bind(this)))throw new J("StrictSigning: Invalid message signature");break;default:throw new J("Cannot validate message: unhandled signature policy")}let s=this.topicValidators.get(e.topic);if(s!=null){let i=await s(t,e);if(i===Ke.Reject||i===Ke.Ignore)throw new J("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return ia(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new J("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new gr("not started yet");if(t==null)throw new z("Topic is required");let e=this.topics.get(t.toString());return e==null?[]:Array.from(e.values())}async publish(t,e){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:e??new Uint8Array(0),sequenceNumber:ta()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let s=await this.buildMessage(n),i=!1;this.emitSelf&&this.subscriptions.has(t)&&(i=!0,super.dispatchEvent(new CustomEvent("message",{detail:s})));let o=await this.publishMessage(this.components.peerId,s);return i&&(o.recipients=[...o.recipients,this.components.peerId]),o}async publishMessage(t,e){let n=this.getSubscribers(e.topic),s=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",e.topic),{recipients:s}):(n.forEach(i=>{if(this.components.peerId.equals(i)){this.log("not sending message on topic %s to myself",e.topic);return}if(i.equals(t)){this.log("not sending message on topic %s to sender %p",e.topic,i);return}this.log("publish msgs on topics %s %p",e.topic,i),s.push(i),this.send(i,{messages:[e]})}),{recipients:s})}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(!this.subscriptions.has(t)){this.log("subscribe to topic: %s",t),this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");if(this.subscriptions.has(t)){this.log("unsubscribe from %s",t),this.subscriptions.delete(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};var Xs="/floodsub/1.0.0",of="StrictSign",af="StrictNoSign",Ke;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ke||(Ke={}));function cf(r){return!!r?.[Ue]}function uf(r={}){return t=>new tn(t,r)}return pa(ff);})();
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 dr(){}Object.create&&(dr.prototype=Object.create(null),new dr().__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 dr:delete e._events[t]}function lt(){this._events=new dr,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 dr,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:()=>Ue,floodsub:()=>ff,isPubSub:()=>uf,protocol:()=>Ws,pubSubSymbol:()=>Me});var Me=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:()=>Oe,base36upper:()=>ka});var Oe=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,qe=ja;function Ve(e,t=0){return[qe.decode(e,t),qe.decode.bytes]}function ve(e,t,r=0){return qe.encode(e,t,r),t}function Se(e){return qe.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]=Ve(t),[i,s]=Ve(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!==He)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!==He)throw new Error(`Version 0 CID must use dag-pb (code: ${He}) 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,He,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]=Ve(t.subarray(r));return r+=l,h},i=n(),s=He;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 Oe.prefix:{let r=t??Oe;return[Oe.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 He=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:$e,1:$e,2:Ic,3:Dc,4:_c,5:Lc,6:Bc,16:$e,22:$e,48:$e};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 Fe(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 $e(e,t){Fe(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=Fe(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=Fe(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=Fe(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=Fe(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 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=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,Ye=(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 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 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 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: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)^Ye(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)^Ye(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)^Ye(n,i,34)^Ye(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 Ge(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 je(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 Xe=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 We(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 We(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 Je(e,t){let r=t.negate();return e?r:t}function he(e,t){let r=We(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=Xe(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(Je(l,r[d])):i=i.add(Je(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 je("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;je("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 Qe=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 tr(e){return new ds(e instanceof Uint8Array?e:e.subarray())}function wt(e,t,r){let n=tr(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 rr=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(er,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(er,4,r.lo)._push(er,4,r.hi)}fixed64Number(t){let r=St.fromNumber(t);return this._push(er,4,r.lo)._push(er,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 er(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&&(rr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Bu,t,e),this},rr.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 rr}function xt(e,t){let r=ws();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Et(e,t,r){let n=tr(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 sr={};pt(sr,{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=sr.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)}},nr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=sr.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 nr(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 nr(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=Xe(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=Ge(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Ge(i.length/2|128):"";return Ge(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=Ge(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=Je(m,y),g=Je(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=Xe(a);function E(g){return je("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 Qe(String(s))});try{return n?.signal?.throwIfAborted(),Ne.verify(t,i.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Qe(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,ir=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()})`}},or=class extends ir{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},ar=class extends ir{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},cr=class extends ir{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 ar({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new cr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new or({multihash:e.toCID().multihash,publicKey:e});throw new ne}function Xo(e){return qs(e.publicKey)}function ur(e){if($u(e))return new or({multihash:e});if(Hu(e))try{let t=Go(e);if(t.type==="Ed25519")return new ar({multihash:e,publicKey:t});if(t.type==="secp256k1")return new cr({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 ur(t)}var fr=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 lr=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 hr(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=hr(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 Ke=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})}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 pr=class extends js.default{#t;#o;#a=0;#d;#m=!1;#w=!1;#c;#L=0;#x=0;#u;#f;#i;#s=[];#n=0;#e;#D;#r=0;#b;#l;#C=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:Ke,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.#V()}#v(t){for(;this.#n<this.#s.length;){let n=this.#s[this.#n];if(n!==void 0&&t-n>=this.#c)this.#n++;else break}(this.#n>100&&this.#n>this.#s.length/2||this.#n===this.#s.length)&&(this.#s=this.#s.slice(this.#n),this.#n=0)}#P(t){this.#i?this.#s.push(t):this.#a++}#N(){this.#i?this.#s.length>this.#n&&this.#s.pop():this.#a>0&&this.#a--}#S(){return this.#s.length-this.#n}get#K(){return this.#o?!0:this.#i?this.#S()<this.#d:this.#a<this.#d}get#U(){return this.#r<this.#b}#M(){this.#r--,this.#r===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#O(){this.#f=void 0,this.#k(),this.#T()}#q(t){if(this.#i){if(this.#v(t),this.#S()>=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.#x>0){let n=t-this.#x;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.#O()},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.#v(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#q(r);if(this.#K&&this.#U){let i=this.#e.dequeue();this.#o||(this.#P(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.#C++).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(l){throw this.#H(),this.#y.delete(s),l}this.#x=Date.now();let f=t({signal:r.signal});if(r.timeout&&(f=hr(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:l}=r;f=Promise.race([f,new Promise((d,p)=>{u=()=>{p(l.reason)},l.addEventListener("abort",u,{once:!0})})])}let h=await f;n(h),this.emit("completed",h)}catch(f){i(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#y.delete(s),queueMicrotask(()=>{this.#M()})}};this.#e.enqueue(c,r);let a=()=>{if(this.#e instanceof Ke){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.#R(),this.emit("empty"),this.#r===0&&(this.#_(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#r===0&&this.#e.size===0||await this.#h("idle")}async onPendingZero(){this.#r!==0&&await this.#h("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#h("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#h("rateLimitCleared")}onError(){return new Promise((t,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}#V(){this.#o||(this.on("add",()=>{this.#e.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#o||this.#w||(this.#w=!0,queueMicrotask(()=>{this.#w=!1,this.#R()}))}#H(){this.#o||(this.#N(),this.#p())}#R(){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.#v(i),r=this.#S()}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=ur(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=ur(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 fr,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)}[Me]=!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 lr,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===Ue.Reject||s===Ue.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",Ue;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(Ue||(Ue={}));function uf(e){return!!e?.[Me]}function ff(e={}){return t=>new rn(t,e)}return ma(lf);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/utils.js: