@libp2p/floodsub 11.0.27 → 11.0.28-47cf9cdc1

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 ka=Object.create;var Dr=Object.defineProperty;var Pa=Object.getOwnPropertyDescriptor;var Oa=Object.getOwnPropertyNames;var Na=Object.getPrototypeOf,Fa=Object.prototype.hasOwnProperty;var Ka=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},pt=(e,t)=>{for(var r in t)Dr(e,r,{get:t[r],enumerable:!0})},xo=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Oa(t))!Fa.call(e,s)&&s!==r&&Dr(e,s,{get:()=>t[s],enumerable:!(n=Pa(t,s))||n.enumerable});return e};var Ua=(e,t,r)=>(r=e!=null?ka(Na(e)):{},xo(t||!e||!e.__esModule?Dr(r,"default",{value:e,enumerable:!0}):r,e)),Ma=e=>xo(Dr({},"__esModule",{value:!0}),e);var va=Ka((eb,po)=>{"use strict";var Nf=Object.prototype.hasOwnProperty,ht="~";function Lr(){}Object.create&&(Lr.prototype=Object.create(null),new Lr().__proto__||(ht=!1));function Ff(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function Sa(e,t,r,n,s){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new Ff(r,n||e,s),i=ht?ht+t:t;return e._events[i]?e._events[i].fn?e._events[i]=[e._events[i],o]:e._events[i].push(o):(e._events[i]=o,e._eventsCount++),e}function pn(e,t){--e._eventsCount===0?e._events=new Lr:delete e._events[t]}function lt(){this._events=new Lr,this._eventsCount=0}lt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)Nf.call(r,n)&&t.push(ht?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};lt.prototype.listeners=function(t){var r=ht?ht+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,o=n.length,i=new Array(o);s<o;s++)i[s]=n[s].fn;return i};lt.prototype.listenerCount=function(t){var r=ht?ht+t:t,n=this._events[r];return n?n.fn?1:n.length:0};lt.prototype.emit=function(t,r,n,s,o,i){var a=ht?ht+t:t;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,l;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,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,s),!0;case 5:return c.fn.call(c.context,r,n,s,o),!0;case 6:return c.fn.call(c.context,r,n,s,o,i),!0}for(l=1,f=new Array(u-1);l<u;l++)f[l-1]=arguments[l];c.fn.apply(c.context,f)}else{var h=c.length,d;for(l=0;l<h;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),u){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,r);break;case 3:c[l].fn.call(c[l].context,r,n);break;case 4:c[l].fn.call(c[l].context,r,n,s);break;default:if(!f)for(d=1,f=new Array(u-1);d<u;d++)f[d-1]=arguments[d];c[l].fn.apply(c[l].context,f)}}return!0};lt.prototype.on=function(t,r,n){return Sa(this,t,r,n,!1)};lt.prototype.once=function(t,r,n){return Sa(this,t,r,n,!0)};lt.prototype.removeListener=function(t,r,n,s){var o=ht?ht+t:t;if(!this._events[o])return this;if(!r)return pn(this,o),this;var i=this._events[o];if(i.fn)i.fn===r&&(!s||i.once)&&(!n||i.context===n)&&pn(this,o);else{for(var a=0,c=[],u=i.length;a<u;a++)(i[a].fn!==r||s&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[o]=c.length===1?c[0]:c:pn(this,o)}return this};lt.prototype.removeAllListeners=function(t){var r;return t?(r=ht?ht+t:t,this._events[r]&&pn(this,r)):(this._events=new Lr,this._eventsCount=0),this};lt.prototype.off=lt.prototype.removeListener;lt.prototype.addListener=lt.prototype.on;lt.prefixed=ht;lt.EventEmitter=lt;typeof po<"u"&&(po.exports=lt)});var Zf={};pt(Zf,{StrictNoSign:()=>zf,StrictSign:()=>Vf,TopicValidatorResult:()=>Ze,floodsub:()=>$f,isPubSub:()=>jf,protocol:()=>yo,pubSubSymbol:()=>Ge});var Ge=Symbol.for("@libp2p/pubsub");var $=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Be=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Cr=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 kr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ce=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var gn=Symbol.for("@libp2p/peer-id");function qa(e){return typeof e?.handleEvent=="function"}function Ha(e){return(e!==!0&&e!==!1&&e?.once)??!1}var Le=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){let s=Ha(n);super.addEventListener(t,i=>{if(s){let a=this.#t.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#t.set(i.type,a))}qa(r)?r.handleEvent(i):r(i)},n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:s})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let s=this.#t.get(t);s!=null&&(s=s.filter(({callback:o})=>o!==r),this.#t.set(t,s))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var Eo=Symbol.for("@libp2p/service-capabilities"),So=Symbol.for("@libp2p/service-dependencies");var vn={};pt(vn,{base58btc:()=>Z,base58flickr:()=>Xa});var Al=new Uint8Array(0);function Ao(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 xt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ue(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ue(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Io(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var vo=4096;function Bo(e){let t=e.length;if(t<=vo)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=vo));return r}function Va(e){return e?.buffer instanceof ArrayBuffer}function ue(e){return Va(e)?e:e.slice()}function za(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=o,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),u!==a&&(n[u]=o)}}var f=e.length,l=e.charAt(0),h=Math.log(f)/Math.log(256),d=Math.log(256)/Math.log(f);function g(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var S=0,I=0,C=0,_=m.length;C!==_&&m[C]===0;)C++,S++;for(var O=(_-C)*d+1>>>0,D=new Uint8Array(O);C!==_;){for(var B=m[C],N=0,F=O-1;(B!==0||N<I)&&F!==-1;F--,N++)B+=256*D[F]>>>0,D[F]=B%f>>>0,B=B/f>>>0;if(B!==0)throw new Error("Non-zero carry");I=N,C++}for(var P=O-I;P!==O&&D[P]===0;)P++;for(var p=l.repeat(S);P<O;++P)p+=e.charAt(D[P]);return p}function E(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var S=0;if(m[S]!==" "){for(var I=0,C=0;m[S]===l;)I++,S++;for(var _=(m.length-S)*h+1>>>0,O=new Uint8Array(_);m[S];){var D=n[m.charCodeAt(S)];if(D===255)return;for(var B=0,N=_-1;(D!==0||B<C)&&N!==-1;N--,B++)D+=f*O[N]>>>0,O[N]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");C=B,S++}if(m[S]!==" "){for(var F=_-C;F!==_&&O[F]===0;)F++;for(var P=new Uint8Array(I+(_-F)),p=I;F!==_;)P[p++]=O[F++];return P}}}function b(m){var S=E(m);if(S)return S;throw new Error(`Non-${t} character`)}return{encode:g,decodeUnsafe:E,decode:b}}var ja=za,$a=ja,To=$a;var wn=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")}},xn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let s=r.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 _o(this,t)}},En=class{decoders;constructor(t){this.decoders=t}or(t){return _o(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 _o(e,t){return new En({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Sn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,s){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new wn(t,r,n),this.decoder=new xn(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Te({name:e,prefix:t,encode:r,decode:n}){return new Sn(e,t,r,n)}function zt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:o}=To(r,e,n);return Te({prefix:t,name:e,encode:s,decode:i=>xt(o(i))})}function Za(e,t,r,n){let s=e.length;for(;e[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function Ya(e,t,r){let n=t[t.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function Ga(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let s=e[n].toLowerCase(),o=e[n].toUpperCase();s!==e[n]&&(r[s]=n),o!==e[n]&&(r[o]=n)}return r}function G({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let o=Ga(n,s);return Te({prefix:t,name:e,encode(i){return Ya(i,n,r)},decode(i){return Za(i,o,r,e)}})}var Z=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xa=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var An={};pt(An,{base32:()=>_e,base32hex:()=>tc,base32hexpad:()=>rc,base32hexpadupper:()=>nc,base32hexupper:()=>ec,base32pad:()=>Ja,base32padupper:()=>Qa,base32upper:()=>Wa,base32z:()=>sc});var _e=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Wa=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Ja=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Qa=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),tc=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),ec=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),rc=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),nc=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),sc=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var In={};pt(In,{base36:()=>Xe,base36upper:()=>oc});var Xe=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),oc=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var ic=Co,Ro=128,ac=127,cc=~ac,uc=Math.pow(2,31);function Co(e,t,r){t=t||[],r=r||0;for(var n=r;e>=uc;)t[r++]=e&255|Ro,e/=128;for(;e&cc;)t[r++]=e&255|Ro,e>>>=7;return t[r]=e|0,Co.bytes=r-n+1,t}var fc=Bn,lc=128,Do=127;function Bn(e,n){var r=0,n=n||0,s=0,o=n,i,a=e.length;do{if(o>=a)throw Bn.bytes=0,new RangeError("Could not decode varint");i=e[o++],r+=s<28?(i&Do)<<s:(i&Do)*Math.pow(2,s),s+=7}while(i>=lc);return Bn.bytes=o-n,r}var hc=Math.pow(2,7),dc=Math.pow(2,14),pc=Math.pow(2,21),mc=Math.pow(2,28),bc=Math.pow(2,35),yc=Math.pow(2,42),gc=Math.pow(2,49),wc=Math.pow(2,56),xc=Math.pow(2,63),Ec=function(e){return e<hc?1:e<dc?2:e<pc?3:e<mc?4:e<bc?5:e<yc?6:e<gc?7:e<wc?8:e<xc?9:10},Sc={encode:ic,decode:fc,encodingLength:Ec},vc=Sc,We=vc;function Je(e,t=0){let r=We.decode(e,t),n=We.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Re(e,t,r=0){return We.encode(e,t,r),t}function De(e){return We.encodingLength(e)}function Rt(e,t){let r=t.byteLength,n=De(e),s=n+De(r),o=new Uint8Array(s+r);return Re(e,o,0),Re(r,o,n),o.set(t,s),new Ce(e,r,t,o)}function jt(e){let t=xt(e),[r,n]=Je(t),[s,o]=Je(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Ce(r,s,i,t)}function ko(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ao(e.bytes,r.bytes)}}var Ce=class{code;size;digest;bytes;constructor(t,r,n,s){this.code=t,this.size=r,this.digest=ue(n),this.bytes=ue(s)}};function Po(e,t){let{bytes:r,version:n}=e;return n===0?Ic(r,Ln(e),t??Z.encoder):Bc(r,Ln(e),t??_e.encoder)}var Oo=new WeakMap;function Ln(e){let t=Oo.get(e);if(t==null){let r=new Map;return Oo.set(e,r),r}return t}var ct=class e{code;version;multihash;bytes;"/";constructor(t,r,n,s){this.code=r,this.version=t,this.multihash=n,this.bytes=ue(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Qe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Lc)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=Rt(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&&ko(t.multihash,n.multihash)}toString(t){return Po(this,t)}toJSON(){return{"/":Po(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:s,multihash:o,bytes:i}=r;return new e(n,s,o,i??No(n,s,o.bytes))}else if(r[Tc]===!0){let{version:n,multihash:s,code:o}=r,i=jt(s);return e.create(n,o,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Qe)throw new Error(`Version 0 CID must use dag-pb (code: ${Qe}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let s=No(t,r,n.bytes);return new e(t,r,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Qe,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,s=xt(t.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new Ce(r.multihashCode,r.digestSize,o,s);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,h]=Je(t.subarray(r));return r+=h,l},s=n(),o=Qe;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,s]=Ac(t,r),o=e.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ln(o).set(n,t),o}};function Ac(e,t){switch(e[0]){case"Q":{let r=t??Z;return[Z.prefix,r.decode(`${Z.prefix}${e}`)]}case Z.prefix:{let r=t??Z;return[Z.prefix,r.decode(e)]}case _e.prefix:{let r=t??_e;return[_e.prefix,r.decode(e)]}case Xe.prefix:{let r=t??Xe;return[Xe.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 Ic(e,t,r){let{prefix:n}=r;if(n!==Z.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=t.get(n);if(s==null){let o=r.encode(e).slice(1);return t.set(n,o),o}else return s}function Bc(e,t,r){let{prefix:n}=r,s=t.get(n);if(s==null){let o=r.encode(e);return t.set(n,o),o}else return s}var Qe=112,Lc=18;function No(e,t,r){let n=De(e),s=n+De(t),o=new Uint8Array(s+r.byteLength);return Re(e,o,0),Re(t,o,n),o.set(r,s),o}var Tc=Symbol.for("@ipld/js-cid/CID");var Tn={};pt(Tn,{identity:()=>vt});var Fo=0,_c="identity",Ko=xt;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 Rt(Fo,Ko(e))}var vt={code:Fo,name:_c,encode:Ko,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 Dc(e){return e.buffer instanceof ArrayBuffer}function Et(e){return Dc(e)?e:e.slice()}async function Uo(e,t,r,n){let s=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,Et(t),Et(r.subarray()));return n?.signal?.throwIfAborted(),o}function Ot(e=0){return new Uint8Array(e)}function bt(e=0){return new Uint8Array(e)}function Cc(e){return e?.buffer instanceof ArrayBuffer}function Mo(e){if(Cc(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function fe(e,t){t==null&&(t=e.reduce((s,o)=>s+o.length,0));let r=bt(t),n=0;for(let s of e)r.set(s,n),n+=s.length;return Mo(r)}var Ho=Symbol.for("@achingbrain/uint8arraylist");function qo(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let s=r+n.byteLength;if(t<s)return{buf:n,index:t-r};r=s}throw new RangeError("index is out of bounds")}function Or(e){return!!e?.[Ho]}var st=class e{bufs;length;[Ho]=!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(Or(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}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(Or(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=qo(this.bufs,t);return r.buf[r.index]}set(t,r){let n=qo(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(Or(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:s}=this._subList(t,r);return fe(n,s)}subarray(t,r){let{bufs:n,length:s}=this._subList(t,r);return n.length===1?n[0]:fe(n,s)}sublist(t,r){let{bufs:n,length:s}=this._subList(t,r),o=new e;return o.length=s,o.bufs=n,o}_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=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Or(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 s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let l=0;l<o;l++)i[l]=-1;for(let l=0;l<s;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let d=this.get(l+h);if(n[h]!==d){f=Math.max(1,h-a[d]);break}}if(f===0)return l}return-1}getInt8(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 s=Ot(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,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 s=Ot(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,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 s=Ot(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,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 s=Ot(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,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 s=Ot(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,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 s=Ot(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,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 s=Ot(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,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 s=Ot(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,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((s,o)=>s+o.byteLength,0)),n.length=r,n}};var _n={};pt(_n,{base10:()=>kc});var kc=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var Rn={};pt(Rn,{base16:()=>Pc,base16upper:()=>Oc});var Pc=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Oc=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Dn={};pt(Dn,{base2:()=>Nc});var Nc=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Cn={};pt(Cn,{base256emoji:()=>qc});var Vo=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}"),Fc=Vo.reduce((e,t,r)=>(e[r]=t,e),[]),Kc=Vo.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+=Fc[r],t),"")}function Mc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Kc[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(s)}return new Uint8Array(t)}var qc=Te({prefix:"\u{1F680}",name:"base256emoji",encode:Uc,decode:Mc});var kn={};pt(kn,{base64:()=>Hc,base64pad:()=>Vc,base64url:()=>zc,base64urlpad:()=>jc});var Hc=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Vc=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),zc=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),jc=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Pn={};pt(Pn,{base8:()=>$c});var $c=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var On={};pt(On,{identity:()=>Zc});var Zc=Te({prefix:"\0",name:"identity",encode:e=>Bo(xt(e)),decode:e=>xt(Io(e))});var uh=new TextEncoder,fh=new TextDecoder;var Kn={};pt(Kn,{sha256:()=>le,sha512:()=>Wc});var Xc=20;function Fn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:s}){return new Nn(e,t,r,n,s)}var Nn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,s,o){this.name=t,this.code=r,this.encode=n,this.minDigestLength=s??Xc,this.maxDigestLength=o}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?zo(n,this.code,r?.truncate):n.then(s=>zo(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function zo(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 Rt(t,e)}function $o(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var le=Fn({name:"sha2-256",code:18,encode:$o("SHA-256")}),Wc=Fn({name:"sha2-512",code:19,encode:$o("SHA-512")});var Un={...On,...Dn,...Pn,..._n,...Rn,...An,...In,...vn,...kn,...Cn},Sh={...Kn,...Tn};function Yo(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Zo=Yo("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Mn=Yo("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}),Jc={utf8:Zo,"utf-8":Zo,hex:Un.base16,latin1:Mn,ascii:Mn,binary:Mn,...Un},Nr=Jc;function z(e,t="utf8"){let r=Nr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function V(e,t="utf8"){let r=Nr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Qc=parseInt("11111",2),qn=parseInt("10000000",2),tu=parseInt("01111111",2),Go={0:tr,1:tr,2:eu,3:su,4:ou,5:nu,6:ru,16:tr,22:tr,48:tr};function Nt(e,t={offset:0}){let r=e[t.offset]&Qc;if(t.offset++,Go[r]!=null)return Go[r](e,t);throw new Error("No decoder for tag "+r)}function er(e,t){let r=0;if((e[t.offset]&qn)===qn){let n=e[t.offset]&tu,s="0x";t.offset++;for(let o=0;o<n;o++,t.offset++)s+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(s,16)}else r=e[t.offset],t.offset++;return r}function tr(e,t){er(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Nt(e,t);if(n===null)break;r.push(n)}return r}function eu(e,t){let r=er(e,t),n=t.offset,s=t.offset+r,o=[];for(let i=n;i<s;i++)i===n&&e[i]===0||o.push(e[i]);return t.offset+=r,Uint8Array.from(o)}function ru(e,t){let r=er(e,t),n=t.offset+r,s=e[t.offset];t.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function nu(e,t){return t.offset++,null}function su(e,t){let r=er(e,t),n=e[t.offset];t.offset++;let s=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 s}function ou(e,t){let r=er(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function iu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new st;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Hn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=iu(e.byteLength);return new st(Uint8Array.from([t.byteLength|qn]),t)}function yt(e){let t=new st,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new st(Uint8Array.from([2]),Hn(t),t)}function Fr(e){let t=Uint8Array.from([0]),r=new st(t,e);return new st(Uint8Array.from([3]),Hn(r),r)}function Zt(e,t=48){let r=new st;for(let n of e)r.append(n);return new st(Uint8Array.from([t]),Hn(r),r)}var au=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),cu=Uint8Array.from([6,5,43,129,4,0,34]),uu=Uint8Array.from([6,5,43,129,4,0,35]),fu={ext:!0,kty:"EC",crv:"P-256"},lu={ext:!0,kty:"EC",crv:"P-384"},hu={ext:!0,kty:"EC",crv:"P-521"},Vn=32,zn=48,jn=66;function $n(e){let t=Nt(e);return Xo(t)}function Xo(e){let t=e[1][1][0],r=1,n,s;if(t.byteLength===Vn*2+1)return n=V(t.subarray(r,r+Vn),"base64url"),s=V(t.subarray(r+Vn),"base64url"),new ke({...fu,key_ops:["verify"],x:n,y:s});if(t.byteLength===zn*2+1)return n=V(t.subarray(r,r+zn),"base64url"),s=V(t.subarray(r+zn),"base64url"),new ke({...lu,key_ops:["verify"],x:n,y:s});if(t.byteLength===jn*2+1)return n=V(t.subarray(r,r+jn),"base64url"),s=V(t.subarray(r+jn),"base64url"),new ke({...hu,key_ops:["verify"],x:n,y:s});throw new $(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Wo(e){return Zt([yt(Uint8Array.from([1])),Zt([du(e.crv)],160),Zt([Fr(new st(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function du(e){if(e==="P-256")return au;if(e==="P-384")return cu;if(e==="P-521")return uu;throw new $(`Invalid curve ${e}`)}var ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Wo(this.jwk)),this._raw}toMultihash(){return vt.digest(Ft(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}async verify(t,r,n){return Uo(this.jwk,r,t,n)}};function Zn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Yt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function gt(e,t,r=""){let n=Zn(e),s=e?.length,o=t!==void 0;if(!n||o&&s!==t){let i=r&&`"${r}" `,a=o?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof e}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return e}function Kr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Yt(e.outputLen),Yt(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Pe(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 Ur(e,t){gt(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Ut(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Mr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function At(e,t){return e<<32-t|e>>>t}var Qo=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",pu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function qr(e){if(gt(e),Qo)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=pu[e[r]];return t}var Kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Jo(e){if(e>=Kt._0&&e<=Kt._9)return e-Kt._0;if(e>=Kt.A&&e<=Kt.F)return e-(Kt.A-10);if(e>=Kt.a&&e<=Kt.f)return e-(Kt.a-10)}function rr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Qo)try{return Uint8Array.fromHex(e)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=Jo(e.charCodeAt(o)),a=Jo(e.charCodeAt(o+1));if(i===void 0||a===void 0){let c=e[o]+e[o+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function Yn(...e){let t=0;for(let n=0;n<e.length;n++){let s=e[n];gt(s),t+=s.length}let r=new Uint8Array(t);for(let n=0,s=0;n<e.length;n++){let o=e[n];r.set(o,s),s+=o.length}return r}function Gn(e,t={}){let r=(s,o)=>e(o).update(s).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>e(s),Object.assign(r,t),Object.freeze(r)}function ti(e=32){Yt(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Xn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ei(e,t,r){return e&t^~e&r}function ri(e,t,r){return e&t^e&r^t&r}var nr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,s){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Mr(this.buffer)}update(t){Pe(this),gt(t);let{view:r,buffer:n,blockLen:s}=this,o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=Mr(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Pe(this),Ur(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,Ut(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let l=i;l<s;l++)r[l]=0;n.setBigUint64(s-8,BigInt(this.length*8),o),this.process(n,0);let a=Mr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],o)}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:s,finished:o,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=o,t.length=s,t.pos=a,s%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=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 Hr=BigInt(4294967295),ni=BigInt(32);function mu(e,t=!1){return t?{h:Number(e&Hr),l:Number(e>>ni&Hr)}:{h:Number(e>>ni&Hr)|0,l:Number(e&Hr)|0}}function si(e,t=!1){let r=e.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=mu(e[o],t);[n[o],s[o]]=[i,a]}return[n,s]}var Wn=(e,t,r)=>e>>>r,Jn=(e,t,r)=>e<<32-r|t>>>r,he=(e,t,r)=>e>>>r|t<<32-r,de=(e,t,r)=>e<<32-r|t>>>r,sr=(e,t,r)=>e<<64-r|t>>>r-32,or=(e,t,r)=>e>>>r-32|t<<64-r;function Dt(e,t,r,n){let s=(t>>>0)+(n>>>0);return{h:e+r+(s/2**32|0)|0,l:s|0}}var oi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ii=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ai=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ci=(e,t,r,n,s)=>t+r+n+s+(e/2**32|0)|0,ui=(e,t,r,n,s)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(s>>>0),fi=(e,t,r,n,s,o)=>t+r+n+s+o+(e/2**32|0)|0;var yu=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]),Gt=new Uint32Array(64),Qn=class extends nr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,r,n,s,o,i,a,c]}set(t,r,n,s,o,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)Gt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let h=Gt[l-15],d=Gt[l-2],g=At(h,7)^At(h,18)^h>>>3,E=At(d,17)^At(d,19)^d>>>10;Gt[l]=E+Gt[l-7]+g+Gt[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=At(a,6)^At(a,11)^At(a,25),d=f+h+ei(a,c,u)+yu[l]+Gt[l]|0,E=(At(n,2)^At(n,13)^At(n,22))+ri(n,s,o)|0;f=u,u=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+E|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){Ut(Gt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}},ts=class extends Qn{A=Mt[0]|0;B=Mt[1]|0;C=Mt[2]|0;D=Mt[3]|0;E=Mt[4]|0;F=Mt[5]|0;G=Mt[6]|0;H=Mt[7]|0;constructor(){super(32)}};var li=si(["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))),gu=li[0],wu=li[1],Xt=new Uint32Array(80),Wt=new Uint32Array(80),es=class extends nr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:d,Gl:g,Hh:E,Hl:b}=this;return[t,r,n,s,o,i,a,c,u,f,l,h,d,g,E,b]}set(t,r,n,s,o,i,a,c,u,f,l,h,d,g,E,b){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=g|0,this.Hh=E|0,this.Hl=b|0}process(t,r){for(let I=0;I<16;I++,r+=4)Xt[I]=t.getUint32(r),Wt[I]=t.getUint32(r+=4);for(let I=16;I<80;I++){let C=Xt[I-15]|0,_=Wt[I-15]|0,O=he(C,_,1)^he(C,_,8)^Wn(C,_,7),D=de(C,_,1)^de(C,_,8)^Jn(C,_,7),B=Xt[I-2]|0,N=Wt[I-2]|0,F=he(B,N,19)^sr(B,N,61)^Wn(B,N,6),P=de(B,N,19)^or(B,N,61)^Jn(B,N,6),p=ai(D,P,Wt[I-7],Wt[I-16]),y=ci(p,O,F,Xt[I-7],Xt[I-16]);Xt[I]=y|0,Wt[I]=p|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:d,Fl:g,Gh:E,Gl:b,Hh:m,Hl:S}=this;for(let I=0;I<80;I++){let C=he(l,h,14)^he(l,h,18)^sr(l,h,41),_=de(l,h,14)^de(l,h,18)^or(l,h,41),O=l&d^~l&E,D=h&g^~h&b,B=ui(S,_,D,wu[I],Wt[I]),N=fi(B,m,C,O,gu[I],Xt[I]),F=B|0,P=he(n,s,28)^sr(n,s,34)^sr(n,s,39),p=de(n,s,28)^or(n,s,34)^or(n,s,39),y=n&o^n&a^o&a,v=s&i^s&c^i&c;m=E|0,S=b|0,E=d|0,b=g|0,d=l|0,g=h|0,{h:l,l:h}=Dt(u|0,f|0,N|0,F|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let x=oi(F,p,v);n=ii(x,N,P,y),s=x|0}({h:n,l:s}=Dt(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Dt(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Dt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Dt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=Dt(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:g}=Dt(this.Fh|0,this.Fl|0,d|0,g|0),{h:E,l:b}=Dt(this.Gh|0,this.Gl|0,E|0,b|0),{h:m,l:S}=Dt(this.Hh|0,this.Hl|0,m|0,S|0),this.set(n,s,o,i,a,c,u,f,l,h,d,g,E,b,m,S)}roundClean(){Ut(Xt,Wt)}destroy(){this.destroyed=!0,Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},rs=class extends es{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 Oe=Gn(()=>new ts,Xn(1));var Vr=Gn(()=>new rs,Xn(3));var M=(e,t,r)=>gt(e,t,r),ss=Yt,Ne=qr,et=(...e)=>Yn(...e),Fe=e=>rr(e),pe=Zn,ir=e=>ti(e),jr=BigInt(0),ns=BigInt(1);function It(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function $r(e){if(typeof e=="bigint"){if(!zr(e))throw new RangeError("positive bigint expected, got "+e)}else ss(e);return e}function Bt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function ar(e){let t=$r(e).toString(16);return t.length&1?"0"+t:t}function hi(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?jr:BigInt("0x"+e)}function me(e){return hi(qr(e))}function Ct(e){return hi(qr(cr(gt(e)).reverse()))}function Zr(e,t){if(Yt(t),t===0)throw new RangeError("zero length");e=$r(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return rr(r.padStart(t*2,"0"))}function os(e,t){return Zr(e,t).reverse()}function di(e,t){if(e=M(e),t=M(t),e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function cr(e){return Uint8Array.from(M(e))}function Yr(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var zr=e=>typeof e=="bigint"&&jr<=e;function xu(e,t,r){return zr(e)&&zr(t)&&zr(r)&&t<=e&&e<r}function Ke(e,t,r,n){if(!xu(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ue(e){if(e<jr)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>jr;e>>=ns,t+=1);return t}var ur=e=>(ns<<BigInt(e))-ns;function pi(e,t,r){if(Yt(e,"hashLen"),Yt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=b=>new Uint8Array(b),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...b)=>r(u,et(c,...b)),d=(b=s)=>{u=h(o,b),c=h(),b.length!==0&&(u=h(i,b),c=h())},g=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let b=0,m=[];for(;b<t;){c=h();let S=c.slice();m.push(S),b+=c.length}return et(...m)};return(b,m)=>{l(),d(b);let S;for(;(S=m(g()))===void 0;)d();return l(),S}}function Lt(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(o,i,a){if(!a&&i!=="function"&&!Object.hasOwn(e,o))throw new TypeError(`param "${o}" is invalid: expected own property`);let c=e[o];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${o}" is invalid: expected ${i}, got ${u}`)}let s=(o,i)=>Object.entries(o).forEach(([a,c])=>n(a,c,i));s(t,!1),s(r,!0)}var is=()=>{throw new Error("not implemented")};var at=BigInt(0),X=BigInt(1),be=BigInt(2),gi=BigInt(3),wi=BigInt(4),xi=BigInt(5),Eu=BigInt(7),Ei=BigInt(8),Su=BigInt(9),Si=BigInt(16);function Q(e,t){if(t<=at)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=at?r:t+r}function j(e,t,r){if(t<at)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >at;)n*=n,n%=r;return n}function mi(e,t){if(e===at)throw new Error("invert: expected non-zero number");if(t<=at)throw new Error("invert: expected positive modulus, got "+t);let r=Q(e,t),n=t,s=at,o=X,i=X,a=at;for(;r!==at;){let u=n/r,f=n-r*u,l=s-i*u,h=o-a*u;n=r,r=f,s=i,o=a,i=l,a=h}if(n!==X)throw new Error("invert: does not exist");return Q(s,t)}function as(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function vi(e,t){let r=e,n=(r.ORDER+X)/wi,s=r.pow(t,n);return as(r,s,t),s}function vu(e,t){let r=e,n=(r.ORDER-xi)/Ei,s=r.mul(t,be),o=r.pow(s,n),i=r.mul(t,o),a=r.mul(r.mul(i,be),o),c=r.mul(i,r.sub(a,r.ONE));return as(r,c,t),c}function Au(e){let t=Me(e),r=Ai(e),n=r(t,t.neg(t.ONE)),s=r(t,n),o=r(t,t.neg(n)),i=(e+Eu)/Si;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),h=u.mul(f,s),d=u.mul(f,o),g=u.eql(u.sqr(l),c),E=u.eql(u.sqr(h),c);f=u.cmov(f,l,g),l=u.cmov(d,h,E);let b=u.eql(u.sqr(l),c),m=u.cmov(f,l,b);return as(u,m,c),m})}function Ai(e){if(e<gi)throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%be===at;)t/=be,r++;let n=be,s=Me(e);for(;bi(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return vi;let o=s.pow(n,t),i=(t+X)/be;return function(c,u){let f=c;if(f.is0(u))return u;if(bi(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,o),d=f.pow(u,t),g=f.pow(u,i);for(;!f.eql(d,f.ONE);){if(f.is0(d))return f.ZERO;let E=1,b=f.sqr(d);for(;!f.eql(b,f.ONE);)if(E++,b=f.sqr(b),E===l)throw new Error("Cannot find square root");let m=X<<BigInt(l-E-1),S=f.pow(h,m);l=E,h=f.sqr(S),d=f.mul(d,h),g=f.mul(g,S)}return g}}function Iu(e){return e%wi===gi?vi:e%Ei===xi?vu:e%Si===Su?Au(e):Ai(e)}var qt=(e,t)=>(Q(e,t)&X)===X,Bu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function cs(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Bu.reduce((n,s)=>(n[s]="function",n),t);if(Lt(e,r),Bt(e.BYTES,"BYTES"),Bt(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Lu(e,t,r){let n=e;if(r<at)throw new Error("invalid exponent, negatives unsupported");if(r===at)return n.ONE;if(r===X)return t;let s=n.ONE,o=t;for(;r>at;)r&X&&(s=n.mul(s,o)),o=n.sqr(o),r>>=X;return s}function fr(e,t,r=!1){let n=e,s=new Array(t.length).fill(r?n.ZERO:void 0),o=t.reduce((a,c,u)=>n.is0(c)?a:(s[u]=a,n.mul(a,c)),n.ONE),i=n.inv(o);return t.reduceRight((a,c,u)=>n.is0(c)?a:(s[u]=n.mul(a,s[u]),n.mul(a,c)),i),s}function bi(e,t){let r=e,n=(r.ORDER-X)/be,s=r.pow(t,n),o=r.eql(s,r.ONE),i=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!o&&!i&&!a)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function Tu(e,t){if(t!==void 0&&ss(t),e<=at)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=Ue(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var yi=new WeakMap,Gr=class{ORDER;BITS;BYTES;isLE;ZERO=at;ONE=X;_lengths;_mod;constructor(t,r={}){if(t<=X)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:o}=Tu(t,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=o,Object.freeze(this)}create(t){return Q(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return at<=t&&t<this.ORDER}is0(t){return t===at}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&X)===X}neg(t){return Q(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return Q(t*t,this.ORDER)}add(t,r){return Q(t+r,this.ORDER)}sub(t,r){return Q(t-r,this.ORDER)}mul(t,r){return Q(t*r,this.ORDER)}pow(t,r){return Lu(this,t,r)}div(t,r){return Q(t*mi(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 mi(t,this.ORDER)}sqrt(t){let r=yi.get(this);return r||yi.set(this,r=Iu(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?os(t,this.BYTES):Zr(t,this.BYTES)}fromBytes(t,r=!1){M(t);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!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,o?0:u.length-t.length),t=u}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=o?Ct(t):me(t);if(a&&(c=Q(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return fr(this,t)}cmov(t,r,n){return It(n,"condition"),n?r:t}};Object.freeze(Gr.prototype);function Me(e,t={}){return new Gr(e,t)}function Ii(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=X)throw new Error("field order must be greater than 1");let t=Ue(e-X);return Math.ceil(t/8)}function us(e){let t=Ii(e);return t+Math.ceil(t/2)}function fs(e,t,r=!1){M(e);let n=e.length,s=Ii(t),o=Math.max(us(t),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?Ct(e):me(e),a=Q(i,t-X)+X;return r?os(a,s):Zr(a,s)}var qe=BigInt(0),ye=BigInt(1);function lr(e,t){let r=t.negate();return e?r:t}function ge(e,t){let r=fr(e.Fp,t.map(n=>n.Z));return t.map((n,s)=>e.fromAffine(n.toAffine(r[s])))}function _i(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function ls(e,t){_i(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),s=2**e,o=ur(e),i=BigInt(e);return{windows:r,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function Bi(e,t,r){let{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=r,a=Number(e&s),c=e>>i;a>n&&(a-=o,c+=ye);let u=t*n,f=u+Math.abs(a)-1,l=a===0,h=a<0,d=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:h,isNegF:d,offsetF:u}}var hs=new WeakMap,Ri=new WeakMap;function ds(e){return Ri.get(e)||1}function Li(e){if(e!==qe)throw new Error("invalid wNAF")}var He=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 s=t;for(;r>qe;)r&ye&&(n=n.add(s)),s=s.double(),r>>=ye;return n}precomputeWindow(t,r){let{windows:n,windowSize:s}=ls(r,this.bits),o=[],i=t,a=i;for(let c=0;c<n;c++){a=i,o.push(a);for(let u=1;u<s;u++)a=a.add(i),o.push(a);i=a.double()}return o}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE,i=ls(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:h,offsetF:d}=Bi(n,a,i);n=c,f?o=o.add(lr(h,r[d])):s=s.add(lr(l,r[u]))}return Li(n),{p:s,f:o}}wNAFUnsafe(t,r,n,s=this.ZERO){let o=ls(t,this.bits);for(let i=0;i<o.windows&&n!==qe;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Bi(n,i,o);if(n=a,!u){let l=r[c];s=s.add(f?l.negate():l)}}return Li(n),s}getPrecomputes(t,r,n){let s=hs.get(r);return s||(s=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(s=n(s)),hs.set(r,s))),s}cached(t,r,n){let s=ds(t);return this.wNAF(s,this.getPrecomputes(s,t,n),r)}unsafe(t,r,n,s){let o=ds(t);return o===1?this._unsafeLadder(t,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,t,n),r,s)}createCache(t,r){_i(r,this.bits),Ri.set(t,r),hs.delete(t)}hasCache(t){return ds(t)!==1}};function Di(e,t,r,n){let s=t,o=e.ZERO,i=e.ZERO;for(;r>qe||n>qe;)r&ye&&(o=o.add(s)),n&ye&&(i=i.add(s)),s=s.double(),r>>=ye,n>>=ye;return{p1:o,p2:i}}function Ti(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return cs(t),t}else return Me(e,{isLE:r})}function Xr(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 c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>qe))throw new Error(`CURVE.${c} must be positive bigint`)}let s=Ti(t.p,r.Fp,n),o=Ti(t.n,r.Fn,n),a=["Gx","Gy","a",e==="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:o}}function Wr(e,t){return function(n){let s=e(n);return{secretKey:s,publicKey:t(s)}}}var Jt=BigInt(0),ot=BigInt(1),ps=BigInt(2),_u=BigInt(8);function Ru(e,t,r,n){let s=e.sqr(r),o=e.sqr(n),i=e.add(e.mul(t.a,s),o),a=e.add(e.ONE,e.mul(t.d,e.mul(s,o)));return e.eql(i,a)}function Ci(e,t={}){let r=t,n=Xr("edwards",e,r,r.FpFnLE),{Fp:s,Fn:o}=n,i=n.CURVE,{h:a}=i;Lt(r,{},{uvRatio:"function"});let c=ps<<BigInt(o.BYTES*8)-ot,u=E=>s.create(E),f=r.uvRatio===void 0?(E,b)=>{try{return{isValid:!0,value:s.sqrt(s.div(E,b))}}catch{return{isValid:!1,value:Jt}}}:r.uvRatio;if(!Ru(s,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(E,b,m=!1){let S=m?ot:Jt;return Ke("coordinate "+E,b,S,c),b}function h(E){if(!(E instanceof d))throw new Error("EdwardsPoint expected")}class d{static BASE=new d(i.Gx,i.Gy,ot,u(i.Gx*i.Gy));static ZERO=new d(Jt,ot,ot,Jt);static Fp=s;static Fn=o;X;Y;Z;T;constructor(b,m,S,I){this.X=l("x",b),this.Y=l("y",m),this.Z=l("z",S,!0),this.T=l("t",I),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){if(b instanceof d)throw new Error("extended point not allowed");let{x:m,y:S}=b||{};return l("x",m),l("y",S),new d(m,S,ot,u(m*S))}static fromBytes(b,m=!1){let S=s.BYTES,{a:I,d:C}=i;b=cr(M(b,S,"point")),It(m,"zip215");let _=cr(b),O=b[S-1];_[S-1]=O&-129;let D=Ct(_),B=m?c:s.ORDER;Ke("point.y",D,Jt,B);let N=u(D*D),F=u(N-ot),P=u(C*N-I),{isValid:p,value:y}=f(F,P);if(!p)throw new Error("bad point: invalid y coordinate");let v=(y&ot)===ot,x=(O&128)!==0;if(!m&&y===Jt&&x)throw new Error("bad point: x=0 and x_0=1");return x!==v&&(y=u(-y)),d.fromAffine({x:y,y:D})}static fromHex(b,m=!1){return d.fromBytes(Fe(b),m)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return g.createCache(this,b),m||this.multiply(ps),this}assertValidity(){let b=this,{a:m,d:S}=i;if(b.is0())throw new Error("bad point: ZERO");let{X:I,Y:C,Z:_,T:O}=b,D=u(I*I),B=u(C*C),N=u(_*_),F=u(N*N),P=u(D*m),p=u(N*u(P+B)),y=u(F+u(S*u(D*B)));if(p!==y)throw new Error("bad point: equation left != right (1)");let v=u(I*C),x=u(_*O);if(v!==x)throw new Error("bad point: equation left != right (2)")}equals(b){h(b);let{X:m,Y:S,Z:I}=this,{X:C,Y:_,Z:O}=b,D=u(m*O),B=u(C*I),N=u(S*O),F=u(_*I);return D===B&&N===F}is0(){return this.equals(d.ZERO)}negate(){return new d(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:b}=i,{X:m,Y:S,Z:I}=this,C=u(m*m),_=u(S*S),O=u(ps*u(I*I)),D=u(b*C),B=m+S,N=u(u(B*B)-C-_),F=D+_,P=F-O,p=D-_,y=u(N*P),v=u(F*p),x=u(N*p),w=u(P*F);return new d(y,v,w,x)}add(b){h(b);let{a:m,d:S}=i,{X:I,Y:C,Z:_,T:O}=this,{X:D,Y:B,Z:N,T:F}=b,P=u(I*D),p=u(C*B),y=u(O*S*F),v=u(_*N),x=u((I+C)*(D+B)-P-p),w=v-y,A=v+y,T=u(p-m*P),L=u(x*w),R=u(A*T),k=u(x*T),U=u(w*A);return new d(L,R,U,k)}subtract(b){return h(b),this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:m,f:S}=g.cached(this,b,I=>ge(d,I));return ge(d,[m,S])[0]}multiplyUnsafe(b){if(!o.isValid(b))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return b===Jt?d.ZERO:this.is0()||b===ot?this:g.unsafe(this,b,m=>ge(d,m))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return g.unsafe(this,i.n).is0()}toAffine(b){let m=this,S=b,{X:I,Y:C,Z:_}=m,O=m.is0();S==null&&(S=O?_u:s.inv(_));let D=u(I*S),B=u(C*S),N=s.mul(_,S);if(O)return{x:Jt,y:ot};if(N!==ot)throw new Error("invZ was invalid");return{x:D,y:B}}clearCofactor(){return a===ot?this:this.multiplyUnsafe(a)}toBytes(){let{x:b,y:m}=this.toAffine(),S=s.toBytes(m);return S[S.length-1]|=b&ot?128:0,S}toHex(){return Ne(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let g=new He(d,o.BITS);return o.BITS>=8&&d.BASE.precompute(8),Object.freeze(d.prototype),Object.freeze(d),d}var Jr=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){is()}static fromHex(t){is()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Ne(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function ki(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,s=r;Lt(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:o}=s,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Bt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=s.randomBytes===void 0?ir:s.randomBytes,h=s.adjustScalarBytes===void 0?p=>p:s.adjustScalarBytes,d=s.domain===void 0?(p,y,v)=>{if(It(v,"phflag"),y.length||v)throw new Error("Contexts/pre-hash are not supported");return p}:s.domain;function g(p){return c.create(Ct(p))}function E(p){let y=D.secretKey;M(p,D.secretKey,"secretKey");let v=M(n(p),2*y,"hashedSecretKey"),x=h(v.slice(0,y)),w=v.slice(y,2*y),A=g(x);return{head:x,prefix:w,scalar:A}}function b(p){let{head:y,prefix:v,scalar:x}=E(p),w=i.multiply(x),A=w.toBytes();return{head:y,prefix:v,scalar:x,point:w,pointBytes:A}}function m(p){return b(p).pointBytes}function S(p=Uint8Array.of(),...y){let v=et(...y);return g(n(d(v,M(p,void 0,"context"),!!o)))}function I(p,y,v={}){p=M(p,void 0,"message"),o&&(p=o(p));let{prefix:x,scalar:w,pointBytes:A}=b(y),T=S(v.context,x,p),L=i.multiply(T).toBytes(),R=S(v.context,L,A,p),k=c.create(T+R*w);if(!c.isValid(k))throw new Error("sign failed: invalid s");let U=et(L,c.toBytes(k));return M(U,D.signature,"result")}let C={zip215:s.zip215};function _(p,y,v,x=C){let{context:w}=x,A=x.zip215===void 0?!!C.zip215:x.zip215,T=D.signature;p=M(p,T,"signature"),y=M(y,void 0,"message"),v=M(v,D.publicKey,"publicKey"),A!==void 0&&It(A,"zip215"),o&&(y=o(y));let L=T/2,R=p.subarray(0,L),k=Ct(p.subarray(L,T)),U,q,K;try{U=e.fromBytes(v,A),q=e.fromBytes(R,A),K=i.multiplyUnsafe(k)}catch{return!1}if(!A&&U.isSmallOrder())return!1;let tt=S(w,R,v,y);return q.add(U.multiplyUnsafe(tt)).subtract(K).clearCofactor().is0()}let O=a.BYTES,D={secretKey:O,publicKey:O,signature:2*O,seed:O};function B(p){return p=p===void 0?l(D.seed):p,M(p,D.seed,"seed")}function N(p){return pe(p)&&p.length===D.secretKey}function F(p,y){try{return!!e.fromBytes(p,y===void 0?C.zip215:y)}catch{return!1}}let P={getExtendedPublicKey:b,randomSecretKey:B,isValidSecretKey:N,isValidPublicKey:F,toMontgomery(p){let{y}=e.fromBytes(p),v=D.publicKey,x=v===32;if(!x&&v!==57)throw new Error("only defined for 25519 and 448");let w=x?a.div(ot+y,ot-y):a.div(y-ot,y+ot);return a.toBytes(w)},toMontgomerySecret(p){let y=D.secretKey;M(p,y);let v=n(p.subarray(0,y));return h(v).subarray(0,y)}};return Object.freeze(D),Object.freeze(P),Object.freeze({keygen:Wr(B,m),getPublicKey:m,sign:I,verify:_,utils:P,Point:e,lengths:D})}function hr(e,t){if(Bt(e),Bt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function Du(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function Cu(e){if(!pe(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?Yr(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function ms(e,t,r,n){M(e),Bt(r),t=Cu(t),t.length>255&&(t=n(et(Yr("H2C-OVERSIZE-DST-"),t)));let{outputLen:s,blockLen:o}=n,i=Math.ceil(r/s);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=et(t,hr(t.length,1)),c=new Uint8Array(o),u=hr(r,2),f=new Array(i),l=n(et(c,e,u,hr(0,1),a));f[0]=n(et(l,hr(1,1),a));for(let d=1;d<i;d++){let g=[Du(l,f[d-1]),hr(d+1,1),a];f[d]=n(et(...g))}return et(...f).slice(0,r)}var Pi="HashToScalar-";var ku=BigInt(0),Ht=BigInt(1),Oi=BigInt(2);var Pu=BigInt(5),Ou=BigInt(8),Ve=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ws={p:Ve,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ou,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Nu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=Ve,a=e*e%o*e%o,c=j(a,Oi,o)*a%o,u=j(c,Ht,o)*e%o,f=j(u,Pu,o)*u%o,l=j(f,t,o)*f%o,h=j(l,r,o)*l%o,d=j(h,n,o)*h%o,g=j(d,s,o)*d%o,E=j(g,s,o)*d%o,b=j(E,t,o)*f%o;return{pow_p_5_8:j(b,Oi,o)*e%o,b2:a}}function Fu(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var bs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function xs(e,t){let r=Ve,n=Q(t*t*t,r),s=Q(n*n*t,r),o=Nu(e*s).pow_p_5_8,i=Q(e*n*o,r),a=Q(t*i*i,r),c=i,u=Q(i*bs,r),f=a===e,l=a===Q(-e,r),h=a===Q(-e*bs,r);return f&&(i=c),(l||h)&&(i=u),qt(i,r)&&(i=Q(-i,r)),{isValid:f||l,value:i}}var te=Ci(ws,{uvRatio:xs}),Qt=te.Fp,Ki=te.Fn;function Ku(e){return ki(te,Vr,Object.assign({adjustScalarBytes:Fu,zip215:!0},e))}var Ui=Ku({});var ys=bs,Uu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Mu=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),qu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Hu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ni=e=>xs(Ht,e),Vu=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),gs=e=>Qt.create(Ct(e)&Vu);function Fi(e){let{d:t}=ws,r=Ve,n=m=>Qt.create(m),s=n(ys*e*e),o=n((s+Ht)*qu),i=BigInt(-1),a=n((i-t*s)*n(s+t)),{isValid:c,value:u}=xs(o,a),f=n(u*e);qt(f,r)||(f=n(-f)),c||(u=f),c||(i=s);let l=n(i*(s-Ht)*Hu-a),h=u*u,d=n((u+u)*a),g=n(l*Uu),E=n(Ht-h),b=n(Ht+h);return new te(n(d*b),n(E*g),n(g*b),n(d*E))}var ee=class e extends Jr{static BASE=new e(te.BASE);static ZERO=new e(te.ZERO);static Fp=Qt;static Fn=Ki;constructor(t){super(t)}static fromAffine(t){return new e(te.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){gt(t,32);let{a:r,d:n}=ws,s=Ve,o=C=>Qt.create(C),i=gs(t);if(!di(Qt.toBytes(i),t)||qt(i,s))throw new Error("invalid ristretto255 encoding 1");let a=o(i*i),c=o(Ht+r*a),u=o(Ht-r*a),f=o(c*c),l=o(u*u),h=o(r*n*f-l),{isValid:d,value:g}=Ni(o(h*l)),E=o(g*u),b=o(g*E*h),m=o((i+i)*E);qt(m,s)&&(m=o(-m));let S=o(c*b),I=o(m*S);if(!d||qt(I,s)||S===ku)throw new Error("invalid ristretto255 encoding 2");return new e(new te(m,S,Ht,I))}static fromHex(t){return e.fromBytes(rr(t))}toBytes(){let{X:t,Y:r,Z:n,T:s}=this.ep,o=Ve,i=b=>Qt.create(b),a=i(i(n+r)*i(n-r)),c=i(t*r),u=i(c*c),{value:f}=Ni(i(a*u)),l=i(f*a),h=i(f*c),d=i(l*h*s),g;if(qt(s*d,o)){let b=i(r*ys),m=i(t*ys);t=b,r=m,g=i(l*Mu)}else g=h;qt(t*d,o)&&(r=i(-r));let E=i((n-r)*g);return qt(E,o)&&(E=i(-E)),Qt.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:s,Y:o}=t.ep,i=u=>Qt.create(u),a=i(r*o)===i(n*s),c=i(n*o)===i(r*s);return a||c}is0(){return this.equals(e.ZERO)}};Object.freeze(ee.BASE);Object.freeze(ee.ZERO);Object.freeze(ee.prototype);Object.freeze(ee);var zu=Object.freeze({Point:ee,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=ms(e,r,64,Vr);return zu.deriveToCurve(n)},hashToScalar(e,t={DST:Pi}){let r=ms(e,t.DST,64,Vr);return Ki.create(Ct(r))},deriveToCurve(e){gt(e,64);let t=gs(e.subarray(0,32)),r=Fi(t),n=gs(e.subarray(32,64)),s=Fi(n);return new ee(r.add(s))}});var dr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Qr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var St={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Qr("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 tn=32;var Es,ju=(async()=>{try{return await St.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function $u(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await St.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await St.get().subtle.verify({name:"Ed25519"},n,Et(t),Et(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Zu(e,t,r){return Ui.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Mi(e,t,r){return Es==null&&(Es=await ju),Es?$u(e,t,r):Zu(e,t,r)}function en(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var rn=class{type="Ed25519";raw;constructor(t){this.raw=Ss(t,tn)}toMultihash(){return vt.digest(Ft(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let s=Mi(this.raw,r,t);return en(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function vs(e){return e=Ss(e,tn),new rn(e)}function Ss(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new $(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Gu=Math.pow(2,7),Xu=Math.pow(2,14),Wu=Math.pow(2,21),As=Math.pow(2,28),Is=Math.pow(2,35),Bs=Math.pow(2,42),Ls=Math.pow(2,49),H=128,ut=127;function Vt(e){if(e<Gu)return 1;if(e<Xu)return 2;if(e<Wu)return 3;if(e<As)return 4;if(e<Is)return 5;if(e<Bs)return 6;if(e<Ls)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ts(e,t,r=0){switch(Vt(e)){case 8:t[r++]=e&255|H,e/=128;case 7:t[r++]=e&255|H,e/=128;case 6:t[r++]=e&255|H,e/=128;case 5:t[r++]=e&255|H,e/=128;case 4:t[r++]=e&255|H,e>>>=7;case 3:t[r++]=e&255|H,e>>>=7;case 2:t[r++]=e&255|H,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ju(e,t,r=0){switch(Vt(e)){case 8:t.set(r++,e&255|H),e/=128;case 7:t.set(r++,e&255|H),e/=128;case 6:t.set(r++,e&255|H),e/=128;case 5:t.set(r++,e&255|H),e/=128;case 4:t.set(r++,e&255|H),e>>>=7;case 3:t.set(r++,e&255|H),e>>>=7;case 2:t.set(r++,e&255|H),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function _s(e,t){let r=e[t],n=0;if(n+=r&ut,r<H||(r=e[t+1],n+=(r&ut)<<7,r<H)||(r=e[t+2],n+=(r&ut)<<14,r<H)||(r=e[t+3],n+=(r&ut)<<21,r<H)||(r=e[t+4],n+=(r&ut)*As,r<H)||(r=e[t+5],n+=(r&ut)*Is,r<H)||(r=e[t+6],n+=(r&ut)*Bs,r<H)||(r=e[t+7],n+=(r&ut)*Ls,r<H))return n;throw new RangeError("Could not decode varint")}function Qu(e,t){let r=e.get(t),n=0;if(n+=r&ut,r<H||(r=e.get(t+1),n+=(r&ut)<<7,r<H)||(r=e.get(t+2),n+=(r&ut)<<14,r<H)||(r=e.get(t+3),n+=(r&ut)<<21,r<H)||(r=e.get(t+4),n+=(r&ut)*As,r<H)||(r=e.get(t+5),n+=(r&ut)*Is,r<H)||(r=e.get(t+6),n+=(r&ut)*Bs,r<H)||(r=e.get(t+7),n+=(r&ut)*Ls,r<H))return n;throw new RangeError("Could not decode varint")}function Hi(e,t,r=0){return t==null&&(t=bt(Vt(e))),t instanceof Uint8Array?Ts(e,t,r):Ju(e,t,r)}function Vi(e,t=0){return e instanceof Uint8Array?_s(e,t):Qu(e,t)}var Rs=new Float32Array([-0]),re=new Uint8Array(Rs.buffer);function zi(e,t,r){Rs[0]=e,t[r]=re[0],t[r+1]=re[1],t[r+2]=re[2],t[r+3]=re[3]}function ji(e,t){return re[0]=e[t],re[1]=e[t+1],re[2]=e[t+2],re[3]=e[t+3],Rs[0]}var Ds=new Float64Array([-0]),ft=new Uint8Array(Ds.buffer);function $i(e,t,r){Ds[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 Zi(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],Ds[0]}var ef=BigInt(Number.MAX_SAFE_INTEGER),rf=BigInt(Number.MIN_SAFE_INTEGER),wt=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 we;if(t<ef&&t>rf)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,s=t-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>Yi&&(s=0n,++n>Yi&&(n=0n))),new e(Number(s),Number(n))}static fromNumber(t){if(t===0)return we;let r=t<0;r&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new e(n,s)}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):we}},we=new wt(0,0);we.toBigInt=function(){return 0n};we.zzEncode=we.zzDecode=function(){return this};we.length=function(){return 1};var Yi=4294967296n;function Gi(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 Xi(e,t,r){if(r-t<1)return"";let s,o=[],i=0,a;for(;t<r;)a=e[t++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function Cs(e,t,r){let n=r,s,o;for(let i=0;i<e.length;++i)s=e.charCodeAt(i),s<128?t[r++]=s:s<2048?(t[r++]=s>>6|192,t[r++]=s&63|128):(s&64512)===55296&&((o=e.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,t[r++]=s>>18|240,t[r++]=s>>12&63|128,t[r++]=s>>6&63|128,t[r++]=s&63|128):(t[r++]=s>>12|224,t[r++]=s>>6&63|128,t[r++]=s&63|128);return r-n}function Tt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function nn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ks=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=Et(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,Tt(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 Tt(this,4);return nn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return nn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=ji(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=Zi(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 Tt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Xi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(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 wt(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 Tt(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 Tt(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 Tt(this,8);let t=nn(this.buf,this.pos+=4),r=nn(this.buf,this.pos+=4);return new wt(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=_s(this.buf,this.pos);return this.pos+=Vt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function pr(e){return new ks(e instanceof Uint8Array?e:e.subarray())}function ne(e,t,r){let n=pr(e);return t.decode(n,void 0,r)}function Ps(e){let t=e??8192,r=t>>>1,n,s=t;return function(i){if(i<1||i>r)return bt(i);s+i>t&&(n=bt(t),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var xe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Os(){}var Fs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},nf=Ps();function sf(e){return globalThis.Buffer!=null?bt(e):nf(e)}var br=class{len;head;tail;states;constructor(){this.len=0,this.head=new xe(Os,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new xe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ks((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(sn,10,wt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=wt.fromBigInt(t);return this._push(sn,r.length(),r)}uint64Number(t){return this._push(Ts,Vt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=wt.fromBigInt(t).zzEncode();return this._push(sn,r.length(),r)}sint64Number(t){let r=wt.fromNumber(t).zzEncode();return this._push(sn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ns,1,t?1:0)}fixed32(t){return this._push(mr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=wt.fromBigInt(t);return this._push(mr,4,r.lo)._push(mr,4,r.hi)}fixed64Number(t){let r=wt.fromNumber(t);return this._push(mr,4,r.lo)._push(mr,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(zi,4,t)}double(t){return this._push($i,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ns,1,0):this.uint32(r)._push(af,r,t)}string(t){let r=Gi(t);return r!==0?this.uint32(r)._push(Cs,r,t):this._push(Ns,1,0)}fork(){return this.states=new Fs(this),this.head=this.tail=new xe(Os,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new xe(Os,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=sf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ns(e,t,r){t[r]=e&255}function of(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ks=class extends xe{next;constructor(t,r){super(of,t,r),this.next=void 0}};function sn(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 mr(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 af(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(br.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(cf,t,e),this},br.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(uf,t,e),this});function cf(e,t,r){t.set(e,r)}function uf(e,t,r){e.length<40?Cs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(z(e),r)}function Us(){return new br}function se(e,t){let r=Us();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*oe(e,t,r){let n=pr(e);yield*t.stream(n,void 0,"$",r)}var on={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function an(e,t,r,n,s){return{name:e,type:t,encode:r,decode:n,stream:s}}function Ms(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},s=function*(i){let a=i.int32();yield t(a)};return an("enum",on.VARINT,r,n,s)}function ie(e,t,r){return an("message",on.LENGTH_DELIMITED,e,t,r)}var Ee=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Y;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Y||(Y={}));var qs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(qs||(qs={}));(function(e){e.codec=()=>Ms(qs)})(Y||(Y={}));var kt;(function(e){let t;e.codec=()=>(t==null&&(t=ie((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),Y.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=Y.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Y.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),t);function r(o){return se(o,e.codec())}e.encode=r;function n(o,i){return ne(o,e.codec(),i)}e.decode=n;function s(o,i){return oe(o,e.codec(),i)}e.stream=s})(kt||(kt={}));var Hs;(function(e){let t;e.codec=()=>(t==null&&(t=ie((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),Y.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=Y.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Y.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),t);function r(o){return se(o,e.codec())}e.encode=r;function n(o,i){return ne(o,e.codec(),i)}e.decode=n;function s(o,i){return oe(o,e.codec(),i)}e.stream=s})(Hs||(Hs={}));var gr={};pt(gr,{MAX_RSA_KEY_SIZE:()=>Vs,generateRSAKeyPair:()=>ra,jwkToJWKKeyPair:()=>na,jwkToPkcs1:()=>df,jwkToPkix:()=>Zs,jwkToRSAPrivateKey:()=>Ws,pkcs1MessageToJwk:()=>js,pkcs1MessageToRSAPrivateKey:()=>Ys,pkcs1ToJwk:()=>hf,pkcs1ToRSAPrivateKey:()=>ea,pkixMessageToJwk:()=>$s,pkixMessageToRSAPublicKey:()=>Xs,pkixToJwk:()=>pf,pkixToRSAPublicKey:()=>Gs});var ze=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=gr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ct.createV1(114,this._multihash)}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,r,n){return ta(this.jwk,r,t,n)}},yr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=gr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}sign(t,r){return Qi(this.jwk,t,r)}};var Vs=8192,zs=18,ff=1062,lf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function hf(e){let t=Nt(e);return js(t)}function js(e){return{n:V(e[1],"base64url"),e:V(e[2],"base64url"),d:V(e[3],"base64url"),p:V(e[4],"base64url"),q:V(e[5],"base64url"),dp:V(e[6],"base64url"),dq:V(e[7],"base64url"),qi:V(e[8],"base64url"),kty:"RSA"}}function df(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new $("JWK was missing components");return Zt([yt(Uint8Array.from([0])),yt(z(e.n,"base64url")),yt(z(e.e,"base64url")),yt(z(e.d,"base64url")),yt(z(e.p,"base64url")),yt(z(e.q,"base64url")),yt(z(e.dp,"base64url")),yt(z(e.dq,"base64url")),yt(z(e.qi,"base64url"))]).subarray()}function pf(e){let t=Nt(e,{offset:0});return $s(t)}function $s(e){let t=Nt(e[1],{offset:0});return{kty:"RSA",n:V(t[0],"base64url"),e:V(t[1],"base64url")}}function Zs(e){if(e.n==null||e.e==null)throw new $("JWK was missing components");return Zt([lf,Fr(Zt([yt(z(e.n,"base64url")),yt(z(e.e,"base64url"))]))]).subarray()}function ea(e){let t=Nt(e);return Ys(t)}function Ys(e){let t=js(e);return Ws(t)}function Gs(e,t){if(e.byteLength>=ff)throw new Be("Key size is too large");let r=Nt(e,{offset:0});return Xs(r,e,t)}function Xs(e,t,r){let n=$s(e);if(r==null){let s=Oe(kt.encode({Type:Y.RSA,Data:t}));r=Rt(zs,s)}return new ze(n,r)}function Ws(e){if(oa(e)>Vs)throw new $("Key size is too large");let t=na(e),r=Oe(kt.encode({Type:Y.RSA,Data:Zs(t.publicKey)})),n=Rt(zs,r);return new yr(t.privateKey,new ze(t.publicKey,n))}async function ra(e){if(e>Vs)throw new $("Key size is too large");let t=await sa(e),r=Oe(kt.encode({Type:Y.RSA,Data:Zs(t.publicKey)})),n=Rt(zs,r);return new yr(t.privateKey,new ze(t.publicKey,n))}function na(e){if(e==null)throw new $("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function sa(e,t){let r=await St.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 mf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Qi(e,t,r){let n=await St.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await St.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Et(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function ta(e,t,r,n){let s=await St.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await St.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,Et(t),Et(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),o}async function mf(e,t){if(e.privateKey==null||e.publicKey==null)throw new $("Private and public key are required");let r=await Promise.all([St.get().subtle.exportKey("jwk",e.privateKey),St.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function oa(e){if(e.kty!=="RSA")throw new $("invalid key type");if(e.n==null)throw new $("invalid key modulus");return z(e.n,"base64url").length*8}var cn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Kr(t),gt(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,s=new Uint8Array(n);s.set(r.length>n?t.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),Ut(s)}update(t){return Pe(this),this.iHash.update(t),this}digestInto(t){Pe(this),Ur(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),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:s,destroyed:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,t.outputLen=a,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()}},ia=(()=>{let e=((t,r,n)=>new cn(t,r).update(n).digest());return e.create=(t,r)=>new cn(t,r),e})();var aa=(e,t)=>(e+(e>=0?t:-t)/ca)/t;function bf(e,t,r){Ke("scalar",e,Pt,r);let[[n,s],[o,i]]=t,a=aa(i*e,r),c=aa(-s*e,r),u=e-a*n-c*o,f=-a*s-c*i,l=u<Pt,h=f<Pt;l&&(u=-u),h&&(f=-f);let d=ur(Math.ceil(Ue(r)/2))+ae;if(u<Pt||u>=d||f<Pt||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function Qs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Js(e,t){Lt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return It(r.lowS,"lowS"),It(r.prehash,"prehash"),r.format!==void 0&&Qs(r.format),r}var to=class extends Error{constructor(t=""){super(t)}},_t={Err:to,_tlv:{encode:(e,t)=>{let{Err:r}=_t;if(Bt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,s=ar(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?ar(s.length/2|128):"";return ar(e)+o+s+t},decode(e,t){let{Err:r}=_t;t=M(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let s=t[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=_t;if($r(e),e<Pt)throw new t("integer: negative integers are not allowed");let r=ar(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}=_t;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return me(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=_t,s=M(e,void 0,"signature"),{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=_t,n=t.encode(2,r.encode(e.r)),s=t.encode(2,r.encode(e.s)),o=n+s;return t.encode(48,o)}};Object.freeze(_t._tlv);Object.freeze(_t._int);Object.freeze(_t);var Pt=BigInt(0),ae=BigInt(1),ca=BigInt(2),un=BigInt(3),yf=BigInt(4);function ua(e,t={}){let r=Xr("weierstrass",e,t),n=r.Fp,s=r.Fn,o=r.CURVE,{h:i,n:a}=o;Lt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=t;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=la(n,s);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(P,p,y){if(u&&p.is0())return Uint8Array.of(0);let{x:v,y:x}=p.toAffine(),w=n.toBytes(v);if(It(y,"isCompressed"),y){l();let A=!n.isOdd(x);return et(fa(A),w)}else return et(Uint8Array.of(4),w,n.toBytes(x))}function d(P){M(P,void 0,"Point");let{publicKey:p,publicKeyUncompressed:y}=f,v=P.length,x=P[0],w=P.subarray(1);if(u&&v===1&&x===0)return{x:n.ZERO,y:n.ZERO};if(v===p&&(x===2||x===3)){let A=n.fromBytes(w);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let T=b(A),L;try{L=n.sqrt(T)}catch(U){let q=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}l();let R=n.isOdd(L);return(x&1)===1!==R&&(L=n.neg(L)),{x:A,y:L}}else if(v===y&&x===4){let A=n.BYTES,T=n.fromBytes(w.subarray(0,A)),L=n.fromBytes(w.subarray(A,A*2));if(!m(T,L))throw new Error("bad point: is not on curve");return{x:T,y:L}}else throw new Error(`bad point: got length ${v}, expected compressed=${p} or uncompressed=${y}`)}let g=t.toBytes===void 0?h:t.toBytes,E=t.fromBytes===void 0?d:t.fromBytes;function b(P){let p=n.sqr(P),y=n.mul(p,P);return n.add(n.add(y,n.mul(P,o.a)),o.b)}function m(P,p){let y=n.sqr(p),v=b(P);return n.eql(y,v)}if(!m(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(o.a,un),yf),I=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(S,I)))throw new Error("bad curve params: a or b");function C(P,p,y=!1){if(!n.isValid(p)||y&&n.is0(p))throw new Error(`bad point coordinate ${P}`);return p}function _(P){if(!(P instanceof B))throw new Error("Weierstrass Point expected")}function O(P){if(!c||!c.basises)throw new Error("no endo");return bf(P,c.basises,s.ORDER)}function D(P,p,y,v,x){return y=new B(n.mul(y.X,P),y.Y,y.Z),p=lr(v,p),y=lr(x,y),p.add(y)}class B{static BASE=new B(o.Gx,o.Gy,n.ONE);static ZERO=new B(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(p,y,v){this.X=C("x",p),this.Y=C("y",y,!0),this.Z=C("z",v),Object.freeze(this)}static CURVE(){return o}static fromAffine(p){let{x:y,y:v}=p||{};if(!p||!n.isValid(y)||!n.isValid(v))throw new Error("invalid affine point");if(p instanceof B)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(v)?B.ZERO:new B(y,v,n.ONE)}static fromBytes(p){let y=B.fromAffine(E(M(p,void 0,"point")));return y.assertValidity(),y}static fromHex(p){return B.fromBytes(Fe(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,y=!0){return F.createCache(this,p),y||this.multiply(un),this}assertValidity(){let p=this;if(p.is0()){if(t.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}let{x:y,y:v}=p.toAffine();if(!n.isValid(y)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!m(y,v))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){_(p);let{X:y,Y:v,Z:x}=this,{X:w,Y:A,Z:T}=p,L=n.eql(n.mul(y,T),n.mul(w,x)),R=n.eql(n.mul(v,T),n.mul(A,x));return L&&R}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{a:p,b:y}=o,v=n.mul(y,un),{X:x,Y:w,Z:A}=this,T=n.ZERO,L=n.ZERO,R=n.ZERO,k=n.mul(x,x),U=n.mul(w,w),q=n.mul(A,A),K=n.mul(x,w);return K=n.add(K,K),R=n.mul(x,A),R=n.add(R,R),T=n.mul(p,R),L=n.mul(v,q),L=n.add(T,L),T=n.sub(U,L),L=n.add(U,L),L=n.mul(T,L),T=n.mul(K,T),R=n.mul(v,R),q=n.mul(p,q),K=n.sub(k,q),K=n.mul(p,K),K=n.add(K,R),R=n.add(k,k),k=n.add(R,k),k=n.add(k,q),k=n.mul(k,K),L=n.add(L,k),q=n.mul(w,A),q=n.add(q,q),k=n.mul(q,K),T=n.sub(T,k),R=n.mul(q,U),R=n.add(R,R),R=n.add(R,R),new B(T,L,R)}add(p){_(p);let{X:y,Y:v,Z:x}=this,{X:w,Y:A,Z:T}=p,L=n.ZERO,R=n.ZERO,k=n.ZERO,U=o.a,q=n.mul(o.b,un),K=n.mul(y,w),tt=n.mul(v,A),rt=n.mul(x,T),nt=n.add(y,v),W=n.add(w,A);nt=n.mul(nt,W),W=n.add(K,tt),nt=n.sub(nt,W),W=n.add(y,x);let dt=n.add(w,T);return W=n.mul(W,dt),dt=n.add(K,rt),W=n.sub(W,dt),dt=n.add(v,x),L=n.add(A,T),dt=n.mul(dt,L),L=n.add(tt,rt),dt=n.sub(dt,L),k=n.mul(U,W),L=n.mul(q,rt),k=n.add(L,k),L=n.sub(tt,k),k=n.add(tt,k),R=n.mul(L,k),tt=n.add(K,K),tt=n.add(tt,K),rt=n.mul(U,rt),W=n.mul(q,W),tt=n.add(tt,rt),rt=n.sub(K,rt),rt=n.mul(U,rt),W=n.add(W,rt),K=n.mul(tt,W),R=n.add(R,K),K=n.mul(dt,W),L=n.mul(nt,L),L=n.sub(L,K),K=n.mul(nt,tt),k=n.mul(dt,k),k=n.add(k,K),new B(L,R,k)}subtract(p){return _(p),this.add(p.negate())}is0(){return this.equals(B.ZERO)}multiply(p){let{endo:y}=t;if(!s.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let v,x,w=A=>F.cached(this,A,T=>ge(B,T));if(y){let{k1neg:A,k1:T,k2neg:L,k2:R}=O(p),{p:k,f:U}=w(T),{p:q,f:K}=w(R);x=U.add(K),v=D(y.beta,k,q,A,L)}else{let{p:A,f:T}=w(p);v=A,x=T}return ge(B,[v,x])[0]}multiplyUnsafe(p){let{endo:y}=t,v=this,x=p;if(!s.isValid(x))throw new RangeError("invalid scalar: out of range");if(x===Pt||v.is0())return B.ZERO;if(x===ae)return v;if(F.hasCache(this))return this.multiply(x);if(y){let{k1neg:w,k1:A,k2neg:T,k2:L}=O(x),{p1:R,p2:k}=Di(B,v,A,L);return D(y.beta,R,k,w,T)}else return F.unsafe(v,x)}toAffine(p){let y=this,v=p,{X:x,Y:w,Z:A}=y;if(n.eql(A,n.ONE))return{x,y:w};let T=y.is0();v==null&&(v=T?n.ONE:n.inv(A));let L=n.mul(x,v),R=n.mul(w,v),k=n.mul(A,v);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(k,n.ONE))throw new Error("invZ was invalid");return{x:L,y:R}}isTorsionFree(){let{isTorsionFree:p}=t;return i===ae?!0:p?p(B,this):F.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=t;return i===ae?this:p?p(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ae?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return It(p,"isCompressed"),this.assertValidity(),g(B,this,p)}toHex(p=!0){return Ne(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=s.BITS,F=new He(B,t.endo?Math.ceil(N/2):N);return N>=8&&B.BASE.precompute(8),Object.freeze(B.prototype),Object.freeze(B),B}function fa(e){return Uint8Array.of(e?2:3)}function la(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function gf(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?ir:t.randomBytes,s=Object.assign(la(e.Fp,r),{seed:Math.max(us(r.ORDER),16)});function o(d){try{let g=r.fromBytes(d);return r.isValidNot0(g)}catch{return!1}}function i(d,g){let{publicKey:E,publicKeyUncompressed:b}=s;try{let m=d.length;return g===!0&&m!==E||g===!1&&m!==b?!1:!!e.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(s.seed):d,fs(M(d,s.seed,"seed"),r.ORDER)}function c(d,g=!0){return e.BASE.multiply(r.fromBytes(d)).toBytes(g)}function u(d){let{secretKey:g,publicKey:E,publicKeyUncompressed:b}=s,m=r._lengths;if(!pe(d))return;let S=M(d,void 0,"key").length,I=S===E||S===b,C=S===g||!!m?.includes(S);if(!(I&&C))return I}function f(d,g,E=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(g)===!1)throw new Error("second arg must be public key");let b=r.fromBytes(d);return e.fromBytes(g).multiply(b).toBytes(E)}let l={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},h=Wr(a,c);return Object.freeze(l),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:e,utils:l,lengths:s})}function ha(e,t,r={}){let n=t;Kr(n),Lt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let s=r.randomBytes===void 0?ir:r.randomBytes,o=r.hmac===void 0?(x,w)=>ia(n,x,w):r.hmac,{Fp:i,Fn:a}=e,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:g}=gf(e,r),E={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},b=c*ca+ae<i.ORDER;function m(x){let w=c>>ae;return x>w}function S(x,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${x}: out of range 1..Point.Fn.ORDER`);return w}function I(){if(b)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(x,w){Qs(w);let A=g.signature,T=w==="compact"?A:w==="recovered"?A+1:void 0;return M(x,T)}class _{r;s;recovery;constructor(w,A,T){if(this.r=S("r",w),this.s=S("s",A),T!=null){if(I(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(w,A=E.format){C(w,A);let T;if(A==="der"){let{r:U,s:q}=_t.toSig(M(w));return new _(U,q)}A==="recovered"&&(T=w[0],A="compact",w=w.subarray(1));let L=g.signature/2,R=w.subarray(0,L),k=w.subarray(L,L*2);return new _(a.fromBytes(R),a.fromBytes(k),T)}static fromHex(w,A){return this.fromBytes(Fe(w),A)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new _(this.r,this.s,w)}recoverPublicKey(w){let{r:A,s:T}=this,L=this.assertRecovery(),R=L===2||L===3?A+c:A;if(!i.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let k=i.toBytes(R),U=e.fromBytes(et(fa((L&1)===0),k)),q=a.inv(R),K=D(M(w,void 0,"msgHash")),tt=a.create(-K*q),rt=a.create(T*q),nt=e.BASE.multiplyUnsafe(tt).add(U.multiplyUnsafe(rt));if(nt.is0())throw new Error("invalid recovery: point at infinify");return nt.assertValidity(),nt}hasHighS(){return m(this.s)}toBytes(w=E.format){if(Qs(w),w==="der")return Fe(_t.hexFromSig(this));let{r:A,s:T}=this,L=a.toBytes(A),R=a.toBytes(T);return w==="recovered"?(I(),et(Uint8Array.of(this.assertRecovery()),L,R)):et(L,R)}toHex(w){return Ne(this.toBytes(w))}}Object.freeze(_.prototype),Object.freeze(_);let O=r.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let A=me(w),T=w.length*8-u;return T>0?A>>BigInt(T):A}:r.bits2int,D=r.bits2int_modN===void 0?function(w){return a.create(O(w))}:r.bits2int_modN,B=ur(u);function N(x){return Ke("num < 2^"+u,x,Pt,B),a.toBytes(x)}function F(x,w){return M(x,void 0,"message"),w?M(n(x),void 0,"prehashed message"):x}function P(x,w,A){let{lowS:T,prehash:L,extraEntropy:R}=Js(A,E);x=F(x,L);let k=D(x),U=a.fromBytes(w);if(!a.isValidNot0(U))throw new Error("invalid private key");let q=[N(U),N(k)];if(R!=null&&R!==!1){let nt=R===!0?s(g.secretKey):R;q.push(M(nt,void 0,"extraEntropy"))}let K=et(...q),tt=k;function rt(nt){let W=O(nt);if(!a.isValidNot0(W))return;let dt=a.inv(W),Ie=e.BASE.multiply(W).toAffine(),Ye=a.create(Ie.x);if(Ye===Pt)return;let Rr=a.create(dt*a.create(tt+Ye*U));if(Rr===Pt)return;let go=(Ie.x===Ye?0:2)|Number(Ie.y&ae),wo=Rr;return T&&m(Rr)&&(wo=a.neg(Rr),go^=1),new _(Ye,wo,b?void 0:go)}return{seed:K,k2sig:rt}}function p(x,w,A={}){let{seed:T,k2sig:L}=P(x,w,A);return pi(n.outputLen,a.BYTES,o)(T,L).toBytes(A.format)}function y(x,w,A,T={}){let{lowS:L,prehash:R,format:k}=Js(T,E);if(A=M(A,void 0,"publicKey"),w=F(w,R),!pe(x)){let U=x instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}C(x,k);try{let U=_.fromBytes(x,k),q=e.fromBytes(A);if(L&&U.hasHighS())return!1;let{r:K,s:tt}=U,rt=D(w),nt=a.inv(tt),W=a.create(rt*nt),dt=a.create(K*nt),Ie=e.BASE.multiplyUnsafe(W).add(q.multiplyUnsafe(dt));return Ie.is0()?!1:a.create(Ie.x)===K}catch{return!1}}function v(x,w,A={}){let{prehash:T}=Js(A,E);return w=F(w,T),_.fromBytes(x,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:g,Point:e,sign:p,verify:y,recoverPublicKey:v,Signature:_,hash:n})}var ro={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},wf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var da=BigInt(2);function xf(e){let t=ro.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=j(f,r,t)*f%t,h=j(l,r,t)*f%t,d=j(h,da,t)*u%t,g=j(d,s,t)*d%t,E=j(g,o,t)*g%t,b=j(E,a,t)*E%t,m=j(b,c,t)*b%t,S=j(m,a,t)*E%t,I=j(S,r,t)*f%t,C=j(I,i,t)*g%t,_=j(C,n,t)*u%t,O=j(_,da,t);if(!eo.eql(eo.sqr(O),e))throw new Error("Cannot find square root");return O}var eo=Me(ro.p,{sqrt:xf}),Ef=ua(ro,{Fp:eo,endo:wf}),je=ha(Ef,Oe);function pa(e,t,r,n){let s=le.digest(r instanceof Uint8Array?r:r.subarray());if(en(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),je.verify(t,o,e,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new dr(String(o))});try{return n?.signal?.throwIfAborted(),je.verify(t,s.digest,e,{prehash:!1,format:"der"})}catch(o){throw new dr(String(o))}}var fn=class{type="secp256k1";raw;_key;constructor(t){this._key=ba(t),this.raw=ma(this._key)}toMultihash(){return vt.digest(Ft(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,r,n){return pa(this._key,r,t,n)}};function no(e){return new fn(e)}function ma(e){return je.Point.fromBytes(e).toBytes()}function ba(e){try{return je.Point.fromBytes(e),e}catch(t){throw new Be(String(t))}}function so(e,t){let{Type:r,Data:n}=kt.decode(e),s=n??new Uint8Array;switch(r){case Y.RSA:return Gs(s,t);case Y.Ed25519:return vs(s);case Y.secp256k1:return no(s);case Y.ECDSA:return $n(s);default:throw new ce}}function ya(e){let{Type:t,Data:r}=kt.decode(e.digest),n=r??new Uint8Array;switch(t){case Y.Ed25519:return vs(n);case Y.secp256k1:return no(n);case Y.ECDSA:return $n(n);default:throw new ce}}function Ft(e){return kt.encode({Type:Y[e.type],Data:e.raw})}var ga=Symbol.for("nodejs.util.inspect.custom"),Sf=114,wr=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()})`}[gn]=!0;toString(){return this.string==null&&(this.string=Z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(Sf,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")}[ga](){return`PeerId(${this.toString()})`}},xr=class extends wr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Er=class extends wr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Sr=class extends wr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},vf=2336,ln=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=vt.digest(z(this.url))}[ga](){return`PeerId(${this.url})`}[gn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(vf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=V(t)),t.toString()===this.toString())}};function oo(e){if(e.type==="Ed25519")return new Er({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Sr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new xr({multihash:e.toCID().multihash,publicKey:e});throw new ce}function wa(e){return oo(e.publicKey)}function vr(e){if(If(e))return new xr({multihash:e});if(Af(e))try{let t=ya(e);if(t.type==="Ed25519")return new Er({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Sr({multihash:e,publicKey:t})}catch{let r=V(e.digest);return new ln(new URL(r))}throw new Cr("Supplied PeerID Multihash is invalid")}function Af(e){return e.code===vt.code}function If(e){return e.code===le.code}function Se(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:t(s)}}};return r}function hn(e){let t=jt(Z.decode(`z${e}`));return vr(t)}var Ar=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 Se(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 Se(this.map.values(),t=>t.key)}values(){return Se(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Ir=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 Se(this.set.entries(),t=>{let r=hn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=hn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Se(this.set.values(),t=>hn(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 io=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},xa=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Br(e,t){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=t,a,c,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){h(xa(i));return}if(i&&(c=()=>{h(xa(i))},i.addEventListener("abort",c,{once:!0})),e.then(l,h),r===Number.POSITIVE_INFINITY)return;let d=new io;a=o.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(g){h(g)}return}typeof e.cancel=="function"&&e.cancel(),s===!1?l():s instanceof Error?h(s):(d.message=s??`Promise timed out after ${r} milliseconds`,h(d))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}var Bf=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 Lf(e,t,r){let n,s=new Promise((o,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:f}=Bf(e),l=async(...d)=>{let g=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(g))return}catch(E){n(),i(E);return}c.push(g),r.count===c.length&&(n(),o(c))},h=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,l);for(let d of r.rejectionEvents)a.includes(d)||f(d,h)};for(let d of a)u(d,l);for(let d of r.rejectionEvents)a.includes(d)||u(d,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=Br(s,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function Ea(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Lf(e,t,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var ve=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Tf(e){return e.reason}async function ao(e,t,r){if(t==null)return e;let n=r?.translateError??Tf;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let s;try{return await Promise.race([e,new Promise((o,i)=>{s=()=>{i(n(t))},t.addEventListener("abort",s)})])}finally{s!=null&&t.removeEventListener("abort",s)}}var Rf=4194304,dn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},uo=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},fo=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},lo=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Df(e){return typeof e?.closeRead=="function"}function Cf(e){return typeof e?.close=="function"}function co(e){return Df(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Cf(e)?e.status!=="open":!1}function kf(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Pf(e,t){let r=t?.maxBufferSize??Rf,n=new st,s,o=!1;if(!kf(e))throw new $("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}s?.resolve()};e.addEventListener("message",i);let a=f=>{f.error!=null?s?.reject(f.error):s?.resolve()};e.addEventListener("close",a);let c=()=>{s?.resolve()};e.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(o===!0)throw new dn("Stream was unwrapped");if(co(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 ve(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=l){s.resolve();break}if(await ao(s.promise,f?.signal),co(e)){if(n.byteLength===0&&f?.bytes==null)return null;break}s=Promise.withResolvers()}let h=f?.bytes??n.byteLength;if(n.byteLength<h){if(co(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,h),new ve(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return u.read(f)}let d=n.sublist(0,h);return n.consume(h),d},async write(f,l){if(o===!0)throw new dn("Stream was unwrapped");e.send(f)||await Ea(e,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n))),e}};return u}function Of(e,t={}){let r=Pf(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Vt(t.maxDataLength));let n=t?.lengthDecoder??Vi,s=t?.lengthEncoder??Hi;return{async read(i){let a=-1,c=new st;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new uo("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new lo(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new fo(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new ve(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new ve(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new st(s(i.byteLength),i),a)},async writeV(i,a){let c=new st(...i.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function ho(e,t){let r=Of(e,t),n={read:async(s,o)=>{let i=await r.read(o);return s.decode(i,o)},write:async(s,o,i)=>{await r.write(o.encode(s),i)},writeV:async(s,o,i)=>{await r.writeV(s.map(a=>o.encode(a)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var mo=Ua(va(),1);function bo(e,t,r){let n=0,s=e.length;for(;s>0;){let o=Math.trunc(s/2),i=n+o;r(e[i],t)<=0?(n=++i,s-=o+1):s=o}return n}var Kf=100,$e=class{#t=[];#e=0;enqueue(t,r){let{priority:n=0,id:s}=r??{},{size:o}=this,i={priority:n,id:s,run:t};if(o===0){this.#t.length=0,this.#e=0,this.#t.push(i);return}if(this.#t.at(-1).priority>=n){this.#t.push(i);return}this.#o();let a=bo(this.#t,i,(c,u)=>u.priority-c.priority);this.#t.splice(a,0,i)}setPriority(t,r){let n=this.#t.findIndex((o,i)=>i>=this.#e&&o.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:r,id:t})}remove(t){let r=this.#t.findIndex((n,s)=>s<this.#e?!1:typeof t=="string"?n.id===t:n.run===t);r!==-1&&this.#t.splice(r,1)}dequeue(){if(this.#e===this.#t.length)return;let t=this.#t[this.#e];return this.#e++,this.#e===this.#t.length?(this.#t.length=0,this.#e=0):this.#e>Kf&&this.#e>this.#t.length/2&&this.#o(),t?.run}filter(t){let r=[];for(let n=this.#e;n<this.#t.length;n++){let s=this.#t[n];s.priority===t.priority&&r.push(s.run)}return r}get size(){return this.#t.length-this.#e}#o(){this.#e!==0&&(this.#t.splice(0,this.#e),this.#e=0)}};var Tr=class extends mo.default{#t;#e;#o=0;#d;#m=!1;#w=!1;#u;#x=0;#c;#f;#a;#i=[];#s=0;#r;#B;#n=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:$e,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.#e=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#u=t.interval,this.#a=t.strict,this.#r=new t.queueClass,this.#B=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.#M()}#S(t){for(;this.#s<this.#i.length;){let n=this.#i[this.#s];if(n!==void 0&&t-n>=this.#u)this.#s++;else break}(this.#s>100&&this.#s>this.#i.length/2||this.#s===this.#i.length)&&(this.#i=this.#i.slice(this.#s),this.#s=0)}#k(t){this.#a?this.#i.push(t):this.#o++}#P(){this.#a?this.#i.length>this.#s&&this.#i.pop():this.#o>0&&this.#o--}#v(){return this.#i.length-this.#s}get#O(){return this.#e?!0:this.#a?this.#v()<this.#d:this.#o<this.#d}get#N(){return this.#n<this.#b}#F(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#K(){this.#f=void 0,this.#R(),this.#_()}#U(t){if(this.#a){if(this.#S(t),this.#v()>=this.#d){let n=this.#i[this.#s],s=this.#u-(t-n);return this.#L(s),!0}return!1}if(this.#c===void 0){let r=this.#x-t;if(r<0)this.#o=this.#t?this.#n:0;else return this.#L(r),!0}return!1}#L(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#K()},t))}#A(){this.#c&&(clearInterval(this.#c),this.#c=void 0)}#T(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#g(){if(this.#r.size===0){if(this.#A(),this.emit("empty"),this.#n===0){if(this.#T(),this.#a&&this.#s>0){let r=Date.now();this.#S(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#U(r);if(this.#O&&this.#N){let s=this.#r.dequeue();this.#e||(this.#k(r),this.#p()),n&&this.#_(),this.emit("active"),s(),t=!0}}return t}#_(){this.#e||this.#c!==void 0||this.#a||(this.#c=setInterval(()=>{this.#R()},this.#u),this.#x=Date.now()+this.#u)}#R(){this.#a||(this.#c!==void 0&&(this.#o===0&&this.#n===0?this.#A():this.#x=Date.now()+this.#u),this.#o=this.#t?this.#n:0),this.#I(),this.#p()}#I(){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.#I()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(t,r)}async add(t,r={}){if(r={timeout:this.timeout,...r,id:r.id??(this.#C++).toString()},r.timeout!==void 0&&!(Number.isFinite(r.timeout)&&r.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${r.timeout}\` (${typeof r.timeout})`);return new Promise((n,s)=>{let o=Symbol(`task-${r.id}`),i=()=>{},a=async()=>{i(),this.#n++,this.#y.set(o,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(h){throw this.#q(),this.#y.delete(o),h}let f=t({signal:r.signal});if(r.timeout!==void 0&&(f=Br(Promise.resolve(f),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),r.signal){let{signal:h}=r;f=Promise.race([f,new Promise((d,g)=>{u=()=>{g(h.reason)},h.addEventListener("abort",u,{once:!0})})])}let l=await f;n(l),this.emit("completed",l)}catch(f){s(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#y.delete(o),queueMicrotask(()=>{this.#F()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof $e){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{i(),c(),s(u.reason),this.#g(),this.emit("next")};if(i=()=>{u.removeEventListener("abort",f),this.#E.delete(i)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(i)}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.#I(),this):this}pause(){this.#l=!0}clear(){for(let t of this.#E)t();this.#r=new this.#B,this.#A(),this.#D(),this.emit("empty"),this.#n===0&&(this.#T(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#r.size<t||await this.#h(["next","active"],()=>this.#r.size<t)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#h("idle")}async onPendingZero(){this.#n!==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=s=>{this.off("error",n),r(s)};this.on("error",n)})}async#h(t,r){let n=Array.isArray(t)?t:[t];return new Promise(s=>{let o=()=>{if(!(r&&!r())){for(let i of n)this.off(i,o);s()}};for(let i of n)this.on(i,o)})}get size(){return this.#r.size}sizeBy(t){return this.#r.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#l}#M(){this.#e||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#e||this.#w||(this.#w=!0,queueMicrotask(()=>{this.#w=!1,this.#D()}))}#q(){this.#e||(this.#P(),this.#p())}#D(){let t=this.#m;if(this.#e||this.#r.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let s=Date.now();this.#S(s),r=this.#v()}else r=this.#o;let n=r>=this.#d;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#n===this.#b&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#y.values()].map(t=>({...t,timeoutRemaining:t.timeout?Math.max(0,t.startTime+t.timeout-Date.now()):void 0}))}};var mn=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 Aa={maxSubscriptions:5e3,maxMessages:5e3};function Ia(e){return{subscriptions:e.maxSubscriptions,messages:e.maxMessages}}var Ae;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=ie((h,d,g={})=>{g.lengthDelimited!==!1&&d.fork(),h.subscribe!=null&&(d.uint32(8),d.bool(h.subscribe)),h.topic!=null&&(d.uint32(18),d.string(h.topic)),g.lengthDelimited!==!1&&d.ldelim()},(h,d,g={})=>{let E={},b=d==null?h.len:h.pos+d;for(;h.pos<b;){let m=h.uint32();switch(m>>>3){case 1:{E.subscribe=h.bool();break}case 2:{E.topic=h.string();break}default:{h.skipType(m&7);break}}}return E},function*(h,d,g,E={}){let b=d==null?h.len:h.pos+d;for(;h.pos<b;){let m=h.uint32();switch(m>>>3){case 1:{yield{field:`${g}.subscribe`,value:h.bool()};break}case 2:{yield{field:`${g}.topic`,value:h.string()};break}default:{h.skipType(m&7);break}}}})),c);function u(h){return se(h,a.codec())}a.encode=u;function f(h,d){return ne(h,a.codec(),d)}a.decode=f;function l(h,d){return oe(h,a.codec(),d)}a.stream=l})(t=e.SubOpts||(e.SubOpts={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=ie((h,d,g={})=>{g.lengthDelimited!==!1&&d.fork(),h.from!=null&&(d.uint32(10),d.bytes(h.from)),h.data!=null&&(d.uint32(18),d.bytes(h.data)),h.sequenceNumber!=null&&(d.uint32(26),d.bytes(h.sequenceNumber)),h.topic!=null&&(d.uint32(34),d.string(h.topic)),h.signature!=null&&(d.uint32(42),d.bytes(h.signature)),h.key!=null&&(d.uint32(50),d.bytes(h.key)),g.lengthDelimited!==!1&&d.ldelim()},(h,d,g={})=>{let E={},b=d==null?h.len:h.pos+d;for(;h.pos<b;){let m=h.uint32();switch(m>>>3){case 1:{E.from=h.bytes();break}case 2:{E.data=h.bytes();break}case 3:{E.sequenceNumber=h.bytes();break}case 4:{E.topic=h.string();break}case 5:{E.signature=h.bytes();break}case 6:{E.key=h.bytes();break}default:{h.skipType(m&7);break}}}return E},function*(h,d,g,E={}){let b=d==null?h.len:h.pos+d;for(;h.pos<b;){let m=h.uint32();switch(m>>>3){case 1:{yield{field:`${g}.from`,value:h.bytes()};break}case 2:{yield{field:`${g}.data`,value:h.bytes()};break}case 3:{yield{field:`${g}.sequenceNumber`,value:h.bytes()};break}case 4:{yield{field:`${g}.topic`,value:h.string()};break}case 5:{yield{field:`${g}.signature`,value:h.bytes()};break}case 6:{yield{field:`${g}.key`,value:h.bytes()};break}default:{h.skipType(m&7);break}}}})),c);function u(h){return se(h,a.codec())}a.encode=u;function f(h,d){return ne(h,a.codec(),d)}a.decode=f;function l(h,d){return oe(h,a.codec(),d)}a.stream=l})(r=e.Message||(e.Message={}));let n;e.codec=()=>(n==null&&(n=ie((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.subscriptions!=null&&a.subscriptions.length>0)for(let f of a.subscriptions)c.uint32(10),e.SubOpts.codec().encode(f,c);if(a.messages!=null&&a.messages.length>0)for(let f of a.messages)c.uint32(18),e.Message.codec().encode(f,c);u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={subscriptions:[],messages:[]},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{if(u.limits?.subscriptions!=null&&f.subscriptions.length===u.limits.subscriptions)throw new Ee('Decode error - repeated field "subscriptions" had too many elements');f.subscriptions.push(e.SubOpts.codec().decode(a,a.uint32(),{limits:u.limits?.subscriptions$}));break}case 2:{if(u.limits?.messages!=null&&f.messages.length===u.limits.messages)throw new Ee('Decode error - repeated field "messages" had too many elements');f.messages.push(e.Message.codec().decode(a,a.uint32(),{limits:u.limits?.messages$}));break}default:{a.skipType(h&7);break}}}return f},function*(a,c,u,f={}){let l={subscriptions:0,messages:0},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let d=a.uint32();switch(d>>>3){case 1:{if(f.limits?.subscriptions!=null&&l.subscriptions===f.limits.subscriptions)throw new Ee('Streaming decode error - repeated field "subscriptions" had too many elements');for(let g of e.SubOpts.codec().stream(a,a.uint32(),`${u}.subscriptions[]`,{limits:f.limits?.subscriptions$}))yield{...g,index:l.subscriptions};l.subscriptions++;break}case 2:{if(f.limits?.messages!=null&&l.messages===f.limits.messages)throw new Ee('Streaming decode error - repeated field "messages" had too many elements');for(let g of e.Message.codec().stream(a,a.uint32(),`${u}.messages[]`,{limits:f.limits?.messages$}))yield{...g,index:l.messages};l.messages++;break}default:{a.skipType(d&7);break}}}})),n);function s(a){return se(a,e.codec())}e.encode=s;function o(a,c){return ne(a,e.codec(),c)}e.decode=o;function i(a,c){return oe(a,e.codec(),c)}e.stream=i})(Ae||(Ae={}));var bn=class extends Le{peerId;shutDownController;inboundPb;outboundPb;constructor(t){super(),this.peerId=t,this.shutDownController=new AbortController}attachInboundStream(t,r,n){this.inboundPb=ho(t,r).pb(Ae),Promise.resolve().then(async()=>{for(;;){if(this.inboundPb==null)return;let s=await this.inboundPb.read({signal:this.shutDownController.signal,limits:n});this.safeDispatchEvent("message",{detail:s})}}).catch(s=>{this.inboundPb?.unwrap().unwrap().abort(s),this.close()})}attachOutboundStream(t,r){this.outboundPb=ho(t,r).pb(Ae)}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 Ba(){return BigInt(`0x${V(crypto.getRandomValues(new Uint8Array(8)),"base16")}`)}var La=(e,t)=>{let r=z(t.toString(16).padStart(16,"0"),"base16"),n=Ft(e),s=new Uint8Array(n.byteLength+r.length);return s.set(n,0),s.set(r,n.byteLength),s},Ta=e=>le.encode(e);var Uf=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=vr(jt(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return oo(so(r)).equals(t)}return!1},_a=async e=>{if(e.from==null)throw new J("RPC message was missing from");if(!await Uf(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=vr(jt(e.from)),r=e.key??t.publicKey;if(r==null)throw new J("RPC message was missing public key");return{type:"signed",from:t,topic:e.topic??"",sequenceNumber:qf(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?so(r):r}},_r=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:Mf(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Ft(e.key):void 0}:{data:e.data,topic:e.topic},Mf=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),z(t,"base16")},qf=e=>BigInt(`0x${V(e,"base16")}`);var Ra=z("libp2p-pubsub:");async function Da(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:wa(e)},s=fe([Ra,r(_r(n)).subarray()]);return n.signature=await e.sign(s),n.key=e.publicKey,n}async function Ca(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=fe([Ra,t({..._r(e),signature:void 0,key:void 0}).subarray()]);return Hf(e).verify(r,e.signature)}function Hf(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.from.publicKey!=null)return e.from.publicKey;if(e.key!=null&&e.from.equals(e.key.toMultihash().bytes))return e.key;throw new Error("Could not get the public key from the originator id")}var yn=class extends Le{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;decodeRpcLimits;constructor(t,r){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocol=r.protocol??yo,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new Ar,this.globalSignaturePolicy=r.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=r.canRelayMessage??!0,this.emitSelf=r.emitSelf??!1,this.topicValidators=new Map,this.queue=new Tr({concurrency:r.messageProcessingConcurrency??10}),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.seenCache=new mn({validityMs:r?.seenTTL??3e4}),this.decodeRpcLimits=Ia(r.decodeRpcLimits??Aa),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[Ge]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[Eo]=["@libp2p/pubsub"];[So]=["@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.topics.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,void 0,this.decodeRpcLimits)}async _onPeerConnected(t,r){if(this.log("connected %p",t),r.streams.find(o=>o.direction==="outbound"&&o.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(o=>o.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 s=new bn(t);return this.peers.set(t,s),s.addEventListener("message",o=>{let i=o.detail,a=[];for(let c of i.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:(i.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 r=this.peers.get(t);if(r!=null){r.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let[n,s]of this.topics)s.delete(t),s.size===0&&this.topics.delete(n)}}async processRpc(t,r){this.log("rpc from %p",t.peerId);let{subscriptions:n,messages:s}=r;return n!=null&&n.length>0&&(this.log("subscription update from %p",t.peerId),n.forEach(o=>{this.processRpcSubOpt(t.peerId,o)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:t.peerId,subscriptions:n.map(({topic:o,subscribe:i})=>({topic:`${o??""}`,subscribe:!!i}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t.peerId),this.queue.addAll(s.map(o=>async()=>{if(o.topic==null||!this.subscriptions.has(o.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let i=await _a(o);await this.processMessage(t.peerId,i)}catch(i){this.log.error("failed to queue messages from %p - %e",t.peerId,i)}})).catch(o=>{this.log(o)})),!0}processRpcSubOpt(t,r){let n=r.topic;if(n==null)return;let s=this.topics.get(n);r.subscribe===!0?(s==null&&(s=new Ir,this.topics.set(n,s)),s.add(t)):s!=null&&(s.delete(t),s.size===0&&this.topics.delete(n))}async processMessage(t,r){if(this.components.peerId.equals(t)&&!this.emitSelf)return;let n=await this.getMsgId(r),s=V(n,"base64");if(!this.seenCache.has(s)){this.seenCache.put(s,!0);try{await this.validate(t,r)}catch(o){this.log("Message is invalid, dropping it. %O",o);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 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 La(t.key,t.sequenceNumber);case"StrictNoSign":return Ta(t.data);default:throw new J("Cannot get message id: unhandled signature policy")}}encodeMessage(t){return Ae.Message.encode(t)}send(t,r){let{messages:n,subscriptions:s,subscribe:o}=r;this.sendRpc(t,{subscriptions:(s??[]).map(i=>({topic:i,subscribe:!!o})),messages:(n??[]).map(_r)})}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 J('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new J("StrictNoSigning: signature should not be present");if(r.key!=null)throw new J("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new J("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new J("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new J("StrictSigning: Signing required and no sequenceNumber was present");if(!await Ca(r,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(r.topic);if(s!=null){let o=await s(t,r);if(o===Ze.Reject||o===Ze.Ignore)throw new J("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Da(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 kr("not started yet");if(t==null)throw new $("Topic is required");let r=this.topics.get(t.toString());return r==null?[]:Array.from(r.values())}async publish(t,r){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:r??new Uint8Array(0),sequenceNumber:Ba()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let s=await this.buildMessage(n),o=!1;this.emitSelf&&this.subscriptions.has(t)&&(o=!0,super.dispatchEvent(new CustomEvent("message",{detail:s})));let i=await this.publishMessage(this.components.peerId,s);return o&&(i.recipients=[...i.recipients,this.components.peerId]),i}async publishMessage(t,r){let n=this.getSubscribers(r.topic),s=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:s}):(n.forEach(o=>{if(this.components.peerId.equals(o)){this.log("not sending message on topic %s to myself",r.topic);return}if(o.equals(t)){this.log("not sending message on topic %s to sender %p",r.topic,o);return}this.log("publish msgs on topics %s %p",r.topic,o),s.push(o),this.send(o,{messages:[r]})}),{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 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 yo="/floodsub/1.0.0",Vf="StrictSign",zf="StrictNoSign",Ze;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(Ze||(Ze={}));function jf(e){return!!e?.[Ge]}function $f(e={}){return t=>new yn(t,e)}return Ma(Zf);})();
2
+ "use strict";var Libp2PFloodsub=(()=>{var Ma=Object.create;var Ar=Object.defineProperty;var Ua=Object.getOwnPropertyDescriptor;var qa=Object.getOwnPropertyNames;var Ha=Object.getPrototypeOf,za=Object.prototype.hasOwnProperty;var Va=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},dt=(e,t)=>{for(var r in t)Ar(e,r,{get:t[r],enumerable:!0})},bi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of qa(t))!za.call(e,s)&&s!==r&&Ar(e,s,{get:()=>t[s],enumerable:!(n=Ua(t,s))||n.enumerable});return e};var $a=(e,t,r)=>(r=e!=null?Ma(Ha(e)):{},bi(t||!e||!e.__esModule?Ar(r,"default",{value:e,enumerable:!0}):r,e)),ja=e=>bi(Ar({},"__esModule",{value:!0}),e);var Ia=Va((my,hi)=>{"use strict";var Wf=Object.prototype.hasOwnProperty,ht="~";function Er(){}Object.create&&(Er.prototype=Object.create(null),new Er().__proto__||(ht=!1));function Xf(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function Ba(e,t,r,n,s){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Xf(r,n||e,s),o=ht?ht+t:t;return e._events[o]?e._events[o].fn?e._events[o]=[e._events[o],i]:e._events[o].push(i):(e._events[o]=i,e._eventsCount++),e}function pn(e,t){--e._eventsCount===0?e._events=new Er:delete e._events[t]}function ft(){this._events=new Er,this._eventsCount=0}ft.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)Wf.call(r,n)&&t.push(ht?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};ft.prototype.listeners=function(t){var r=ht?ht+t:t,n=this._events[r];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 r=ht?ht+t:t,n=this._events[r];return n?n.fn?1:n.length:0};ft.prototype.emit=function(t,r,n,s,i,o){var a=ht?ht+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,h;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,s),!0;case 5:return c.fn.call(c.context,r,n,s,i),!0;case 6:return c.fn.call(c.context,r,n,s,i,o),!0}for(h=1,u=new Array(f-1);h<f;h++)u[h-1]=arguments[h];c.fn.apply(c.context,u)}else{var l=c.length,d;for(h=0;h<l;h++)switch(c[h].once&&this.removeListener(t,c[h].fn,void 0,!0),f){case 1:c[h].fn.call(c[h].context);break;case 2:c[h].fn.call(c[h].context,r);break;case 3:c[h].fn.call(c[h].context,r,n);break;case 4:c[h].fn.call(c[h].context,r,n,s);break;default:if(!u)for(d=1,u=new Array(f-1);d<f;d++)u[d-1]=arguments[d];c[h].fn.apply(c[h].context,u)}}return!0};ft.prototype.on=function(t,r,n){return Ba(this,t,r,n,!1)};ft.prototype.once=function(t,r,n){return Ba(this,t,r,n,!0)};ft.prototype.removeListener=function(t,r,n,s){var i=ht?ht+t:t;if(!this._events[i])return this;if(!r)return pn(this,i),this;var o=this._events[i];if(o.fn)o.fn===r&&(!s||o.once)&&(!n||o.context===n)&&pn(this,i);else{for(var a=0,c=[],f=o.length;a<f;a++)(o[a].fn!==r||s&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[i]=c.length===1?c[0]:c:pn(this,i)}return this};ft.prototype.removeAllListeners=function(t){var r;return t?(r=ht?ht+t:t,this._events[r]&&pn(this,r)):(this._events=new Er,this._eventsCount=0),this};ft.prototype.off=ft.prototype.removeListener;ft.prototype.addListener=ft.prototype.on;ft.prefixed=ht;ft.EventEmitter=ft;typeof hi<"u"&&(hi.exports=ft)});var al={};dt(al,{StrictNoSign:()=>sl,StrictSign:()=>nl,TopicValidatorResult:()=>ze,floodsub:()=>ol,isPubSub:()=>il,protocol:()=>mi,pubSubSymbol:()=>je});var je=Symbol.for("@libp2p/pubsub");var W=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ae=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Br=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var nt=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 oe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var wn=Symbol.for("@libp2p/peer-id");function Ya(e){return typeof e?.handleEvent=="function"}function Za(e){return(e!==!0&&e!==!1&&e?.once)??!1}var Be=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){let s=Za(n);super.addEventListener(t,o=>{if(s){let a=this.#t.get(o.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#t.set(o.type,a))}Ya(r)?r.handleEvent(o):r(o)},n);let i=this.#t.get(t);i==null&&(i=[],this.#t.set(t,i)),i.push({callback:r,once:s})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let s=this.#t.get(t);s!=null&&(s=s.filter(({callback:i})=>i!==r),this.#t.set(t,s))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var gi=Symbol.for("@libp2p/service-capabilities"),wi=Symbol.for("@libp2p/service-dependencies");var An={};dt(An,{base58btc:()=>X,base58flickr:()=>rc});var Fl=new Uint8Array(0);function Ei(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 xt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ae(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ae(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Si(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var xi=4096;function vi(e){let t=e.length;if(t<=xi)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=xi));return r}function Ga(e){return e?.buffer instanceof ArrayBuffer}function ae(e){return Ga(e)?e:e.slice()}function Wa(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var i=0;i<e.length;i++){var o=e.charAt(i),a=o.charCodeAt(0);if(n[a]!==255)throw new TypeError(o+" is ambiguous");if(n[a]=i,r){var c=o.toLowerCase().charCodeAt(0),f=o.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),f!==a&&(n[f]=i)}}var u=e.length,h=e.charAt(0),l=Math.log(u)/Math.log(256),d=Math.log(256)/Math.log(u);function b(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var A=0,y=0,B=0,T=w.length;B!==T&&w[B]===0;)B++,A++;for(var F=(T-B)*d+1>>>0,M=new Uint8Array(F);B!==T;){for(var N=w[B],P=0,O=F-1;(N!==0||P<y)&&O!==-1;O--,P++)N+=256*M[O]>>>0,M[O]=N%u>>>0,N=N/u>>>0;if(N!==0)throw new Error("Non-zero carry");y=P,B++}for(var U=F-y;U!==F&&M[U]===0;)U++;for(var D=h.repeat(A);U<F;++U)D+=e.charAt(M[U]);return D}function g(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var A=0;if(w[A]!==" "){for(var y=0,B=0;w[A]===h;)y++,A++;for(var T=(w.length-A)*l+1>>>0,F=new Uint8Array(T);w[A];){var M=n[w.charCodeAt(A)];if(M===255)return;for(var N=0,P=T-1;(M!==0||N<B)&&P!==-1;P--,N++)M+=u*F[P]>>>0,F[P]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");B=N,A++}if(w[A]!==" "){for(var O=T-B;O!==T&&F[O]===0;)O++;for(var U=new Uint8Array(y+(T-O)),D=y;O!==T;)U[D++]=F[O++];return U}}}function I(w){var A=g(w);if(A)return A;throw new Error(`Non-${t} character`)}return{encode:b,decodeUnsafe:g,decode:I}}var Xa=Wa,Ja=Xa,Bi=Ja;var xn=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")}},En=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let s=r.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 Ii(this,t)}},Sn=class{decoders;constructor(t){this.decoders=t}or(t){return Ii(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 Ii(e,t){return new Sn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var vn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,s){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new xn(t,r,n),this.decoder=new En(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ie({name:e,prefix:t,encode:r,decode:n}){return new vn(e,t,r,n)}function Ht({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:i}=Bi(r,e,n);return Ie({prefix:t,name:e,encode:s,decode:o=>xt(i(o))})}function Qa(e,t,r,n){let s=e.length;for(;e[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),o=0,a=0,c=0;for(let f=0;f<s;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,o+=r,o>=8&&(o-=8,i[c++]=255&a>>o)}if(o>=r||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function tc(e,t,r){let n=t[t.length-1]==="=",s=(1<<r)-1,i="",o=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],o+=8;o>r;)o-=r,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<r-o]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function ec(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let s=e[n].toLowerCase(),i=e[n].toUpperCase();s!==e[n]&&(r[s]=n),i!==e[n]&&(r[i]=n)}return r}function rt({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let i=ec(n,s);return Ie({prefix:t,name:e,encode(o){return tc(o,n,r)},decode(o){return Qa(o,i,r,e)}})}var X=Ht({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rc=Ht({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Bn={};dt(Bn,{base32:()=>Te,base32hex:()=>oc,base32hexpad:()=>cc,base32hexpadupper:()=>uc,base32hexupper:()=>ac,base32pad:()=>sc,base32padupper:()=>ic,base32upper:()=>nc,base32z:()=>fc});var Te=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),nc=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),sc=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),ic=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),oc=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),ac=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),cc=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),uc=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),fc=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var In={};dt(In,{base36:()=>Ye,base36upper:()=>lc});var Ye=Ht({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),lc=Ht({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var hc=_i,Ti=128,dc=127,pc=~dc,mc=Math.pow(2,31);function _i(e,t,r){t=t||[],r=r||0;for(var n=r;e>=mc;)t[r++]=e&255|Ti,e/=128;for(;e&pc;)t[r++]=e&255|Ti,e>>>=7;return t[r]=e|0,_i.bytes=r-n+1,t}var yc=Tn,bc=128,Li=127;function Tn(e,n){var r=0,n=n||0,s=0,i=n,o,a=e.length;do{if(i>=a)throw Tn.bytes=0,new RangeError("Could not decode varint");o=e[i++],r+=s<28?(o&Li)<<s:(o&Li)*Math.pow(2,s),s+=7}while(o>=bc);return Tn.bytes=i-n,r}var gc=Math.pow(2,7),wc=Math.pow(2,14),xc=Math.pow(2,21),Ec=Math.pow(2,28),Sc=Math.pow(2,35),vc=Math.pow(2,42),Ac=Math.pow(2,49),Bc=Math.pow(2,56),Ic=Math.pow(2,63),Tc=function(e){return e<gc?1:e<wc?2:e<xc?3:e<Ec?4:e<Sc?5:e<vc?6:e<Ac?7:e<Bc?8:e<Ic?9:10},Lc={encode:hc,decode:yc,encodingLength:Tc},_c=Lc,Ze=_c;function Ge(e,t=0){let r=Ze.decode(e,t),n=Ze.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Le(e,t,r=0){return Ze.encode(e,t,r),t}function _e(e){return Ze.encodingLength(e)}function Rt(e,t){let r=t.byteLength,n=_e(e),s=n+_e(r),i=new Uint8Array(s+r);return Le(e,i,0),Le(r,i,n),i.set(t,s),new Re(e,r,t,i)}function zt(e){let t=xt(e),[r,n]=Ge(t),[s,i]=Ge(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new Re(r,s,o,t)}function Ri(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ei(e.bytes,r.bytes)}}var Re=class{code;size;digest;bytes;constructor(t,r,n,s){this.code=t,this.size=r,this.digest=ae(n),this.bytes=ae(s)}};function Di(e,t){let{bytes:r,version:n}=e;return n===0?Dc(r,Ln(e),t??X.encoder):Cc(r,Ln(e),t??Te.encoder)}var Ci=new WeakMap;function Ln(e){let t=Ci.get(e);if(t==null){let r=new Map;return Ci.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,s){this.code=r,this.version=t,this.multihash=n,this.bytes=ae(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==We)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Pc)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=Rt(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&&Ri(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:s,multihash:i,bytes:o}=r;return new e(n,s,i,o??Pi(n,s,i.bytes))}else if(r[Oc]===!0){let{version:n,multihash:s,code:i}=r,o=zt(s);return e.create(n,i,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!==We)throw new Error(`Version 0 CID must use dag-pb (code: ${We}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let s=Pi(t,r,n.bytes);return new e(t,r,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,We,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,s=xt(t.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=s.subarray(r.multihashSize-r.digestSize),o=new Re(r.multihashCode,r.digestSize,i,s);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]=Ge(t.subarray(r));return r+=l,h},s=n(),i=We;if(s===18?(s=0,r=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=r,a=n(),c=n(),f=r+c,u=f-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,r){let[n,s]=Rc(t,r),i=e.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 Rc(e,t){switch(e[0]){case"Q":{let r=t??X;return[X.prefix,r.decode(`${X.prefix}${e}`)]}case X.prefix:{let r=t??X;return[X.prefix,r.decode(e)]}case Te.prefix:{let r=t??Te;return[Te.prefix,r.decode(e)]}case Ye.prefix:{let r=t??Ye;return[Ye.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 Dc(e,t,r){let{prefix:n}=r;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=t.get(n);if(s==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return s}function Cc(e,t,r){let{prefix:n}=r,s=t.get(n);if(s==null){let i=r.encode(e);return t.set(n,i),i}else return s}var We=112,Pc=18;function Pi(e,t,r){let n=_e(e),s=n+_e(t),i=new Uint8Array(s+r.byteLength);return Le(e,i,0),Le(t,i,n),i.set(r,s),i}var Oc=Symbol.for("@ipld/js-cid/CID");var _n={};dt(_n,{identity:()=>Bt});var Oi=0,Nc="identity",Ni=xt;function kc(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 Rt(Oi,Ni(e))}var Bt={code:Oi,name:Nc,encode:Ni,digest:kc};function pt(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 Kc(e){return e.buffer instanceof ArrayBuffer}function Et(e){return Kc(e)?e:e.slice()}async function ki(e,t,r,n){let s=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,Et(t),Et(r.subarray()));return n?.signal?.throwIfAborted(),i}function Ot(e=0){return new Uint8Array(e)}function mt(e=0){return new Uint8Array(e)}function Fc(e){return e?.buffer instanceof ArrayBuffer}function Ki(e){if(Fc(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function ce(e,t){t==null&&(t=e.reduce((s,i)=>s+i.length,0));let r=mt(t),n=0;for(let s of e)r.set(s,n),n+=s.length;return Ki(r)}var Mi=Symbol.for("@achingbrain/uint8arraylist");function Fi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let s=r+n.byteLength;if(t<s)return{buf:n,index:t-r};r=s}throw new RangeError("index is out of bounds")}function Lr(e){return!!e?.[Mi]}var it=class e{bufs;length;[Mi]=!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;for(let s of n.bufs)this.bufs.push(s)}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=Fi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Fi(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:s}=this._subList(t,r);return ce(n,s)}subarray(t,r){let{bufs:n,length:s}=this._subList(t,r);return n.length===1?n[0]:ce(n,s)}sublist(t,r){let{bufs:n,length:s}=this._subList(t,r),i=new e;return i.length=s,i.bufs=n,i}_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=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,t>=c)continue;let f=t>=a&&t<c,u=r>a&&r<=c;if(f&&u){if(t===a&&r===c){n.push(o);break}let h=t-a;n.push(o.subarray(h,h+(r-t)));break}if(f){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(u){if(r===c){n.push(o);break}n.push(o.subarray(0,r-a));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 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 h=0;h<i;h++)o[h]=-1;for(let h=0;h<s;h++)o[n[h]]=h;let a=o,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let h=r;h<=c;h+=u){u=0;for(let l=f;l>=0;l--){let d=this.get(h+l);if(n[l]!==d){u=Math.max(1,l-a[d]);break}}if(u===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=mt(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 s=Ot(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,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 s=Ot(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,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 s=Ot(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,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=mt(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 s=Ot(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,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 s=Ot(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,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 s=Ot(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,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 s=Ot(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,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 s=Ot(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,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(!pt(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((s,i)=>s+i.byteLength,0)),n.length=r,n}};var Rn={};dt(Rn,{base10:()=>Mc});var Mc=Ht({prefix:"9",name:"base10",alphabet:"0123456789"});var Dn={};dt(Dn,{base16:()=>Uc,base16upper:()=>qc});var Uc=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),qc=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Cn={};dt(Cn,{base2:()=>Hc});var Hc=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Pn={};dt(Pn,{base256emoji:()=>Yc});var Ui=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}"),zc=Ui.reduce((e,t,r)=>(e[r]=t,e),[]),Vc=Ui.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function $c(e){return e.reduce((t,r)=>(t+=zc[r],t),"")}function jc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Vc[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(s)}return new Uint8Array(t)}var Yc=Ie({prefix:"\u{1F680}",name:"base256emoji",encode:$c,decode:jc});var On={};dt(On,{base64:()=>Zc,base64pad:()=>Gc,base64url:()=>Wc,base64urlpad:()=>Xc});var Zc=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Gc=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Wc=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Xc=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Nn={};dt(Nn,{base8:()=>Jc});var Jc=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var kn={};dt(kn,{identity:()=>Qc});var Qc=Ie({prefix:"\0",name:"identity",encode:e=>vi(xt(e)),decode:e=>xt(Si(e))});var vh=new TextEncoder,Ah=new TextDecoder;var Mn={};dt(Mn,{sha256:()=>ue,sha512:()=>nu});var ru=20;function Fn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:s}){return new Kn(e,t,r,n,s)}var Kn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,s,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=s??ru,this.maxDigestLength=i}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?qi(n,this.code,r?.truncate):n.then(s=>qi(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function qi(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 Rt(t,e)}function zi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ue=Fn({name:"sha2-256",code:18,encode:zi("SHA-256")}),nu=Fn({name:"sha2-512",code:19,encode:zi("SHA-512")});var Un={...kn,...Cn,...Nn,...Rn,...Dn,...Bn,...In,...An,...On,...Pn},kh={...Mn,..._n};function $i(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Vi=$i("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),qn=$i("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=mt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),su={utf8:Vi,"utf-8":Vi,hex:Un.base16,latin1:qn,ascii:qn,binary:qn,...Un},_r=su;function Y(e,t="utf8"){let r=_r[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function j(e,t="utf8"){let r=_r[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var iu=parseInt("11111",2),Hn=parseInt("10000000",2),ou=parseInt("01111111",2),ji={0:Xe,1:Xe,2:au,3:fu,4:lu,5:uu,6:cu,16:Xe,22:Xe,48:Xe};function Nt(e,t={offset:0}){let r=e[t.offset]&iu;if(t.offset++,ji[r]!=null)return ji[r](e,t);throw new Error("No decoder for tag "+r)}function Je(e,t){let r=0;if((e[t.offset]&Hn)===Hn){let n=e[t.offset]&ou,s="0x";t.offset++;for(let i=0;i<n;i++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");s+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(s,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function Xe(e,t){Je(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Nt(e,t);if(n===null)break;r.push(n)}return r}function au(e,t){let r=Je(e,t),n=t.offset,s=t.offset+r,i=[];for(let o=n;o<s;o++)o===n&&e[o]===0||i.push(e[o]);return t.offset+=r,Uint8Array.from(i)}function cu(e,t){let r=Je(e,t),n=t.offset+r,s=e[t.offset];t.offset++;let i=0,o=0;s<40?(i=0,o=s):s<80?(i=1,o=s-40):(i=2,o=s-80);let a=`${i}.${o}`,c=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let h=0;h<c.length;h++)u+=c[h]<<h*7;a+=`.${u}`,c=[]}}return a}function uu(e,t){return t.offset++,null}function fu(e,t){let r=Je(e,t),n=e[t.offset];t.offset++;let s=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 s}function lu(e,t){let r=Je(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function hu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new it;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function zn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=hu(e.byteLength);return new it(Uint8Array.from([t.byteLength|Hn]),t)}function yt(e){let t=new it,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new it(Uint8Array.from([2]),zn(t),t)}function Rr(e){let t=Uint8Array.from([0]),r=new it(t,e);return new it(Uint8Array.from([3]),zn(r),r)}function $t(e,t=48){let r=new it;for(let n of e)r.append(n);return new it(Uint8Array.from([t]),zn(r),r)}var du=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),pu=Uint8Array.from([6,5,43,129,4,0,34]),mu=Uint8Array.from([6,5,43,129,4,0,35]),yu={ext:!0,kty:"EC",crv:"P-256"},bu={ext:!0,kty:"EC",crv:"P-384"},gu={ext:!0,kty:"EC",crv:"P-521"},Vn=32,$n=48,jn=66;function Yn(e){let t=Nt(e);return Yi(t)}function Yi(e){let t=e[1][1][0],r=1,n,s;if(t.byteLength===Vn*2+1)return n=j(t.subarray(r,r+Vn),"base64url"),s=j(t.subarray(r+Vn),"base64url"),new De({...yu,key_ops:["verify"],x:n,y:s});if(t.byteLength===$n*2+1)return n=j(t.subarray(r,r+$n),"base64url"),s=j(t.subarray(r+$n),"base64url"),new De({...bu,key_ops:["verify"],x:n,y:s});if(t.byteLength===jn*2+1)return n=j(t.subarray(r,r+jn),"base64url"),s=j(t.subarray(r+jn),"base64url"),new De({...gu,key_ops:["verify"],x:n,y:s});throw new W(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Zi(e){return $t([yt(Uint8Array.from([1])),$t([wu(e.crv)],160),$t([Rr(new it(Uint8Array.from([4]),Y(e.x??"","base64url"),Y(e.y??"","base64url")))],161)]).subarray()}function wu(e){if(e==="P-256")return du;if(e==="P-384")return pu;if(e==="P-521")return mu;throw new W(`Invalid curve ${e}`)}var De=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Zi(this.jwk)),this._raw}toMultihash(){return Bt.digest(kt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}async verify(t,r,n){return ki(this.jwk,r,t,n)}};var Dr=BigInt(4294967295),Gi=BigInt(32);function xu(e,t=!1){return t?{h:Number(e&Dr),l:Number(e>>Gi&Dr)}:{h:Number(e>>Gi&Dr)|0,l:Number(e&Dr)|0}}function Wi(e,t=!1){let r=e.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let i=0;i<r;i++){let{h:o,l:a}=xu(e[i],t);[n[i],s[i]]=[o,a]}return[n,s]}var Eu=e=>e/2**32|0,Su=e=>e>>>0;function Xi(e,t,r,n){let s=Eu(r),i=Su(r);e.setUint32(t,n?i:s,n),e.setUint32(t+4,n?s:i,n)}var Zn=(e,t,r)=>e>>>r,Gn=(e,t,r)=>e<<32-r|t>>>r,fe=(e,t,r)=>e>>>r|t<<32-r,le=(e,t,r)=>e<<32-r|t>>>r,Qe=(e,t,r)=>e<<64-r|t>>>r-32,tr=(e,t,r)=>e>>>r-32|t<<64-r;function Dt(e,t,r,n){let s=(t>>>0)+(n>>>0);return{h:e+r+(s/2**32|0)|0,l:s|0}}var Ji=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Qi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,to=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),eo=(e,t,r,n,s)=>t+r+n+s+(e/2**32|0)|0,ro=(e,t,r,n,s)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(s>>>0),no=(e,t,r,n,s,i)=>t+r+n+s+i+(e/2**32|0)|0;function Cr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Wn=e=>e?`"${e}" `:"";function Kt(e,t=""){if(typeof e!="number")throw new TypeError(Wn(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Wn(t)+"expected integer >= 0, got "+e);return e}function St(e,t,r=""){if(Cr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&Kt(t,"length");let n=Cr(e),s=t!==void 0?` of length ${t}`:"",i=n?`length=${e.length}`:`type=${typeof e}`,o=Wn(r)+"expected Uint8Array"+s+", got "+i;throw n?new RangeError(o):new TypeError(o)}function Pr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Kt(e.outputLen),Kt(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var so=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)};function Ce(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function Or(e,t){St(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function he(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Nr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function It(e,t){return e<<32-t|e>>>t}var oo=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Au=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function kr(e){if(St(e),oo)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Au[e[r]];return t}function io(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Kr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(oo)try{return Uint8Array.fromHex(e)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let s=0,i=0;s<r;s++,i+=2){let o=io(e.charCodeAt(i)),a=io(e.charCodeAt(i+1));if(o===void 0||a===void 0){let c=e[i]+e[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function Xn(...e){let t=0;for(let n=0;n<e.length;n++){let s=e[n];St(s),t+=s.length}let r=new Uint8Array(t);for(let n=0,s=0;n<e.length;n++){let i=e[n];r.set(i,s),s+=i.length}return r}function Bu(e,t,r="opts"){return so(e,"defaults"),t!==void 0&&so(t,r),Object.assign(e,t)}function Jn(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=Bu({},t,"info");let r=(s,i)=>e(i).update(s).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>e(s),Object.assign(r,t),Object.freeze(r)}function ao(e=32){Kt(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Qn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function co(e,t,r){return e&t^~e&r}function uo(e,t,r){return e&t^e&r^t&r}var er=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,s){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Nr(this.buffer)}update(t){Ce(this),St(t);let{view:r,buffer:n,blockLen:s}=this,i=t.length,o=!1;for(let a=0;a<i;){let c=Math.min(s-this.pos,i-a);if(c===s){let f=Nr(t);for(;s<=i-a;a+=s)this.process(f,a);o=!0;continue}n.set(a===0&&c===i?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(r,0),this.pos=0,o=!0)}return this.length+=t.length,o&&this.roundClean(),this}digestInto(t){Ce(this),Or(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;r[o++]=128,r.fill(0,o),this.padOffset>s-o&&(this.process(n,0),r.fill(0)),Xi(n,s-8,this.length*8,i),this.process(n,0),this.roundClean();let a=t===r?n:Nr(t),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let h=0;h<f;h++)a.setUint32(4*h,u[h],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:s,destroyed:i,pos:o}=this;return t.destroyed=i,t.finished=s,t.length=n,t.pos=o,o&&t.buffer.set(r),t}clone(){return this._cloneInto()}},fo=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var lo=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Iu=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),ts=class extends er{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:t,B:r,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[t,r,n,s,i,o,a,c]}set(t,r,n,s,i,o,a,c){this.A=t|0,this.B=r|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}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let h=0;h<16;h++,r+=4)jt[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let l=jt[h-15],d=jt[h-2],b=It(l,7)^It(l,18)^l>>>3,g=It(d,17)^It(d,19)^d>>>10;jt[h]=g+jt[h-7]+b+jt[h-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){let l=It(a,6)^It(a,11)^It(a,25),d=u+l+co(a,c,f)+Iu[h]+jt[h]|0,g=(It(n,2)^It(n,13)^It(n,22))+uo(n,s,i)|0;u=f,f=c,c=a,a=o+d|0,o=i,i=s,s=n,n=d+g|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,s,i,o,a,c,f,u)}roundClean(){he(jt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),he(this.buffer)}},es=class extends ts{constructor(){super(32,fo)}};var ho=Wi(["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))),Tu=ho[0],Lu=ho[1],Yt=new Uint32Array(80),Zt=new Uint32Array(80),rs=class extends er{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:f,El:u,Fh:h,Fl:l,Gh:d,Gl:b,Hh:g,Hl:I}=this;return[t,r,n,s,i,o,a,c,f,u,h,l,d,b,g,I]}set(t,r,n,s,i,o,a,c,f,u,h,l,d,b,g,I){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=b|0,this.Hh=g|0,this.Hl=I|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let y=0;y<16;y++,r+=4)Yt[y]=t.getUint32(r),Zt[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let B=Yt[y-15]|0,T=Zt[y-15]|0,F=fe(B,T,1)^fe(B,T,8)^Zn(B,T,7),M=le(B,T,1)^le(B,T,8)^Gn(B,T,7),N=Yt[y-2]|0,P=Zt[y-2]|0,O=fe(N,P,19)^Qe(N,P,61)^Zn(N,P,6),U=le(N,P,19)^tr(N,P,61)^Gn(N,P,6),D=to(M,U,Zt[y-7],Zt[y-16]),Z=eo(D,F,O,Yt[y-7],Yt[y-16]);Yt[y]=Z|0,Zt[y]=D|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:f,Dl:u,Eh:h,El:l,Fh:d,Fl:b,Gh:g,Gl:I,Hh:w,Hl:A}=this;for(let y=0;y<80;y++){let B=fe(h,l,14)^fe(h,l,18)^Qe(h,l,41),T=le(h,l,14)^le(h,l,18)^tr(h,l,41),F=h&d^~h&g,M=l&b^~l&I,N=ro(A,T,M,Lu[y],Zt[y]),P=no(N,w,B,F,Tu[y],Yt[y]),O=N|0,U=fe(n,s,28)^Qe(n,s,34)^Qe(n,s,39),D=le(n,s,28)^tr(n,s,34)^tr(n,s,39),Z=n&i^n&a^i&a,R=s&o^s&c^o&c;w=g|0,A=I|0,g=d|0,I=b|0,d=h|0,b=l|0,{h,l}=Dt(f|0,u|0,P|0,O|0),f=a|0,u=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let _=Ji(O,D,R);n=Qi(_,P,U,Z),s=_|0}({h:n,l:s}=Dt(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=Dt(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=Dt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Dt(this.Dh|0,this.Dl|0,f|0,u|0),{h,l}=Dt(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:b}=Dt(this.Fh|0,this.Fl|0,d|0,b|0),{h:g,l:I}=Dt(this.Gh|0,this.Gl|0,g|0,I|0),{h:w,l:A}=Dt(this.Hh|0,this.Hl|0,w|0,A|0),this.set(n,s,i,o,a,c,f,u,h,l,d,b,g,I,w,A)}roundClean(){he(Yt,Zt)}destroy(){this.destroyed=!0,he(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ns=class extends rs{constructor(){super(64,lo)}};var Pe=Jn(()=>new es,Qn(1));var ss=Jn(()=>new ns,Qn(3));function Mr(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var z=(e,t,r)=>St(e,t,r),is=Kt;function mo(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function Gt(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function de(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var rr=kr,vt=(...e)=>Xn(...e),Oe=e=>Kr(e),Xt=Cr,pe=e=>ao(e),Fr=BigInt(0),po=BigInt(1),_u=e=>e?`"${e}" `:"";function bt(e,t=""){if(typeof e!="boolean")throw new TypeError(_u(t)+"expected boolean, got type="+typeof e);return e}function Ur(e){if(typeof e=="bigint"){if(!Wt(e))throw new RangeError("positive bigint expected, got "+e)}else is(e);return e}function Jt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function nr(e){let t=Ur(e).toString(16);return t.length&1?"0"+t:t}function yo(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Fr:BigInt("0x"+e)}function Ct(e){return yo(kr(e))}function me(e){return yo(kr(Hr(St(e)).reverse()))}function qr(e,t){if(Kt(t),t===0)throw new Error("zero output length is invalid");e=Ur(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return Kr(n.padStart(r,"0"))}function os(e,t){return qr(e,t).reverse()}function Hr(e){return Uint8Array.from(z(e))}function Wt(e){return typeof e=="bigint"&&Fr<=e}function as(e,t,r){return Wt(e)&&Wt(t)&&Wt(r)&&t<=e&&e<r}function Ne(e,t,r,n){if(!as(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function ke(e){if(e<Fr)throw new Error("expected non-negative bigint, got "+e);return e===Fr?0:e.toString(2).length}var sr=e=>(Jt(e,"n"),(po<<BigInt(e))-po);function bo(e,t,r){if(Kt(e,"hashLen"),Kt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=I=>new Uint8Array(I),s=Uint8Array.of(),i=Uint8Array.of(0),o=Uint8Array.of(1),a=1e3,c=n(e),f=n(e),u=0,h=()=>{c.fill(1),f.fill(0),u=0},l=(...I)=>r(f,vt(c,...I)),d=(I=s)=>{f=l(i,I),c=l(),I.length!==0&&(f=l(o,I),c=l())},b=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let I=0,w=[];for(;I<t;){c=l();let A=c.slice();w.push(A),I+=c.length}return vt(...w)};return(I,w)=>{h(),d(I);let A;for(;(A=w(b()))===void 0;)d();return h(),A}}function gt(e,t={},r={},n="object"){Gt(e,n),Gt(t,"fields"),Gt(r,"optFields");function s(o,a,c){let f=n==="object"?`param "${String(o)}"`:`"${n}.${String(o)}"`,u=e[o];if(!Object.hasOwn(e,o)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let h=typeof u;if(h!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${h}`)}let i=(o,a)=>Object.entries(o).forEach(([c,f])=>s(c,f,a));i(t,!1),i(r,!0)}var st=BigInt(0),V=BigInt(1),Qt=BigInt(2),xo=BigInt(3),cs=BigInt(4),Eo=BigInt(5),Ru=BigInt(7),So=BigInt(8),Du=BigInt(9),Cu=BigInt(15),vo=BigInt(16),Pu=BigInt("0x10000000000000000");function J(e,t){if(t<=st)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=st?r:t+r}function Ao(e,t,r){if(r<=V)throw new Error("pow: expected modulus > 1, got "+r);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<st)throw new Error("invalid exponent, negatives unsupported");if(t===st)return V;if(t===V)return e;let n=e%r;if(n<st&&(n+=r),t<Pu){let a=V;for(;t>st;)t&V&&(a=a*n%r),n=n*n%r,t>>=V;return a}let s=[];for(;t>st;)s.push(Number(t&Cu)),t>>=cs;let i=new Array(16);i[0]=V,i[1]=n;for(let a=2;a<16;a++)i[a]=i[a-1]*n%r;let o=i[s[s.length-1]];for(let a=s.length-2;a>=0;a--){o=o*o%r,o=o*o%r,o=o*o%r,o=o*o%r;let c=s[a];c!==0&&(o=o*i[c]%r)}return o}function G(e,t,r){if(r<=V)throw new Error("pow2: expected modulus > 1, got "+r);if(t<st)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >st;)n*=n,n%=r;return n}function go(e,t){if(e===st)throw new Error("invert: expected non-zero number");if(t<=V)throw new Error("invert: expected modulus > 1, got "+t);let r=J(e,t),n=t,s=st,i=V;for(;r!==st;){let a=n/r,c=n-r*a,f=s-i*a;n=r,r=c,s=i,i=f}if(n!==V)throw new Error("invert: does not exist");return J(s,t)}function Bo(e,t){if(t<=V)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=J(e,t);if(r===st)throw new Error("invertCt: expected non-zero number");let n=Ao(r,t-Qt,t);if(J(r*n,t)!==V)throw new Error("invertCt: does not exist");return n}function us(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function fs(e,t){if((e&V)===st)throw new Error(t+": expected odd modulus, got "+e)}function Io(e,t){let r=e,n=(r.ORDER+V)/cs,s=r.pow(t,n);return us(r,s,t),s}function Ou(e,t){let r=e,n=(r.ORDER-Eo)/So,s=r.mul(t,Qt),i=r.pow(s,n),o=r.mul(t,i),a=r.mul(r.mul(o,Qt),i),c=r.mul(o,r.sub(a,r.ONE));return us(r,c,t),c}function Nu(e){let t=Fe(e),r=To(e),n=r(t,t.neg(t.ONE)),s=r(t,n),i=r(t,t.neg(n)),o=(e+Ru)/vo;return((a,c)=>{let f=a,u=f.pow(c,o),h=f.mul(u,n),l=f.mul(u,s),d=f.mul(u,i),b=f.eql(f.sqr(h),c),g=f.eql(f.sqr(l),c);u=f.cmov(u,h,b),h=f.cmov(d,l,g);let I=f.eql(f.sqr(h),c),w=f.cmov(u,h,I);return us(f,w,c),w})}function To(e){if(e<xo)throw new Error("sqrt is not defined for small field");fs(e,"tonelliShanks");let t=e-V,r=0;for(;t%Qt===st;)t/=Qt,r++;let n=Qt,s=Fe(e);for(;ir(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Io;let i=s.pow(n,t),o=(t+V)/Qt;return function(c,f){let u=c;if(u.is0(f))return f;if(ir(u,f)!==1)throw new Error("Cannot find square root");let h=r,l=u.mul(u.ONE,i),d=u.pow(f,t),b=u.pow(f,o);for(;!u.eql(d,u.ONE);){if(u.is0(d))throw new Error("Cannot find square root: probably non-prime P");let g=1,I=u.sqr(d);for(;!u.eql(I,u.ONE);)if(g++,I=u.sqr(I),g===h)throw new Error("Cannot find square root");let w=V<<BigInt(h-g-1),A=u.pow(l,w);h=g,l=u.sqr(A),d=u.mul(d,l),b=u.mul(b,A)}return b}}function ku(e){return fs(e,"Fp.sqrt"),e%cs===xo?Io:e%So===Eo?Ou:e%vo===Du?Nu(e):To(e)}var Lo=(e,t)=>(J(e,t)&V)===V,Ku=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ke(e){if(Gt(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);Jt(e.BYTES,"BYTES"),Jt(e.BITS,"BITS");for(let t of Ku)de(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=V)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Vr(e,t,r=!1){Ke(e),Mr(t,"nums"),bt(r,"passZero");let n=e,s=new Array(t.length).fill(r?n.ZERO:void 0),i=t.reduce((a,c,f)=>n.is0(c)?a:(s[f]=a,n.mul(a,c)),n.ONE),o=n.inv(i);return t.reduceRight((a,c,f)=>n.is0(c)?a:(s[f]=n.mul(a,s[f]),n.mul(a,c)),o),s}function ir(e,t){Ke(e);let r=e;fs(r.ORDER,"FpLegendre");let n=(r.ORDER-V)/Qt,s=r.pow(t,n),i=r.eql(s,r.ONE),o=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!i&&!o&&!a)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function Fu(e,t){if(t!==void 0&&is(t),e<=st)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=ke(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${r})`);let n=t!==void 0?t:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var wo=new WeakMap,zr=class{ORDER;BITS;BYTES;isLE;ZERO=st;ONE=V;_lengths;_mod;constructor(t,r={}){if(t<=V)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:i}=Fu(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=i,Object.freeze(this)}create(t){return J(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return st<=t&&t<this.ORDER}is0(t){return t===st}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&V)===V}neg(t){return J(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return J(t*t,this.ORDER)}add(t,r){return J(t+r,this.ORDER)}sub(t,r){return J(t-r,this.ORDER)}mul(t,r){return J(t*r,this.ORDER)}pow(t,r){return Ao(t,r,this.ORDER)}div(t,r){return J(t*go(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 go(t,this.ORDER)}sqrt(t){let r=wo.get(this);return r||wo.set(this,r=ku(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?os(t,this.BYTES):qr(t,this.BYTES)}fromBytes(t,r=!1){z(t);let{_lengths:n,BYTES:s,isLE:i,ORDER:o,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(s);f.set(t,i?0:f.length-t.length),t=f}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=i?me(t):Ct(t);if(a&&(c=J(c,o)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Vr(this,t,!0)}cmov(t,r,n){return bt(n,"condition"),n?r:t}};function Fe(e,t={}){return Object.freeze(zr.prototype),new zr(e,t)}function _o(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=V)throw new Error("field order must be greater than 1");let t=ke(e-V);return Math.ceil(t/8)}function $r(e){let t=_o(e);return t+Math.ceil(t/2)}function jr(e,t,r=!1){z(e);let n=e.length,s=_o(t),i=Math.max($r(t),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=r?me(e):Ct(e),a=J(o,t-V)+V;return r?os(a,s):qr(a,s)}var ds=BigInt(0),or=BigInt(1),Mu=BigInt(4),ls=16,Ro=128,Uu=5,Do=2**31;function te(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);de(t.fromAffine,"Point.fromAffine"),de(t.fromBytes,"Point.fromBytes"),de(t.fromHex,"Point.fromHex"),Gt(t.BASE,"Point.BASE"),Gt(t.ZERO,"Point.ZERO"),Ke(t.Fp),Ke(t.Fn)}function Yr(e,t){te(e),Po(t,e);let r=Vr(e.Fp,t.map(n=>n.Z));return t.map((n,s)=>e.fromAffine(n.toAffine(r[s])))}function qu(e,t,r=1){if(!Number.isSafeInteger(e)||e<r||e>t)throw new Error("invalid window size, expected ["+r+".."+t+"], got W="+e)}function Hu(e,t){let r=e*(4*t+128);if(r>Do)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Do/2**20+" MiB")}function ps(e,t){if(e!==void 0){de(e,"randomBytes");try{let r=e(t);if(!Xt(r)||r.length!==t)return}catch{return}return e}}function Po(e,t){Mr(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function zu(e,t,r){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,s)=>{if(!(r===void 0?t.isValid(n):Wt(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var Oo=new WeakMap;function hs(e){return Oo.get(e)||1}function Vu(e,t){let r=e.double(),n=[e];for(let s=1;s<t;s++)n.push(n[s-1].add(r));return n}function $u(e,t){let r=2**t,n=r/2,s=BigInt(r-1),i=[];for(;e>ds;){let o=0;e&or&&(o=Number(e&s),o>=n&&(o-=r),e-=BigInt(o)),i.push(o),e>>=or}return i}function ju(e,t,r){let n=2**t,s=n/2,i=BigInt(n-1),o=BigInt(t),a=[];for(let c=0;c<r;c++){let f=Number(e&i);e>>=o,f>s&&(f-=n,e+=or),a.push(f)}if(e!==ds)throw new Error("invalid wnaf");return a}function Yu(e,t,r){let n=0;for(let i of r)n=Math.max(n,i.length);let s=e;for(let i=n-1;i>=0;i--){i!==n-1&&(s=s.double());for(let o=0;o<r.length;o++){let a=r[o][i];if(a){let c=t[o][Math.abs(a)-1>>1];s=s.add(a<0?c.negate():c)}}}return s}var Me=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){te(t),this.randomBytes=ps(r,ls),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let s=Math.ceil(n/r)+1,i=2**(r-1),o=[],a=t;for(let c=0;c<s;c++){let f=a;for(let u=0;u<i;u++)o.push(f),f=f.add(a);a=o[o.length-1].double()}return{W:r,bits:n,windows:s,comp:o}}wnafCachedCT(t,r){let{W:n,windows:s,comp:i}=t,o=2**(n-1),a=ju(r,n,s),c=this.ZERO,f=this.BASE;for(let u=0;u<s;u++){let h=a[u],l=u*o,d=Math.abs(h)-1,b=i[l];for(let I=1;I<o;I++)b=I===d?i[l+I]:b;let g=b.negate();h===0?f=f.add(i[l]):c=c.add(h<0?g:b)}return{p:c,f}}getWnafPrecomputes(t,r,n,s){let i=this.wnafPrecomputes.get(r),o=i?.find(a=>a.W===t&&a.bits===n);return o||(o=this.buildWnafTable(r,t,n),typeof s=="function"&&(o={...o,comp:s(o.comp)}),i||(i=[],this.wnafPrecomputes.set(r,i)),i.push(o)),o}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,r){if(this.assertPoint(t),!as(r,or,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,s){let i=hs(t);return i===1?this.fixedWindowCT(t,r,n):this.wnafCachedCT(this.getWnafPrecomputes(i,t,n,s),r)}mulCT(t,r,n){return this.validateMulInput(t,r),this.runCT(t,r,this.bits,n)}mulCTBlinded(t,r,n){if(this.validateMulInput(t,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let s=this.Point.Fn.BITS+Ro,i=this.randomBytes(ls);if(!Xt(i)||i.length!==ls)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let o=r+Ct(i)*this.Point.Fn.ORDER;return this.runCT(t,o,s,n)}fixedWindowCT(t,r,n){let s=Uu,i=1<<s,o=sr(s),a=new Array(i);a[0]=this.ZERO;for(let u=1;u<i;u++)a[u]=a[u-1].add(t);let c=Math.ceil(n/s),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let d=0;d<s;d++)f=f.double();let h=Number(r>>BigInt(u*s)&o),l=a[0];for(let d=1;d<i;d++)l=d===h?a[d]:l;f=f.add(l)}return{p:f,f}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===or?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,r,n,s){return this.shouldBlind(t,n)?this.mulCTBlinded(t,r,s):this.mulCT(t,r,s)}mulUnsafe(t,r,n){if(this.assertPoint(t),!Wt(r))throw new Error("invalid scalar");let s=hs(t);if(s===1||r>=this.Point.Fn.ORDER)return Zr(this.Point,[t],[r],!0);let i=this.getWnafPrecomputes(s,t,this.bits,n);return this.wnafCachedCT(i,r).p}setWindowSize(t,r){this.assertPoint(t),qu(r,this.bits);let n=Math.ceil((this.bits+Ro)/r)+1;Hu(n*2**(r-1),this.Point.Fp.BYTES),Oo.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return hs(t)!==1}};function Zr(e,t,r,n=!1){if(te(e),Po(t,e),bt(n,"allowOversized"),zu(r,e.Fn,n?e.Fn.ORDER**Mu:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=t.map(o=>Vu(o,4)),i=r.map(o=>$u(o,4));return Yu(e.ZERO,s,i)}function Co(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ke(t),t}else return Fe(e,{isLE:r})}function Gr(e,t,r={},n){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);gt(r);for(let c of["p","n","h"]){let f=t[c];if(!(Wt(f)&&f!==ds))throw new Error(`CURVE.${c} must be positive bigint`)}let s=Co(t.p,r.Fp,n),i=Co(t.n,r.Fn,n),a=["Gx","Gy","a",e==="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 Wr(e,t){return function(n){let s=e(n);return{secretKey:s,publicKey:t(s)}}}var Xr=BigInt(0),Jr=BigInt(1),Qr=BigInt(2),Zu=BigInt(4),No=BigInt(8);function Gu(e,t,r,n){let s=e.sqr(r),i=e.sqr(n),o=e.add(e.mul(t.a,s),i),a=e.add(e.ONE,e.mul(t.d,e.mul(s,i)));return e.eql(o,a)}function ko(e,t={}){gt(t,{},{},"extraOpts");let r=t,n=Gr("edwards",e,r,r.FpFnLE),{Fp:s,Fn:i}=n,o=n.CURVE,{h:a}=o;if(ir(s,o.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(ir(s,o.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");gt(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?pe:r.randomBytes,f=Qr<<BigInt(s.BYTES*8)-Jr;function u(A){if(!s.isOdd)throw new Error("Field does not have .isOdd()");return s.isOdd(A)}let h=r.uvRatio===void 0?(A,y)=>{try{return{isValid:!0,value:s.sqrt(s.div(A,y))}}catch{return{isValid:!1,value:Xr}}}:r.uvRatio;if(!Gu(s,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");let l=s.eql(o.a,s.neg(s.ONE))?A=>s.neg(A):s.eql(o.a,s.ONE)?A=>A:A=>s.mul(o.a,A);function d(A,y,B=!1){let T=B?Jr:Xr;return Ne("coordinate "+A,y,T,f),y}function b(A){if(!(A instanceof g))throw new Error("EdwardsPoint expected")}class g{static BASE=new g(o.Gx,o.Gy,s.ONE,s.mul(o.Gx,o.Gy));static ZERO=new g(s.ZERO,s.ONE,s.ONE,s.ZERO);static Fp=s;static Fn=i;X;Y;Z;T;constructor(y,B,T,F){this.X=d("x",y),this.Y=d("y",B),this.Z=d("z",T,!0),this.T=d("t",F),Object.freeze(this)}static CURVE(){return o}static fromAffine(y){if(y instanceof g)throw new Error("extended point not allowed");let{x:B,y:T}=y||{};return d("x",B),d("y",T),new g(B,T,s.ONE,s.mul(B,T))}static fromBytes(y,B=!1){let T=s.BYTES,{a:F,d:M}=o;y=Hr(z(y,T,"point")),bt(B,"zip215");let N=Hr(y),P=y[T-1];N[T-1]=P&-129;let O=me(N),U=B?f:s.ORDER;Ne("point.y",O,Xr,U);let D=s.sqr(O),Z=s.sub(D,s.ONE),R=s.sub(s.mulN(M,D),F),{isValid:_,value:p}=h(Z,R);if(!_)throw new Error("bad point: invalid y coordinate");let x=u(p),S=(P&128)!==0;if(!B&&s.is0(p)&&S)throw new Error("bad point: x=0 and x_0=1");return S!==x&&(p=s.neg(p)),g.fromAffine({x:p,y:O})}static fromHex(y,B=!1){return g.fromBytes(Oe(y),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=6,B=!0){return w.setWindowSize(this,y),B||this.multiply(Qr),this}assertValidity(){let y=this,{a:B,d:T}=o;if(y.is0())throw new Error("bad point: ZERO");let{X:F,Y:M,Z:N,T:P}=y,O=s.sqr(F),U=s.sqr(M),D=s.sqr(N),Z=s.sqr(D),R=s.mul(O,B),_=s.mul(s.add(R,U),D),p=s.add(Z,s.mul(T,s.mul(O,U)));if(!s.eql(_,p))throw new Error("bad point: equation left != right (1)");let x=s.mul(F,M),S=s.mul(N,P);if(!s.eql(x,S))throw new Error("bad point: equation left != right (2)")}equals(y){b(y);let{X:B,Y:T,Z:F}=this,{X:M,Y:N,Z:P}=y,O=s.mul(B,P),U=s.mul(M,F),D=s.mul(T,P),Z=s.mul(N,F);return s.eql(O,U)&&s.eql(D,Z)}is0(){return this.equals(g.ZERO)}negate(){return new g(s.neg(this.X),this.Y,this.Z,s.neg(this.T))}double(){let{X:y,Y:B,Z:T}=this,F=s.sqr(y),M=s.sqr(B),N=s.mul(s.sqr(T),Qr),P=l(F),O=s.addN(y,B),U=s.sub(s.subN(s.sqr(O),F),M),D=s.addN(P,M),Z=s.subN(D,N),R=s.subN(P,M),_=s.mul(U,Z),p=s.mul(D,R),x=s.mul(U,R),S=s.mul(Z,D);return new g(_,p,S,x)}add(y){b(y);let{d:B}=o,{X:T,Y:F,Z:M,T:N}=this,{X:P,Y:O,Z:U,T:D}=y,Z=s.mul(T,P),R=s.mul(F,O),_=s.mul(s.mulN(N,B),D),p=s.mul(M,U),x=s.sub(s.subN(s.mulN(s.addN(T,F),s.addN(P,O)),Z),R),S=s.subN(p,_),C=s.addN(p,_),E=s.sub(R,l(Z)),m=s.mul(x,S),v=s.mul(C,E),L=s.mul(x,E),k=s.mul(S,C);return new g(m,v,k,L)}subtract(y){return b(y),this.add(y.negate())}multiply(y){if(!i.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:T}=w.mulSecret(this,y,a,I);return I([B,T])[0]}multiplyUnsafe(y){if(!i.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===Xr?g.ZERO:this.is0()||y===Jr?this:w.mulUnsafe(this,y,I)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return w.mulUnsafe(this,o.n).is0()}toAffine(y){let B=this,T=y;if(T!=null&&typeof T!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof T);let{X:F,Y:M,Z:N}=B,P=B.is0();T==null&&(T=P?s.create(No):s.inv(N));let O=s.mul(F,T),U=s.mul(M,T),D=s.mul(N,T);if(P)return{x:s.ZERO,y:s.ONE};if(!s.eql(D,s.ONE))throw new Error("invZ was invalid");return{x:O,y:U}}clearCofactor(){return a===Jr?this:a===Qr?this.double():a===Zu?this.double().double():a===No?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:y,y:B}=this.toAffine(),T=s.toBytes(B);return T[T.length-1]|=u(y)?128:0,T}toHex(){return rr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let I=A=>Yr(g,A),w=new Me(g,c);return w.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function Ko(e,t,r={}){if(te(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,s=r;gt(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:i}=s,{BASE:o,Fp:a,Fn:c}=e,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(Jt(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let h=s.randomBytes===void 0?pe:s.randomBytes,l=s.toMontgomery,d=s.toMontgomerySecret,b=s.adjustScalarBytes===void 0?R=>R:s.adjustScalarBytes,g=s.domain===void 0?(R,_,p)=>{if(bt(p,"phflag"),_.length||p)throw new Error("Contexts/pre-hash are not supported");return R}:s.domain;function I(R){return c.create(me(R))}function w(R){let _=P.secretKey;z(R,P.secretKey,"secretKey");let p=z(n(R),2*_,"hashedSecretKey"),x=b(p.slice(0,_)),S=p.slice(_,2*_),C=I(x);return{head:x,prefix:S,scalar:C}}function A(R){let{head:_,prefix:p,scalar:x}=w(R),S=o.multiply(x),C=S.toBytes();return{head:_,prefix:p,scalar:x,point:S,pointBytes:C}}function y(R){return A(R).pointBytes}function B(R=Uint8Array.of(),..._){let p=vt(..._);return I(n(g(p,z(R,void 0,"context"),!!i)))}function T(R,_,p={}){gt(p,{},{},"options"),R=z(R,void 0,"message"),i&&(R=i(R));let{prefix:x,scalar:S,pointBytes:C}=A(_),E=B(p.context,x,R),m=o.multiply(E).toBytes(),v=B(p.context,m,C,R),L=c.create(E+v*S);if(!c.isValid(L))throw new Error("sign failed: invalid s");let k=vt(m,c.toBytes(L));return z(k,P.signature,"result")}let F={zip215:s.zip215};function M(R,_,p,x=F){gt(x);let{context:S}=x,C=x.zip215===void 0?!!F.zip215:x.zip215,E=P.signature;R=z(R,E,"signature"),_=z(_,void 0,"message"),p=z(p,P.publicKey,"publicKey"),C!==void 0&&bt(C,"zip215"),i&&(_=i(_));let m=E/2,v=R.subarray(0,m),L=me(R.subarray(m,E)),k,K,H;try{k=e.fromBytes(p,C),K=e.fromBytes(v,C),H=o.multiplyUnsafe(L)}catch{return!1}if(!C&&k.isSmallOrder())return!1;let q=B(S,v,p,_);return K.add(k.multiplyUnsafe(q)).subtract(H).clearCofactor().is0()}let N=a.BYTES,P={secretKey:N,publicKey:N,signature:2*N,seed:N};function O(R){return R=R===void 0?h(P.seed):R,z(R,P.seed,"seed")}function U(R){return Xt(R)&&R.length===P.secretKey}function D(R,_){try{return!!e.fromBytes(R,_===void 0?F.zip215:_)}catch{return!1}}let Z={getExtendedPublicKey:A,randomSecretKey:O,isValidSecretKey:U,isValidPublicKey:D,toMontgomery(R){if(l===void 0)throw new Error("Montgomery conversion is not supported for this curve");return l(e.fromBytes(R))},toMontgomerySecret(R){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(R)}};return Object.freeze(P),Object.freeze(Z),Object.freeze({keygen:Wr(O,y),getPublicKey:y,sign:T,verify:M,utils:Z,Point:e,lengths:P})}var ms=BigInt(1),Fo=BigInt(2);var Wu=BigInt(5),Xu=BigInt(8),ys=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ju={p:ys,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Xu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Qu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),i=ys,a=e*e%i*e%i,c=G(a,Fo,i)*a%i,f=G(c,ms,i)*e%i,u=G(f,Wu,i)*f%i,h=G(u,t,i)*u%i,l=G(h,r,i)*h%i,d=G(l,n,i)*l%i,b=G(d,s,i)*d%i,g=G(b,s,i)*d%i,I=G(g,t,i)*u%i;return{pow_p_5_8:G(I,Fo,i)*e%i,b2:a}}function qo(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Mo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function tf(e,t){let r=ys,n=J(t*t*t,r),s=J(n*n*t,r),i=Qu(e*s).pow_p_5_8,o=J(e*n*i,r),a=J(t*o*o,r),c=o,f=J(o*Mo,r),u=a===e,h=a===J(-e,r),l=a===J(-e*Mo,r);return u&&(o=c),(h||l)&&(o=f),Lo(o,r)&&(o=J(-o,r)),{isValid:u||h,value:o}}var bs=ko(Ju,{uvRatio:tf}),Uo=bs.Fp;function ef(e){let{y:t}=e;return Uo.toBytes(Uo.div(ms+t,ms-t))}function rf(e){let t=bs.Fp.BYTES;return St(e,t),qo(ss(e.subarray(0,t))).subarray(0,t)}function nf(e){return Ko(bs,ss,Object.assign({adjustScalarBytes:qo,toMontgomery:ef,toMontgomerySecret:rf,zip215:!0},e))}var Ho=nf({});var ar=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},tn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var At={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new tn("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 en=32;var gs,sf=(async()=>{try{return await At.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function of(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,Et(t),Et(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function af(e,t,r){return Ho.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function zo(e,t,r){return gs==null&&(gs=await sf),gs?of(e,t,r):af(e,t,r)}function rn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var nn=class{type="Ed25519";raw;constructor(t){this.raw=ws(t,en)}toMultihash(){return Bt.digest(kt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let s=zo(this.raw,r,t);return rn(s)?s.then(i=>(n?.signal?.throwIfAborted(),i)):s}};function xs(e){return e=ws(e,en),new nn(e)}function ws(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new W(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var uf=Math.pow(2,7),ff=Math.pow(2,14),lf=Math.pow(2,21),Es=Math.pow(2,28),Ss=Math.pow(2,35),vs=Math.pow(2,42),As=Math.pow(2,49),$=128,ct=127;function Ft(e){if(e<uf)return 1;if(e<ff)return 2;if(e<lf)return 3;if(e<Es)return 4;if(e<Ss)return 5;if(e<vs)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 Bs(e,t,r=0){switch(Ft(e)){case 8:t[r++]=e&255|$,e/=128;case 7:t[r++]=e&255|$,e/=128;case 6:t[r++]=e&255|$,e/=128;case 5:t[r++]=e&255|$,e/=128;case 4:t[r++]=e&255|$,e>>>=7;case 3:t[r++]=e&255|$,e>>>=7;case 2:t[r++]=e&255|$,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function hf(e,t,r=0){switch(Ft(e)){case 8:t.set(r++,e&255|$),e/=128;case 7:t.set(r++,e&255|$),e/=128;case 6:t.set(r++,e&255|$),e/=128;case 5:t.set(r++,e&255|$),e/=128;case 4:t.set(r++,e&255|$),e>>>=7;case 3:t.set(r++,e&255|$),e>>>=7;case 2:t.set(r++,e&255|$),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Is(e,t){let r=e[t],n=0;if(n+=r&ct,r<$||(r=e[t+1],n+=(r&ct)<<7,r<$)||(r=e[t+2],n+=(r&ct)<<14,r<$)||(r=e[t+3],n+=(r&ct)<<21,r<$)||(r=e[t+4],n+=(r&ct)*Es,r<$)||(r=e[t+5],n+=(r&ct)*Ss,r<$)||(r=e[t+6],n+=(r&ct)*vs,r<$)||(r=e[t+7],n+=(r&ct)*As,r<$))return n;throw new RangeError("Could not decode varint")}function df(e,t){let r=e.get(t),n=0;if(n+=r&ct,r<$||(r=e.get(t+1),n+=(r&ct)<<7,r<$)||(r=e.get(t+2),n+=(r&ct)<<14,r<$)||(r=e.get(t+3),n+=(r&ct)<<21,r<$)||(r=e.get(t+4),n+=(r&ct)*Es,r<$)||(r=e.get(t+5),n+=(r&ct)*Ss,r<$)||(r=e.get(t+6),n+=(r&ct)*vs,r<$)||(r=e.get(t+7),n+=(r&ct)*As,r<$))return n;throw new RangeError("Could not decode varint")}function $o(e,t,r=0){return t==null&&(t=mt(Ft(e))),t instanceof Uint8Array?Bs(e,t,r):hf(e,t,r)}function jo(e,t=0){return e instanceof Uint8Array?Is(e,t):df(e,t)}var Ts=new Float32Array([-0]),ee=new Uint8Array(Ts.buffer);function Yo(e,t,r){Ts[0]=e,t[r]=ee[0],t[r+1]=ee[1],t[r+2]=ee[2],t[r+3]=ee[3]}function Zo(e,t){return ee[0]=e[t],ee[1]=e[t+1],ee[2]=e[t+2],ee[3]=e[t+3],Ts[0]}var Ls=new Float64Array([-0]),ut=new Uint8Array(Ls.buffer);function Go(e,t,r){Ls[0]=e,t[r]=ut[0],t[r+1]=ut[1],t[r+2]=ut[2],t[r+3]=ut[3],t[r+4]=ut[4],t[r+5]=ut[5],t[r+6]=ut[6],t[r+7]=ut[7]}function Wo(e,t){return ut[0]=e[t],ut[1]=e[t+1],ut[2]=e[t+2],ut[3]=e[t+3],ut[4]=e[t+4],ut[5]=e[t+5],ut[6]=e[t+6],ut[7]=e[t+7],Ls[0]}var mf=BigInt(Number.MAX_SAFE_INTEGER),yf=BigInt(Number.MIN_SAFE_INTEGER),wt=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 ye;if(t<mf&&t>yf)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,s=t-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>Xo&&(s=0n,++n>Xo&&(n=0n))),new e(Number(s),Number(n))}static fromNumber(t){if(t===0)return ye;let r=t<0;r&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new e(n,s)}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):ye}},ye=new wt(0,0);ye.toBigInt=function(){return 0n};ye.zzEncode=ye.zzDecode=function(){return this};ye.length=function(){return 1};var Xo=4294967296n;function Jo(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 Qo(e,t,r){if(r-t<1)return"";let s,i=[],o=0,a;for(;t<r;)a=e[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(e[t++]&63)<<6|e[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 _s(e,t,r){let n=r,s,i;for(let o=0;o<e.length;++o)s=e.charCodeAt(o),s<128?t[r++]=s:s<2048?(t[r++]=s>>6|192,t[r++]=s&63|128):(s&64512)===55296&&((i=e.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[r++]=s>>18|240,t[r++]=s>>12&63|128,t[r++]=s>>6&63|128,t[r++]=s&63|128):(t[r++]=s>>12|224,t[r++]=s>>6&63|128,t[r++]=s&63|128);return r-n}function Tt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function sn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Rs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=Et(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,Tt(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 Tt(this,4);return sn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return sn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=Zo(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=Wo(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 Tt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Qo(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(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 wt(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 Tt(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 Tt(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 Tt(this,8);let t=sn(this.buf,this.pos+=4),r=sn(this.buf,this.pos+=4);return new wt(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=Is(this.buf,this.pos);return this.pos+=Ft(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 cr(e){return new Rs(e instanceof Uint8Array?e:e.subarray())}function re(e,t,r){let n=cr(e);return t.decode(n,void 0,r)}function Ds(e){let t=e??8192,r=t>>>1,n,s=t;return function(o){if(o<1||o>r)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 be=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Cs(){}var Os=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},bf=Ds();function gf(e){return globalThis.Buffer!=null?mt(e):bf(e)}var fr=class{len;head;tail;states;constructor(){this.len=0,this.head=new be(Cs,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new be(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ns((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(on,10,wt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=wt.fromBigInt(t);return this._push(on,r.length(),r)}uint64Number(t){return this._push(Bs,Ft(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=wt.fromBigInt(t).zzEncode();return this._push(on,r.length(),r)}sint64Number(t){let r=wt.fromNumber(t).zzEncode();return this._push(on,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ps,1,t?1:0)}fixed32(t){return this._push(ur,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=wt.fromBigInt(t);return this._push(ur,4,r.lo)._push(ur,4,r.hi)}fixed64Number(t){let r=wt.fromNumber(t);return this._push(ur,4,r.lo)._push(ur,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(Yo,4,t)}double(t){return this._push(Go,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ps,1,0):this.uint32(r)._push(xf,r,t)}string(t){let r=Jo(t);return r!==0?this.uint32(r)._push(_s,r,t):this._push(Ps,1,0)}fork(){return this.states=new Os(this),this.head=this.tail=new be(Cs,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new be(Cs,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=gf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ps(e,t,r){t[r]=e&255}function wf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ns=class extends be{next;constructor(t,r){super(wf,t,r),this.next=void 0}};function on(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 ur(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 xf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(fr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Ef,t,e),this},fr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Sf,t,e),this});function Ef(e,t,r){t.set(e,r)}function Sf(e,t,r){e.length<40?_s(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Y(e),r)}function ks(){return new fr}function ne(e,t){let r=ks();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*se(e,t,r){let n=cr(e);yield*t.stream(n,void 0,"$",r)}var an={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function cn(e,t,r,n,s){return{name:e,type:t,encode:r,decode:n,stream:s}}function Ks(e){function t(i){if(e[i.toString()]==null)throw new Error("Invalid enum value");return e[i]}let r=function(o,a){let c=t(o);a.int32(c)},n=function(o){let a=o.int32();return t(a)},s=function*(o){let a=o.int32();yield t(a)};return cn("enum",an.VARINT,r,n,s)}function ie(e,t,r){return cn("message",an.LENGTH_DELIMITED,e,t,r)}var ge=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Q;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Q||(Q={}));var Fs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Fs||(Fs={}));(function(e){e.codec=()=>Ks(Fs)})(Q||(Q={}));var Pt;(function(e){let t;e.codec=()=>(t==null&&(t=ie((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),Q.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),a.lengthDelimited!==!1&&o.ldelim()},(i,o,a={})=>{let c={},f=o==null?i.len:i.pos+o;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{c.Type=Q.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(u&7);break}}}return c},function*(i,o,a,c={}){let f=o==null?i.len:i.pos+o;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:Q.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(u&7);break}}}})),t);function r(i){return ne(i,e.codec())}e.encode=r;function n(i,o){return re(i,e.codec(),o)}e.decode=n;function s(i,o){return se(i,e.codec(),o)}e.stream=s})(Pt||(Pt={}));var Ms;(function(e){let t;e.codec=()=>(t==null&&(t=ie((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),Q.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),a.lengthDelimited!==!1&&o.ldelim()},(i,o,a={})=>{let c={},f=o==null?i.len:i.pos+o;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{c.Type=Q.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(u&7);break}}}return c},function*(i,o,a,c={}){let f=o==null?i.len:i.pos+o;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:Q.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(u&7);break}}}})),t);function r(i){return ne(i,e.codec())}e.encode=r;function n(i,o){return re(i,e.codec(),o)}e.decode=n;function s(i,o){return se(i,e.codec(),o)}e.stream=s})(Ms||(Ms={}));var hr={};dt(hr,{MAX_RSA_KEY_SIZE:()=>Us,generateRSAKeyPair:()=>ia,jwkToJWKKeyPair:()=>oa,jwkToPkcs1:()=>If,jwkToPkix:()=>Vs,jwkToRSAPrivateKey:()=>Zs,pkcs1MessageToJwk:()=>Hs,pkcs1MessageToRSAPrivateKey:()=>$s,pkcs1ToJwk:()=>Bf,pkcs1ToRSAPrivateKey:()=>sa,pkixMessageToJwk:()=>zs,pkixMessageToRSAPublicKey:()=>Ys,pkixToJwk:()=>Tf,pkixToRSAPublicKey:()=>js});var Ue=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=hr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,r,n){return na(this.jwk,r,t,n)}},lr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=hr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}sign(t,r){return ra(this.jwk,t,r)}};var Us=8192,qs=18,vf=1062,Af=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Bf(e){let t=Nt(e);return Hs(t)}function Hs(e){return{n:j(e[1],"base64url"),e:j(e[2],"base64url"),d:j(e[3],"base64url"),p:j(e[4],"base64url"),q:j(e[5],"base64url"),dp:j(e[6],"base64url"),dq:j(e[7],"base64url"),qi:j(e[8],"base64url"),kty:"RSA"}}function If(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 W("JWK was missing components");return $t([yt(Uint8Array.from([0])),yt(Y(e.n,"base64url")),yt(Y(e.e,"base64url")),yt(Y(e.d,"base64url")),yt(Y(e.p,"base64url")),yt(Y(e.q,"base64url")),yt(Y(e.dp,"base64url")),yt(Y(e.dq,"base64url")),yt(Y(e.qi,"base64url"))]).subarray()}function Tf(e){let t=Nt(e,{offset:0});return zs(t)}function zs(e){let t=Nt(e[1],{offset:0});return{kty:"RSA",n:j(t[0],"base64url"),e:j(t[1],"base64url")}}function Vs(e){if(e.n==null||e.e==null)throw new W("JWK was missing components");return $t([Af,Rr($t([yt(Y(e.n,"base64url")),yt(Y(e.e,"base64url"))]))]).subarray()}function sa(e){let t=Nt(e);return $s(t)}function $s(e){let t=Hs(e);return Zs(t)}function js(e,t){if(e.byteLength>=vf)throw new Ae("Key size is too large");let r=Nt(e,{offset:0});return Ys(r,e,t)}function Ys(e,t,r){let n=zs(e);if(r==null){let s=Pe(Pt.encode({Type:Q.RSA,Data:t}));r=Rt(qs,s)}return new Ue(n,r)}function Zs(e){if(ca(e)>Us)throw new W("Key size is too large");let t=oa(e),r=Pe(Pt.encode({Type:Q.RSA,Data:Vs(t.publicKey)})),n=Rt(qs,r);return new lr(t.privateKey,new Ue(t.publicKey,n))}async function ia(e){if(e>Us)throw new W("Key size is too large");let t=await aa(e),r=Pe(Pt.encode({Type:Q.RSA,Data:Vs(t.publicKey)})),n=Rt(qs,r);return new lr(t.privateKey,new Ue(t.publicKey,n))}function oa(e){if(e==null)throw new W("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function aa(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 Lf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function ra(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 s=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Et(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function na(e,t,r,n){let s=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,Et(t),Et(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),i}async function Lf(e,t){if(e.privateKey==null||e.publicKey==null)throw new W("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 ca(e){if(e.kty!=="RSA")throw new W("invalid key type");if(e.n==null)throw new W("invalid key modulus");return Y(e.n,"base64url").length*8}var un=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Pr(t),St(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(r.length>n?t.create().update(r).digest():r);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),he(s)}update(t){return Ce(this),this.iHash.update(t),this}digestInto(t){Ce(this),Or(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),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:s,destroyed:i,blockLen:o,outputLen:a,canXOF:c}=this;return t=t,t.finished=s,t.destroyed=i,t.blockLen=o,t.outputLen=a,t.canXOF=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()}},ua=(()=>{let e=((t,r,n)=>new un(t,r).update(n).digest());return e.create=(t,r)=>new un(t,r),e})();var _f=BigInt(0),Gs=class extends Error{constructor(t=""){super(t)}},Mt={Err:Gs,_tlv:{encode:(e,t)=>{let{Err:r}=Mt;if(Jt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(mo(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,s=nr(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?nr(s.length/2|128):"";return nr(e)+i+s+t},decode(e,t){let{Err:r}=Mt;t=z(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("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 r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)o=o<<8|u;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(e){let{Err:t}=Mt;if(Ur(e),e<_f)throw new t("integer: negative integers are not allowed");let r=nr(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}=Mt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ct(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Mt,s=z(e,void 0,"signature"),{v:i,l:o}=n.decode(48,s);if(o.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=Mt;gt(e,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,r.encode(e.r)),s=t.encode(2,r.encode(e.s)),i=n+s;return t.encode(48,i)}},Ws=(Object.freeze(Mt._tlv),Object.freeze(Mt._int),Object.freeze(Mt));var fa=(e,t)=>(e+(e>=0?t:-t)/la)/t;function Rf(e,t,r){Ne("scalar",e,Ut,r);let[[n,s],[i,o]]=t,a=fa(o*e,r),c=fa(-s*e,r),f=e-a*n-c*i,u=-a*s-c*o,h=f<Ut,l=u<Ut;h&&(f=-f),l&&(u=-u);let d=sr(Math.ceil(ke(r)/2))+we;if(f<Ut||f>=d||u<Ut||u>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:f,k2neg:l,k2:u}}function Qs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Xs(e,t){gt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return bt(r.lowS,"lowS"),bt(r.prehash,"prehash"),r.format!==void 0&&Qs(r.format),r}var Ut=BigInt(0),we=BigInt(1),la=BigInt(2),Js=BigInt(3),Df=BigInt(4);function ha(e,t={}){let r=Gr("weierstrass",e,t),n=r.Fp,s=r.Fn,i=r.CURVE,{h:o,n:a}=i;gt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f}=t,u=t.randomBytes===void 0?pe:t.randomBytes;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 h=pa(n,s);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(_,p,x){if(f&&p.is0())return Uint8Array.of(0);let{x:S,y:C}=p.toAffine(),E=n.toBytes(S);if(bt(x,"isCompressed"),x){l();let m=!n.isOdd(C);return vt(da(m),E)}else return vt(Uint8Array.of(4),E,n.toBytes(C))}function b(_){z(_,void 0,"Point");let{publicKey:p,publicKeyUncompressed:x}=h,S=_.length,C=_[0],E=_.subarray(1);if(f&&S===1&&C===0)return{x:n.ZERO,y:n.ZERO};if(S===p&&(C===2||C===3)){let m=n.fromBytes(E);if(!n.isValid(m))throw new Error("bad point: is not on curve, wrong x");let v=y(m),L;try{L=n.sqrt(v)}catch(H){let q=H instanceof Error?": "+H.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}l();let k=n.isOdd(L);return(C&1)===1!==k&&(L=n.neg(L)),{x:m,y:L}}else if(S===x&&C===4){let m=n.BYTES,v=n.fromBytes(E.subarray(0,m)),L=n.fromBytes(E.subarray(m,m*2));if(!B(v,L))throw new Error("bad point: is not on curve");return{x:v,y:L}}else throw new Error(`bad point: got length ${S}, expected compressed=${p} or uncompressed=${x}`)}let g=t.toBytes===void 0?d:t.toBytes,I=t.fromBytes===void 0?b:t.fromBytes,w=n.mul(i.b,Js),A=n.is0(i.a)?_=>n.ZERO:_=>n.mul(i.a,_);function y(_){let p=n.sqr(_),x=n.mul(p,_);return n.add(n.add(x,n.mul(_,i.a)),i.b)}function B(_,p){let x=n.sqr(p),S=y(_);return n.eql(x,S)}if(!B(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let T=n.mul(n.pow(i.a,Js),Df),F=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(T,F)))throw new Error("bad curve params: a or b");function M(_,p,x=!1){if(!n.isValid(p)||x&&n.is0(p))throw new Error(`bad point coordinate ${_}`);return p}function N(_){if(!(_ instanceof D))throw new Error("Weierstrass Point expected")}function P(_){if(!c||!c.basises)throw new Error("no endo");return Rf(_,c.basises,s.ORDER)}function O(_,p,x,S){if(!s.isValid(S))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:C,k1:E,k2neg:m,k2:v}=P(S),L=new D(n.mul(x.X,c.beta),x.Y,x.Z);_.push(C?x.negate():x,m?L.negate():L),p.push(E,v)}else _.push(x),p.push(S)}let U=new WeakSet;class D{static BASE=new D(i.Gx,i.Gy,n.ONE);static ZERO=new D(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(p,x,S){this.X=M("x",p),this.Y=M("y",x,!0),this.Z=M("z",S),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x,y:S}=p||{};if(!p||!n.isValid(x)||!n.isValid(S))throw new Error("invalid affine point");if(p instanceof D)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(S)?D.ZERO:new D(x,S,n.ONE)}static fromBytes(p){let x=D.fromAffine(I(z(p,void 0,"point")));return x.assertValidity(),x}static fromHex(p){return D.fromBytes(Oe(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,x=!0){return R.setWindowSize(this,p),x||this.multiply(Js),this}assertValidity(){let p=this;if(p.is0()){if(t.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(U.has(p))return;let{x,y:S}=p.toAffine();if(!n.isValid(x)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!B(x,S))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");U.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){N(p);let{X:x,Y:S,Z:C}=this,{X:E,Y:m,Z:v}=p,L=n.eql(n.mul(x,v),n.mul(E,C)),k=n.eql(n.mul(S,v),n.mul(m,C));return L&&k}negate(){return new D(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:x,Z:S}=this,C=n.ZERO,E=n.ZERO,m=n.ZERO,v=n.mul(p,p),L=n.mul(x,x),k=n.mul(S,S),K=n.mul(p,x);return K=n.add(K,K),m=n.mul(p,S),m=n.add(m,m),C=A(m),E=n.mul(w,k),E=n.add(C,E),C=n.sub(L,E),E=n.add(L,E),E=n.mul(C,E),C=n.mul(K,C),m=n.mul(w,m),k=A(k),K=n.sub(v,k),K=A(K),K=n.add(K,m),m=n.add(v,v),v=n.add(m,v),v=n.add(v,k),v=n.mul(v,K),E=n.add(E,v),k=n.mul(x,S),k=n.add(k,k),v=n.mul(k,K),C=n.sub(C,v),m=n.mul(k,L),m=n.add(m,m),m=n.add(m,m),new D(C,E,m)}add(p){N(p);let{X:x,Y:S,Z:C}=this,{X:E,Y:m,Z:v}=p,L=n.ZERO,k=n.ZERO,K=n.ZERO,H=n.mul(x,E),q=n.mul(S,m),tt=n.mul(C,v),lt=n.add(x,S),et=n.add(E,m);lt=n.mul(lt,et),et=n.add(H,q),lt=n.sub(lt,et),et=n.add(x,C);let ot=n.add(E,v);return et=n.mul(et,ot),ot=n.add(H,tt),et=n.sub(et,ot),ot=n.add(S,C),L=n.add(m,v),ot=n.mul(ot,L),L=n.add(q,tt),ot=n.sub(ot,L),K=A(et),L=n.mul(w,tt),K=n.add(L,K),L=n.sub(q,K),K=n.add(q,K),k=n.mul(L,K),q=n.add(H,H),q=n.add(q,H),tt=A(tt),et=n.mul(w,et),q=n.add(q,tt),tt=n.sub(H,tt),tt=A(tt),et=n.add(et,tt),H=n.mul(q,et),k=n.add(k,H),H=n.mul(ot,et),L=n.mul(lt,L),L=n.sub(L,H),H=n.mul(lt,q),K=n.mul(ot,K),K=n.add(K,H),new D(L,k,K)}subtract(p){return N(p),this.add(p.negate())}is0(){return this.equals(D.ZERO)}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:x,f:S}=R.mulSecret(this,p,o,Z);return Z([x,S])[0]}multiplyUnsafe(p){let x=this,S=p;if(!s.isValid(S))throw new RangeError("invalid scalar: out of range");if(S===Ut||x.is0())return D.ZERO;if(S===we)return x;if(R.hasWindowSize(this))return R.mulUnsafe(x,S,Z);let C=[],E=[];return O(C,E,x,S),Zr(D,C,E)}mulAddUnsafe(p,x,S){N(x);let C=[],E=[];return O(C,E,this,p),O(C,E,x,S),Zr(D,C,E)}toAffine(p){let x=this,S=p;if(S!=null&&!n.isValid(S))throw new RangeError('"invertedZ" expected valid field element');let{X:C,Y:E,Z:m}=x;if(n.eql(m,n.ONE))return{x:C,y:E};let v=x.is0();S==null&&(S=v?n.ONE:n.inv(m));let L=n.mul(C,S),k=n.mul(E,S),K=n.mul(m,S);if(v)return{x:n.ZERO,y:n.ZERO};if(!n.eql(K,n.ONE))throw new Error("invZ was invalid");return{x:L,y:k}}isTorsionFree(){let{isTorsionFree:p}=t;return o===we?!0:p?p(D,this):R.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=t;return o===we?this:p?p(D,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===we?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return bt(p,"isCompressed"),this.assertValidity(),g(D,this,p)}toHex(p=!0){return rr(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let Z=_=>Yr(D,_),R=new Me(D,u);return R.bits>=6&&D.BASE.precompute(6),Object.freeze(D.prototype),Object.freeze(D),D}function da(e){return Uint8Array.of(e?2:3)}function pa(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Cf(e,t={}){te(e);let{Fn:r}=e,n=t.randomBytes===void 0?pe:t.randomBytes,s=Object.assign(pa(e.Fp,r),{seed:Math.max($r(r.ORDER),16)});function i(d){try{let b=r.fromBytes(d);return r.isValidNot0(b)}catch{return!1}}function o(d,b){let{publicKey:g,publicKeyUncompressed:I}=s;try{let w=d.length;return b===!0&&w!==g||b===!1&&w!==I?!1:!!e.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(s.seed):d,jr(z(d,s.seed,"seed"),r.ORDER)}function c(d,b=!0){return e.BASE.multiply(r.fromBytes(d)).toBytes(b)}function f(d){let{secretKey:b,publicKey:g,publicKeyUncompressed:I}=s,w=r._lengths;if(!Xt(d))return;let A=z(d,void 0,"key").length,y=A===g||A===I,B=A===b||!!w?.includes(A);if(!(y&&B))return y}function u(d,b,g=!0){if(f(d)===!0)throw new Error("first arg must be private key");if(f(b)===!1)throw new Error("second arg must be public key");let I=r.fromBytes(d);return e.fromBytes(b).multiply(I).toBytes(g)}let h={isValidSecretKey:i,isValidPublicKey:o,randomSecretKey:a},l=Wr(a,c);return Object.freeze(h),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:l,Point:e,utils:h,lengths:s})}function ma(e,t,r={}){te(e);let n=t;Pr(n),gt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),i=s.randomBytes===void 0?pe:s.randomBytes,o=s.hmac===void 0?(E,m)=>ua(n,E,m):s.hmac,{Fp:a,Fn:c}=e,{ORDER:f,BITS:u}=c,h=$r(f),l=ps(i,h),{keygen:d,getPublicKey:b,getSharedSecret:g,utils:I,lengths:w}=Cf(e,s),A={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},y=f*la+we<a.ORDER;function B(E){let m=f>>we;return E>m}function T(E,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return m}function F(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function M(E,m,v){return F(),(E===v?0:2)|Number(a.isOdd(m))}function N(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function P(E,m){Qs(m);let v=w.signature,L=m==="compact"?v:m==="recovered"?v+1:void 0;return z(E,L)}class O{r;s;recovery;constructor(m,v,L){if(this.r=T("r",m),this.s=T("s",v),L!=null){if(N(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(m,v=A.format){P(m,v);let L;if(v==="der"){let{r:q,s:tt}=Ws.toSig(z(m));return new O(q,tt)}v==="recovered"&&(L=m[0],v="compact",m=m.subarray(1));let k=w.signature/2,K=m.subarray(0,k),H=m.subarray(k,k*2);return new O(c.fromBytes(K),c.fromBytes(H),L)}static fromHex(m,v){return this.fromBytes(Oe(m),v)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new O(this.r,this.s,m)}recoverPublicKey(m){let{r:v,s:L}=this,k=this.assertRecovery(),K=k===2||k===3?v+f:v;if(!a.isValid(K))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let H=a.toBytes(K),q=e.fromBytes(vt(da((k&1)===0),H)),tt=c.inv(K),lt=D(z(m,void 0,"msgHash")),et=c.create(-lt*tt),ot=c.create(L*tt),Lt=e.BASE.mulAddUnsafe(et,q,ot);if(Lt.is0())throw new Error("invalid recovery: point at infinify");return Lt.assertValidity(),Lt}hasHighS(){return B(this.s)}toBytes(m=A.format){if(Qs(m),m==="der")return Oe(Ws.hexFromSig(this));let{r:v,s:L}=this,k=c.toBytes(v),K=c.toBytes(L);return m==="recovered"?(N(),vt(Uint8Array.of(this.assertRecovery()),k,K)):vt(k,K)}toHex(m){return rr(this.toBytes(m))}}Object.freeze(O.prototype),Object.freeze(O);let U=s.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let v=Ct(m),L=m.length*8-u;return L>0?v>>BigInt(L):v}:s.bits2int,D=s.bits2int_modN===void 0?function(m){return c.create(U(m))}:s.bits2int_modN,Z=sr(u);function R(E){return Ne("num < 2^"+u,E,Ut,Z),c.toBytes(E)}function _(E,m){return z(E,void 0,"message"),m?z(n(E),void 0,"prehashed message"):E}function p(E,m,v){let{lowS:L,prehash:k,extraEntropy:K}=Xs(v,A);E=_(E,k);let H=D(E),q=c.fromBytes(m);if(!c.isValidNot0(q))throw new Error("invalid private key");let tt=[R(q),R(H)];if(K!=null&&K!==!1){let Lt=K===!0?i(w.secretKey):K;tt.push(z(Lt,void 0,"extraEntropy"))}let lt=vt(...tt),et=H;function ot(Lt){let ve=U(Lt);if(!c.isValidNot0(ve))return;let Ve=e.BASE.multiply(ve).toAffine(),qt=c.create(Ve.x);if(qt===Ut)return;let _t;if(l!==void 0){let $e=Ct(jr(l(h),f)),ka=c.inv(c.mul($e,ve)),Ka=c.mul($e,et),Fa=c.mul($e,q);_t=c.create(ka*c.create(Ka+Fa*qt))}else{let $e=Bo(ve,f);_t=c.create($e*c.create(et+qt*q))}if(_t===Ut)return;let gn=M(Ve.x,Ve.y,qt),yi=_t;return L&&B(_t)&&(yi=c.neg(_t),gn^=1),new O(qt,yi,y?void 0:gn)}return{seed:lt,k2sig:ot}}function x(E,m,v={}){let{seed:L,k2sig:k}=p(E,m,v);return bo(n.outputLen,c.BYTES,o)(L,k).toBytes(v.format)}function S(E,m,v,L={}){let{lowS:k,prehash:K,format:H}=Xs(L,A);if(v=z(v,void 0,"publicKey"),m=_(m,K),!Xt(E)){let q=E instanceof O?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}P(E,H);try{let q=O.fromBytes(E,H),tt=e.fromBytes(v);if(k&&q.hasHighS())return!1;let{r:lt,s:et}=q,ot=D(m),Lt=c.inv(et),ve=c.create(ot*Lt),Ve=c.create(lt*Lt),qt=e.BASE.mulAddUnsafe(ve,tt,Ve);if(qt.is0())return!1;let _t=qt.toAffine();return!(c.create(_t.x)!==lt||H==="recovered"&&q.recovery!==M(_t.x,_t.y,lt))}catch{return!1}}function C(E,m,v={}){let{prehash:L}=Xs(v,A);return m=_(m,L),O.fromBytes(E,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:d,getPublicKey:b,getSharedSecret:g,utils:I,lengths:w,Point:e,sign:x,verify:S,recoverPublicKey:C,Signature:O,hash:n})}var ei={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Pf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ya=BigInt(2);function Of(e){let t=ei.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,u=f*f*e%t,h=G(u,r,t)*u%t,l=G(h,r,t)*u%t,d=G(l,ya,t)*f%t,b=G(d,s,t)*d%t,g=G(b,i,t)*b%t,I=G(g,a,t)*g%t,w=G(I,c,t)*I%t,A=G(w,a,t)*g%t,y=G(A,r,t)*u%t,B=G(y,o,t)*b%t,T=G(B,n,t)*f%t,F=G(T,ya,t);if(!ti.eql(ti.sqr(F),e))throw new Error("Cannot find square root");return F}var ti=Fe(ei.p,{sqrt:Of}),Nf=ha(ei,{Fp:ti,endo:Pf}),qe=ma(Nf,Pe);function ba(e,t,r,n){let s=ue.digest(r instanceof Uint8Array?r:r.subarray());if(rn(s))return s.then(({digest:i})=>(n?.signal?.throwIfAborted(),qe.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new ar(String(i))});try{return n?.signal?.throwIfAborted(),qe.verify(t,s.digest,e,{prehash:!1,format:"der"})}catch(i){throw new ar(String(i))}}var fn=class{type="secp256k1";raw;_key;constructor(t){this._key=wa(t),this.raw=ga(this._key)}toMultihash(){return Bt.digest(kt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,r,n){return ba(this._key,r,t,n)}};function ri(e){return new fn(e)}function ga(e){return qe.Point.fromBytes(e).toBytes()}function wa(e){try{return qe.Point.fromBytes(e),e}catch(t){throw new Ae(String(t))}}function ni(e,t){let{Type:r,Data:n}=Pt.decode(e),s=n??new Uint8Array;switch(r){case Q.RSA:return js(s,t);case Q.Ed25519:return xs(s);case Q.secp256k1:return ri(s);case Q.ECDSA:return Yn(s);default:throw new oe}}function xa(e){let{Type:t,Data:r}=Pt.decode(e.digest),n=r??new Uint8Array;switch(t){case Q.Ed25519:return xs(n);case Q.secp256k1:return ri(n);case Q.ECDSA:return Yn(n);default:throw new oe}}function kt(e){return Pt.encode({Type:Q[e.type],Data:e.raw})}var Ea=Symbol.for("nodejs.util.inspect.custom"),kf=114,dr=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()})`}[wn]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(kf,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")}[Ea](){return`PeerId(${this.toString()})`}},pr=class extends dr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},mr=class extends dr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},yr=class extends dr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Kf=2336,ln=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Bt.digest(Y(this.url))}[Ea](){return`PeerId(${this.url})`}[wn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Kf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=j(t)),t.toString()===this.toString())}};function si(e){if(e.type==="Ed25519")return new mr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new yr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new pr({multihash:e.toCID().multihash,publicKey:e});throw new oe}function Sa(e){return si(e.publicKey)}function br(e){if(Mf(e))return new pr({multihash:e});if(Ff(e))try{let t=xa(e);if(t.type==="Ed25519")return new mr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new yr({multihash:e,publicKey:t})}catch{let r=j(e.digest);return new ln(new URL(r))}throw new Br("Supplied PeerID Multihash is invalid")}function Ff(e){return e.code===Bt.code}function Mf(e){return e.code===ue.code}function xe(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:t(s)}}};return r}function hn(e){let t=zt(X.decode(`z${e}`));return br(t)}var gr=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 xe(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 xe(this.map.values(),t=>t.key)}values(){return xe(this.map.values(),t=>t.value)}get size(){return this.map.size}};var wr=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 xe(this.set.entries(),t=>{let r=hn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=hn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return xe(this.set.values(),t=>hn(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 ii=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},va=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function xr(e,t){let{milliseconds:r,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=t,a,c,u=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(va(o));return}if(o&&(c=()=>{l(va(o))},o.addEventListener("abort",c,{once:!0})),e.then(h,l),r===Number.POSITIVE_INFINITY)return;let d=new ii;a=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(b){l(b)}return}typeof e.cancel=="function"&&e.cancel(),s===!1?h():s instanceof Error?l(s):(d.message=s??`Promise timed out after ${r} milliseconds`,l(d))},r)}).finally(()=>{u.clear(),c&&o&&o.removeEventListener("abort",c)});return u.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},u}var Uf=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 qf(e,t,r){let n,s=new Promise((i,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 a=[t].flat(),c=[],{addListener:f,removeListener:u}=Uf(e),h=async(...d)=>{let b=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(b))return}catch(g){n(),o(g);return}c.push(b),r.count===c.length&&(n(),i(c))},l=(...d)=>{n(),o(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)u(d,h);for(let d of r.rejectionEvents)a.includes(d)||u(d,l)};for(let d of a)f(d,h);for(let d of r.rejectionEvents)a.includes(d)||f(d,l);r.signal&&r.signal.addEventListener("abort",()=>{l(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(s.cancel=n,typeof r.timeout=="number"){let i=xr(s,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return s}function Aa(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=qf(e,t,r),s=n.then(i=>i[0]);return s.cancel=n.cancel,s}var Ee=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Hf(e){return e.reason}async function oi(e,t,r){if(t==null)return e;let n=r?.translateError??Hf;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let s;try{return await Promise.race([e,new Promise((i,o)=>{s=()=>{o(n(t))},t.addEventListener("abort",s)})])}finally{s!=null&&t.removeEventListener("abort",s)}}var Vf=4194304,dn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ci=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ui=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},fi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function $f(e){return typeof e?.closeRead=="function"}function jf(e){return typeof e?.close=="function"}function ai(e){return $f(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:jf(e)?e.status!=="open":!1}function Yf(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Zf(e,t){let r=t?.maxBufferSize??Vf,n=new it,s,i=!1;if(!Yf(e))throw new W("Argument should be a Stream or a Multiaddr");let o=u=>{if(n.append(u.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}s?.resolve()};e.addEventListener("message",o);let a=u=>{u.error!=null?s?.reject(u.error):s?.resolve()};e.addEventListener("close",a);let c=()=>{s?.resolve()};e.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(u){if(i===!0)throw new dn("Stream was unwrapped");if(ai(e)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new Ee(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let h=u?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=h){s.resolve();break}if(await oi(s.promise,u?.signal),ai(e)){if(n.byteLength===0&&u?.bytes==null)return null;break}s=Promise.withResolvers()}let l=u?.bytes??n.byteLength;if(n.byteLength<l){if(ai(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,l),new Ee(`Unexpected EOF - stream closed while reading ${n.byteLength}/${l} bytes`);return f.read(u)}let d=n.sublist(0,l);return n.consume(l),d},async write(u,h){if(i===!0)throw new dn("Stream was unwrapped");e.send(u)||await Aa(e,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,e.removeEventListener("message",o),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n))),e}};return f}function Gf(e,t={}){let r=Zf(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ft(t.maxDataLength));let n=t?.lengthDecoder??jo,s=t?.lengthEncoder??$o;return{async read(o){let a=-1,c=new it;for(;;){let u=await r.read({...o,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new ci("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new fi(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new ui(`Message length too long - ${a} > ${t.maxDataLength}`);let f=await r.read({...o,bytes:a});if(f==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new Ee(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new Ee(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(o,a){await r.write(new it(s(o.byteLength),o),a)},async writeV(o,a){let c=new it(...o.flatMap(f=>[s(f.byteLength),f]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function li(e,t){let r=Gf(e,t),n={read:async(s,i)=>{let o=await r.read(i);return s.decode(o,i)},write:async(s,i,o)=>{await r.write(i.encode(s),o)},writeV:async(s,i,o)=>{await r.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:()=>r.unwrap()};return n}var di=$a(Ia(),1);function pi(e,t,r){let n=0,s=e.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;r(e[o],t)<=0?(n=++o,s-=i+1):s=i}return n}var Jf=100,He=class{#t=[];#e=0;enqueue(t,r){let{priority:n=0,id:s}=r??{},{size:i}=this,o={priority:n,id:s,run:t};if(i===0){this.#t.length=0,this.#e=0,this.#t.push(o);return}if(this.#t.at(-1).priority>=n){this.#t.push(o);return}this.#i();let a=pi(this.#t,o,(c,f)=>f.priority-c.priority);this.#t.splice(a,0,o)}setPriority(t,r){let n=this.#t.findIndex((i,o)=>o>=this.#e&&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:r,id:t})}remove(t){let r=this.#t.findIndex((n,s)=>s<this.#e?!1:typeof t=="string"?n.id===t:n.run===t);r!==-1&&this.#t.splice(r,1)}dequeue(){if(this.#e===this.#t.length)return;let t=this.#t[this.#e];return this.#e++,this.#e===this.#t.length?(this.#t.length=0,this.#e=0):this.#e>Jf&&this.#e>this.#t.length/2&&this.#i(),t?.run}filter(t){let r=[];for(let n=this.#e;n<this.#t.length;n++){let s=this.#t[n];s.priority===t.priority&&r.push(s.run)}return r}get size(){return this.#t.length-this.#e}#i(){this.#e!==0&&(this.#t.splice(0,this.#e),this.#e=0)}};var Sr=class extends di.default{#t;#e;#i=0;#d;#m=!1;#w=!1;#u;#x=0;#c;#f;#a;#o=[];#s=0;#r;#I;#n=0;#y;#l;#C=1n;#b=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:He,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.#e=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#u=t.interval,this.#a=t.strict,this.#r=new t.queueClass,this.#I=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.#U()}#S(t){for(;this.#s<this.#o.length;){let n=this.#o[this.#s];if(n!==void 0&&t-n>=this.#u)this.#s++;else break}(this.#s>100&&this.#s>this.#o.length/2||this.#s===this.#o.length)&&(this.#o=this.#o.slice(this.#s),this.#s=0)}#P(t){this.#a?this.#o.push(t):this.#i++}#O(){this.#a?this.#o.length>this.#s&&this.#o.pop():this.#i>0&&this.#i--}#v(){return this.#o.length-this.#s}get#N(){return this.#e?!0:this.#a?this.#v()<this.#d:this.#i<this.#d}get#k(){return this.#n<this.#y}#K(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#F(){this.#f=void 0,this.#R(),this.#_()}#M(t){if(this.#a){if(this.#S(t),this.#v()>=this.#d){let n=this.#o[this.#s],s=this.#u-(t-n);return this.#T(s),!0}return!1}if(this.#c===void 0){let r=this.#x-t;if(r<0)this.#i=this.#t?this.#n:0;else return this.#T(r),!0}return!1}#T(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#F()},t))}#A(){this.#c&&(clearInterval(this.#c),this.#c=void 0)}#L(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#g(){if(this.#r.size===0){if(this.#A(),this.emit("empty"),this.#n===0){if(this.#L(),this.#a&&this.#s>0){let r=Date.now();this.#S(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#M(r);if(this.#N&&this.#k){let s=this.#r.dequeue();this.#e||(this.#P(r),this.#p()),n&&this.#_(),this.emit("active"),s(),t=!0}}return t}#_(){this.#e||this.#c!==void 0||this.#a||(this.#c=setInterval(()=>{this.#R()},this.#u),this.#x=Date.now()+this.#u)}#R(){this.#a||(this.#c!==void 0&&(this.#i===0&&this.#n===0?this.#A():this.#x=Date.now()+this.#u),this.#i=this.#t?this.#n:0),this.#B(),this.#p()}#B(){for(;this.#g(););}get concurrency(){return this.#y}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.#y=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.#r.setPriority(t,r)}async add(t,r={}){if(r={timeout:this.timeout,...r,id:r.id??(this.#C++).toString()},r.timeout!==void 0&&!(Number.isFinite(r.timeout)&&r.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${r.timeout}\` (${typeof r.timeout})`);return new Promise((n,s)=>{let i=Symbol(`task-${r.id}`),o=()=>{},a=async()=>{o(),this.#n++,this.#b.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let f;try{try{r.signal?.throwIfAborted()}catch(l){throw this.#q(),this.#b.delete(i),l}let u=t({signal:r.signal});if(r.timeout!==void 0&&(u=xr(Promise.resolve(u),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),r.signal){let{signal:l}=r;u=Promise.race([u,new Promise((d,b)=>{f=()=>{b(l.reason)},l.addEventListener("abort",f,{once:!0})})])}let h=await u;n(h),this.emit("completed",h)}catch(u){s(u),this.emit("error",u)}finally{f&&r.signal?.removeEventListener("abort",f),this.#b.delete(i),queueMicrotask(()=>{this.#K()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof He){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:f}=r,u=()=>{o(),c(),s(f.reason),this.#g(),this.emit("next")};if(o=()=>{f.removeEventListener("abort",u),this.#E.delete(o)},f.aborted){u();return}f.addEventListener("abort",u,{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.#r=new this.#I,this.#A(),this.#D(),this.emit("empty"),this.#n===0&&(this.#L(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#r.size<t||await this.#h(["next","active"],()=>this.#r.size<t)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#h("idle")}async onPendingZero(){this.#n!==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=s=>{this.off("error",n),r(s)};this.on("error",n)})}async#h(t,r){let n=Array.isArray(t)?t:[t];return new Promise(s=>{let i=()=>{if(!(r&&!r())){for(let o of n)this.off(o,i);s()}};for(let o of n)this.on(o,i)})}get size(){return this.#r.size}sizeBy(t){return this.#r.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#l}#U(){this.#e||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#e||this.#w||(this.#w=!0,queueMicrotask(()=>{this.#w=!1,this.#D()}))}#q(){this.#e||(this.#O(),this.#p())}#D(){let t=this.#m;if(this.#e||this.#r.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let s=Date.now();this.#S(s),r=this.#v()}else r=this.#i;let n=r>=this.#d;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#n===this.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#b.values()].map(t=>({...t,timeoutRemaining:t.timeout?Math.max(0,t.startTime+t.timeout-Date.now()):void 0}))}};var mn=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 Ta={maxSubscriptions:5e3,maxMessages:5e3};function La(e){return{subscriptions:e.maxSubscriptions,messages:e.maxMessages}}var Se;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=ie((l,d,b={})=>{b.lengthDelimited!==!1&&d.fork(),l.subscribe!=null&&(d.uint32(8),d.bool(l.subscribe)),l.topic!=null&&(d.uint32(18),d.string(l.topic)),b.lengthDelimited!==!1&&d.ldelim()},(l,d,b={})=>{let g={},I=d==null?l.len:l.pos+d;for(;l.pos<I;){let w=l.uint32();switch(w>>>3){case 1:{g.subscribe=l.bool();break}case 2:{g.topic=l.string();break}default:{l.skipType(w&7);break}}}return g},function*(l,d,b,g={}){let I=d==null?l.len:l.pos+d;for(;l.pos<I;){let w=l.uint32();switch(w>>>3){case 1:{yield{field:`${b}.subscribe`,value:l.bool()};break}case 2:{yield{field:`${b}.topic`,value:l.string()};break}default:{l.skipType(w&7);break}}}})),c);function f(l){return ne(l,a.codec())}a.encode=f;function u(l,d){return re(l,a.codec(),d)}a.decode=u;function h(l,d){return se(l,a.codec(),d)}a.stream=h})(t=e.SubOpts||(e.SubOpts={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=ie((l,d,b={})=>{b.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)),b.lengthDelimited!==!1&&d.ldelim()},(l,d,b={})=>{let g={},I=d==null?l.len:l.pos+d;for(;l.pos<I;){let w=l.uint32();switch(w>>>3){case 1:{g.from=l.bytes();break}case 2:{g.data=l.bytes();break}case 3:{g.sequenceNumber=l.bytes();break}case 4:{g.topic=l.string();break}case 5:{g.signature=l.bytes();break}case 6:{g.key=l.bytes();break}default:{l.skipType(w&7);break}}}return g},function*(l,d,b,g={}){let I=d==null?l.len:l.pos+d;for(;l.pos<I;){let w=l.uint32();switch(w>>>3){case 1:{yield{field:`${b}.from`,value:l.bytes()};break}case 2:{yield{field:`${b}.data`,value:l.bytes()};break}case 3:{yield{field:`${b}.sequenceNumber`,value:l.bytes()};break}case 4:{yield{field:`${b}.topic`,value:l.string()};break}case 5:{yield{field:`${b}.signature`,value:l.bytes()};break}case 6:{yield{field:`${b}.key`,value:l.bytes()};break}default:{l.skipType(w&7);break}}}})),c);function f(l){return ne(l,a.codec())}a.encode=f;function u(l,d){return re(l,a.codec(),d)}a.decode=u;function h(l,d){return se(l,a.codec(),d)}a.stream=h})(r=e.Message||(e.Message={}));let n;e.codec=()=>(n==null&&(n=ie((a,c,f={})=>{if(f.lengthDelimited!==!1&&c.fork(),a.subscriptions!=null&&a.subscriptions.length>0)for(let u of a.subscriptions)c.uint32(10),e.SubOpts.codec().encode(u,c);if(a.messages!=null&&a.messages.length>0)for(let u of a.messages)c.uint32(18),e.Message.codec().encode(u,c);f.lengthDelimited!==!1&&c.ldelim()},(a,c,f={})=>{let u={subscriptions:[],messages:[]},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let l=a.uint32();switch(l>>>3){case 1:{if(f.limits?.subscriptions!=null&&u.subscriptions.length===f.limits.subscriptions)throw new ge('Decode error - repeated field "subscriptions" had too many elements');u.subscriptions.push(e.SubOpts.codec().decode(a,a.uint32(),{limits:f.limits?.subscriptions$}));break}case 2:{if(f.limits?.messages!=null&&u.messages.length===f.limits.messages)throw new ge('Decode error - repeated field "messages" had too many elements');u.messages.push(e.Message.codec().decode(a,a.uint32(),{limits:f.limits?.messages$}));break}default:{a.skipType(l&7);break}}}return u},function*(a,c,f,u={}){let h={subscriptions:0,messages:0},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{if(u.limits?.subscriptions!=null&&h.subscriptions===u.limits.subscriptions)throw new ge('Streaming decode error - repeated field "subscriptions" had too many elements');for(let b of e.SubOpts.codec().stream(a,a.uint32(),`${f}.subscriptions[]`,{limits:u.limits?.subscriptions$}))yield{...b,index:h.subscriptions};h.subscriptions++;break}case 2:{if(u.limits?.messages!=null&&h.messages===u.limits.messages)throw new ge('Streaming decode error - repeated field "messages" had too many elements');for(let b of e.Message.codec().stream(a,a.uint32(),`${f}.messages[]`,{limits:u.limits?.messages$}))yield{...b,index:h.messages};h.messages++;break}default:{a.skipType(d&7);break}}}})),n);function s(a){return ne(a,e.codec())}e.encode=s;function i(a,c){return re(a,e.codec(),c)}e.decode=i;function o(a,c){return se(a,e.codec(),c)}e.stream=o})(Se||(Se={}));var yn=class extends Be{peerId;shutDownController;inboundPb;outboundPb;constructor(t){super(),this.peerId=t,this.shutDownController=new AbortController}attachInboundStream(t,r,n){this.inboundPb=li(t,r).pb(Se),Promise.resolve().then(async()=>{for(;;){if(this.inboundPb==null)return;let s=await this.inboundPb.read({signal:this.shutDownController.signal,limits:n});this.safeDispatchEvent("message",{detail:s})}}).catch(s=>{this.inboundPb?.unwrap().unwrap().abort(s),this.close()})}attachOutboundStream(t,r){this.outboundPb=li(t,r).pb(Se)}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 _a(){return BigInt(`0x${j(crypto.getRandomValues(new Uint8Array(8)),"base16")}`)}var Ra=(e,t)=>{let r=Y(t.toString(16).padStart(16,"0"),"base16"),n=kt(e),s=new Uint8Array(n.byteLength+r.length);return s.set(n,0),s.set(r,n.byteLength),s},Da=e=>ue.encode(e);var Qf=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=br(zt(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return si(ni(r)).equals(t)}return!1},Ca=async e=>{if(e.from==null)throw new nt("RPC message was missing from");if(!await Qf(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=br(zt(e.from)),r=e.key??t.publicKey;if(r==null)throw new nt("RPC message was missing public key");return{type:"signed",from:t,topic:e.topic??"",sequenceNumber:el(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?ni(r):r}},vr=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:tl(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?kt(e.key):void 0}:{data:e.data,topic:e.topic},tl=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),Y(t,"base16")},el=e=>BigInt(`0x${j(e,"base16")}`);var Pa=Y("libp2p-pubsub:");async function Oa(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Sa(e)},s=ce([Pa,r(vr(n)).subarray()]);return n.signature=await e.sign(s),n.key=e.publicKey,n}async function Na(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=ce([Pa,t({...vr(e),signature:void 0,key:void 0}).subarray()]);return rl(e).verify(r,e.signature)}function rl(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.from.publicKey!=null)return e.from.publicKey;if(e.key!=null&&e.from.equals(e.key.toMultihash().bytes))return e.key;throw new Error("Could not get the public key from the originator id")}var bn=class extends Be{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;decodeRpcLimits;constructor(t,r){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocol=r.protocol??mi,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new gr,this.globalSignaturePolicy=r.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=r.canRelayMessage??!0,this.emitSelf=r.emitSelf??!1,this.topicValidators=new Map,this.queue=new Sr({concurrency:r.messageProcessingConcurrency??10}),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.seenCache=new mn({validityMs:r?.seenTTL??3e4}),this.decodeRpcLimits=La(r.decodeRpcLimits??Ta),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[je]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[gi]=["@libp2p/pubsub"];[wi]=["@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.topics.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,void 0,this.decodeRpcLimits)}async _onPeerConnected(t,r){if(this.log("connected %p",t),r.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 r.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,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 s=new yn(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 r=this.peers.get(t);if(r!=null){r.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let[n,s]of this.topics)s.delete(t),s.size===0&&this.topics.delete(n)}}async processRpc(t,r){this.log("rpc from %p",t.peerId);let{subscriptions:n,messages:s}=r;return n!=null&&n.length>0&&(this.log("subscription update from %p",t.peerId),n.forEach(i=>{this.processRpcSubOpt(t.peerId,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:t.peerId,subscriptions:n.map(({topic:i,subscribe:o})=>({topic:`${i??""}`,subscribe:!!o}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t.peerId),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let o=await Ca(i);await this.processMessage(t.peerId,o)}catch(o){this.log.error("failed to queue messages from %p - %e",t.peerId,o)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,r){let n=r.topic;if(n==null)return;let s=this.topics.get(n);r.subscribe===!0?(s==null&&(s=new wr,this.topics.set(n,s)),s.add(t)):s!=null&&(s.delete(t),s.size===0&&this.topics.delete(n))}async processMessage(t,r){if(this.components.peerId.equals(t)&&!this.emitSelf)return;let n=await this.getMsgId(r),s=j(n,"base64");if(!this.seenCache.has(s)){this.seenCache.put(s,!0);try{await this.validate(t,r)}catch(i){this.log("Message is invalid, dropping it. %O",i);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 nt('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new nt("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new nt("Need key when signature policy is StrictSign but it was missing");return Ra(t.key,t.sequenceNumber);case"StrictNoSign":return Da(t.data);default:throw new nt("Cannot get message id: unhandled signature policy")}}encodeMessage(t){return Se.Message.encode(t)}send(t,r){let{messages:n,subscriptions:s,subscribe:i}=r;this.sendRpc(t,{subscriptions:(s??[]).map(o=>({topic:o,subscribe:!!i})),messages:(n??[]).map(vr)})}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 nt('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new nt("StrictNoSigning: signature should not be present");if(r.key!=null)throw new nt("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new nt("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new nt('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new nt("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new nt("StrictSigning: Signing required and no sequenceNumber was present");if(!await Na(r,this.encodeMessage.bind(this)))throw new nt("StrictSigning: Invalid message signature");break;default:throw new nt("Cannot validate message: unhandled signature policy")}let s=this.topicValidators.get(r.topic);if(s!=null){let i=await s(t,r);if(i===ze.Reject||i===ze.Ignore)throw new nt("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 nt("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Ir("not started yet");if(t==null)throw new W("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:_a()};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,r){let n=this.getSubscribers(r.topic),s=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:s}):(n.forEach(i=>{if(this.components.peerId.equals(i)){this.log("not sending message on topic %s to myself",r.topic);return}if(i.equals(t)){this.log("not sending message on topic %s to sender %p",r.topic,i);return}this.log("publish msgs on topics %s %p",r.topic,i),s.push(i),this.send(i,{messages:[r]})}),{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 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 mi="/floodsub/1.0.0",nl="StrictSign",sl="StrictNoSign",ze;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(ze||(ze={}));function il(e){return!!e?.[je]}function ol(e={}){return t=>new bn(t,e)}return ja(al);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js:
@@ -7,6 +7,7 @@
7
7
  @noble/curves/abstract/curve.js:
8
8
  @noble/curves/abstract/edwards.js:
9
9
  @noble/curves/ed25519.js:
10
+ @noble/curves/abstract/der.js:
10
11
  @noble/curves/abstract/weierstrass.js:
11
12
  @noble/curves/secp256k1.js:
12
13
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)