@libp2p/pubsub 10.1.17-79473c99a → 10.1.17-cb1c14e62

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.Libp2PPubsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PPubsub=(()=>{var fa=Object.create;var br=Object.defineProperty;var la=Object.getOwnPropertyDescriptor;var ha=Object.getOwnPropertyNames;var da=Object.getPrototypeOf,pa=Object.prototype.hasOwnProperty;var ma=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ht=(r,t)=>{for(var e in t)br(r,e,{get:t[e],enumerable:!0})},Yo=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ha(t))!pa.call(r,o)&&o!==e&&br(r,o,{get:()=>t[o],enumerable:!(n=la(t,o))||n.enumerable});return r};var ya=(r,t,e)=>(e=r!=null?fa(da(r)):{},Yo(t||!r||!r.__esModule?br(e,"default",{value:r,enumerable:!0}):e,r)),ba=r=>Yo(br({},"__esModule",{value:!0}),r);var Yi=ma((F0,zo)=>{"use strict";var af=Object.prototype.hasOwnProperty,lt="~";function fr(){}Object.create&&(fr.prototype=Object.create(null),new fr().__proto__||(lt=!1));function cf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function $i(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new cf(e,n||r,o),i=lt?lt+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function en(r,t){--r._eventsCount===0?r._events=new fr:delete r._events[t]}function at(){this._events=new fr,this._eventsCount=0}at.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)af.call(e,n)&&t.push(lt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};at.prototype.listeners=function(t){var e=lt?lt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};at.prototype.listenerCount=function(t){var e=lt?lt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};at.prototype.emit=function(t,e,n,o,s,i){var a=lt?lt+t:t;if(!this._events[a])return!1;var c=this._events[a],l=arguments.length,u,f;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,s),!0;case 6:return c.fn.call(c.context,e,n,o,s,i),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var b=c.length,p;for(f=0;f<b;f++)switch(c[f].once&&this.removeListener(t,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,e);break;case 3:c[f].fn.call(c[f].context,e,n);break;case 4:c[f].fn.call(c[f].context,e,n,o);break;default:if(!u)for(p=1,u=new Array(l-1);p<l;p++)u[p-1]=arguments[p];c[f].fn.apply(c[f].context,u)}}return!0};at.prototype.on=function(t,e,n){return $i(this,t,e,n,!1)};at.prototype.once=function(t,e,n){return $i(this,t,e,n,!0)};at.prototype.removeListener=function(t,e,n,o){var s=lt?lt+t:t;if(!this._events[s])return this;if(!e)return en(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&en(this,s);else{for(var a=0,c=[],l=i.length;a<l;a++)(i[a].fn!==e||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:en(this,s)}return this};at.prototype.removeAllListeners=function(t){var e;return t?(e=lt?lt+t:t,this._events[e]&&en(this,e)):(this._events=new fr,this._eventsCount=0),this};at.prototype.off=at.prototype.removeListener;at.prototype.addListener=at.prototype.on;at.prefixed=lt;at.EventEmitter=at;typeof zo<"u"&&(zo.exports=at)});var mf={};ht(mf,{PubSubBaseProtocol:()=>$o});var ln=Symbol.for("@libp2p/peer-id");var Ke;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ke||(Ke={}));var gf=Symbol.for("@libp2p/pubsub");var V=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},he=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var gr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var $=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var wr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var Yt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var de=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var yn={};ht(yn,{base58btc:()=>F,base58flickr:()=>Aa});var Sf=new Uint8Array(0);function Wo(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Lt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Xo(r){return new TextEncoder().encode(r)}function Jo(r){return new TextDecoder().decode(r)}function ga(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(v){if(v instanceof Uint8Array||(ArrayBuffer.isView(v)?v=new Uint8Array(v.buffer,v.byteOffset,v.byteLength):Array.isArray(v)&&(v=Uint8Array.from(v))),!(v instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(v.length===0)return"";for(var x=0,d=0,S=0,L=v.length;S!==L&&v[S]===0;)S++,x++;for(var A=(L-S)*u+1>>>0,D=new Uint8Array(A);S!==L;){for(var y=v[S],C=0,P=A-1;(y!==0||C<d)&&P!==-1;P--,C++)y+=256*D[P]>>>0,D[P]=y%a>>>0,y=y/a>>>0;if(y!==0)throw new Error("Non-zero carry");d=C,S++}for(var B=A-d;B!==A&&D[B]===0;)B++;for(var h=c.repeat(x);B<A;++B)h+=r.charAt(D[B]);return h}function b(v){if(typeof v!="string")throw new TypeError("Expected String");if(v.length===0)return new Uint8Array;var x=0;if(v[x]!==" "){for(var d=0,S=0;v[x]===c;)d++,x++;for(var L=(v.length-x)*l+1>>>0,A=new Uint8Array(L);v[x];){var D=e[v.charCodeAt(x)];if(D===255)return;for(var y=0,C=L-1;(D!==0||y<S)&&C!==-1;C--,y++)D+=a*A[C]>>>0,A[C]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");S=y,x++}if(v[x]!==" "){for(var P=L-S;P!==L&&A[P]===0;)P++;for(var B=new Uint8Array(d+(L-P)),h=d;P!==L;)B[h++]=A[P++];return B}}}function p(v){var x=b(v);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:b,decode:p}}var wa=ga,xa=wa,ts=xa;var hn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},dn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return es(this,t)}},pn=class{decoders;constructor(t){this.decoders=t}or(t){return es(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function es(r,t){return new pn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var mn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new hn(t,e,n),this.decoder=new dn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function pe({name:r,prefix:t,encode:e,decode:n}){return new mn(r,t,e,n)}function Mt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ts(e,r);return pe({prefix:t,name:r,encode:n,decode:s=>Lt(o(s))})}function Ea(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let u=t[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Sa(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function va(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function j({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=va(n);return pe({prefix:t,name:r,encode(s){return Sa(s,n,e)},decode(s){return Ea(s,o,e,r)}})}var F=Mt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Aa=Mt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var bn={};ht(bn,{base32:()=>me,base32hex:()=>La,base32hexpad:()=>Pa,base32hexpadupper:()=>Ca,base32hexupper:()=>Ta,base32pad:()=>Ba,base32padupper:()=>_a,base32upper:()=>Ia,base32z:()=>Da});var me=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ia=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ba=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_a=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),La=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ta=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Pa=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ca=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Da=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var gn={};ht(gn,{base36:()=>Ue,base36upper:()=>Na});var Ue=Mt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Na=Mt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ra=os,rs=128,Ka=127,Ua=~Ka,ka=Math.pow(2,31);function os(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ka;)t[e++]=r&255|rs,r/=128;for(;r&Ua;)t[e++]=r&255|rs,r>>>=7;return t[e]=r|0,os.bytes=e-n+1,t}var Ma=wn,Oa=128,ns=127;function wn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw wn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ns)<<o:(i&ns)*Math.pow(2,o),o+=7}while(i>=Oa);return wn.bytes=s-n,e}var Ha=Math.pow(2,7),qa=Math.pow(2,14),za=Math.pow(2,21),Va=Math.pow(2,28),Fa=Math.pow(2,35),Ga=Math.pow(2,42),ja=Math.pow(2,49),Za=Math.pow(2,56),$a=Math.pow(2,63),Ya=function(r){return r<Ha?1:r<qa?2:r<za?3:r<Va?4:r<Fa?5:r<Ga?6:r<ja?7:r<Za?8:r<$a?9:10},Wa={encode:Ra,decode:Ma,encodingLength:Ya},Xa=Wa,ke=Xa;function Me(r,t=0){return[ke.decode(r,t),ke.decode.bytes]}function ye(r,t,e=0){return ke.encode(r,t,e),t}function be(r){return ke.encodingLength(r)}function gt(r,t){let e=t.byteLength,n=be(r),o=n+be(e),s=new Uint8Array(o+e);return ye(r,s,0),ye(e,s,n),s.set(t,o),new ge(r,e,t,s)}function Ot(r){let t=Lt(r),[e,n]=Me(t),[o,s]=Me(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ge(e,o,i,t)}function ss(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Wo(r.bytes,e.bytes)}}var ge=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function is(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Qa(e,xn(r),t??F.encoder);default:return tc(e,xn(r),t??me.encoder)}}var as=new WeakMap;function xn(r){let t=as.get(r);if(t==null){let e=new Map;return as.set(r,e),e}return t}var rt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Oe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ec)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=gt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&ss(t.multihash,n.multihash)}toString(t){return is(this,t)}toJSON(){return{"/":is(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??cs(n,o,s.bytes))}else if(e[rc]===!0){let{version:n,multihash:o,code:s}=e,i=Ot(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Oe)throw new Error(`Version 0 CID must use dag-pb (code: ${Oe}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=cs(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Oe,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Lt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new ge(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,b]=Me(t.subarray(e));return e+=b,f},o=n(),s=Oe;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),l=e+c,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,e){let[n,o]=Ja(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return xn(s).set(n,t),s}};function Ja(r,t){switch(r[0]){case"Q":{let e=t??F;return[F.prefix,e.decode(`${F.prefix}${r}`)]}case F.prefix:{let e=t??F;return[F.prefix,e.decode(r)]}case me.prefix:{let e=t??me;return[me.prefix,e.decode(r)]}case Ue.prefix:{let e=t??Ue;return[Ue.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Qa(r,t,e){let{prefix:n}=e;if(n!==F.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function tc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Oe=112,ec=18;function cs(r,t,e){let n=be(r),o=n+be(t),s=new Uint8Array(o+e.byteLength);return ye(r,s,0),ye(t,s,n),s.set(e,o),s}var rc=Symbol.for("@ipld/js-cid/CID");var En={};ht(En,{identity:()=>wt});var us=0,nc="identity",fs=Lt;function oc(r){return gt(us,fs(r))}var wt={code:us,name:nc,encode:fs,digest:oc};function dt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Tt(r=0){return new Uint8Array(r)}function nt(r=0){return new Uint8Array(r)}function Wt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=nt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var hs=Symbol.for("@achingbrain/uint8arraylist");function ls(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Er(r){return!!r?.[hs]}var X=class r{bufs;length;[hs]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Er(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Er(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=ls(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ls(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Er(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Wt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Wt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let l=t>=a&&t<c,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Er(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let b=l;b>=0;b--){let p=this.get(f+b);if(n[b]!==p){u=Math.max(1,b-a[p]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=nt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Tt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Tt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Tt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=nt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Tt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Tt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Tt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Tt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Tt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!dt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Sn={};ht(Sn,{base10:()=>sc});var sc=Mt({prefix:"9",name:"base10",alphabet:"0123456789"});var vn={};ht(vn,{base16:()=>ic,base16upper:()=>ac});var ic=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ac=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var An={};ht(An,{base2:()=>cc});var cc=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var In={};ht(In,{base256emoji:()=>dc});var ds=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}"),uc=ds.reduce((r,t,e)=>(r[e]=t,r),[]),fc=ds.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function lc(r){return r.reduce((t,e)=>(t+=uc[e],t),"")}function hc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=fc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var dc=pe({prefix:"\u{1F680}",name:"base256emoji",encode:lc,decode:hc});var Bn={};ht(Bn,{base64:()=>pc,base64pad:()=>mc,base64url:()=>yc,base64urlpad:()=>bc});var pc=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),mc=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yc=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),bc=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var _n={};ht(_n,{base8:()=>gc});var gc=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ln={};ht(Ln,{identity:()=>wc});var wc=pe({prefix:"\0",name:"identity",encode:r=>Jo(r),decode:r=>Xo(r)});var sl=new TextEncoder,il=new TextDecoder;var Cn={};ht(Cn,{sha256:()=>Xt,sha512:()=>Sc});function Pn({name:r,code:t,encode:e}){return new Tn(r,t,e)}var Tn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?gt(this.code,e):e.then(n=>gt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ms(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Xt=Pn({name:"sha2-256",code:18,encode:ms("SHA-256")}),Sc=Pn({name:"sha2-512",code:19,encode:ms("SHA-512")});var Dn={...Ln,...An,..._n,...Sn,...vn,...bn,...gn,...yn,...Bn,...In},gl={...Cn,...En};function bs(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ys=bs("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Nn=bs("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=nt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),vc={utf8:ys,"utf-8":ys,hex:Dn.base16,latin1:Nn,ascii:Nn,binary:Nn,...Dn},Sr=vc;function M(r,t="utf8"){let e=Sr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function O(r,t="utf8"){let e=Sr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ac=parseInt("11111",2),Rn=parseInt("10000000",2),Ic=parseInt("01111111",2),gs={0:He,1:He,2:Bc,3:Tc,4:Pc,5:Lc,6:_c,16:He,22:He,48:He};function Pt(r,t={offset:0}){let e=r[t.offset]&Ac;if(t.offset++,gs[e]!=null)return gs[e](r,t);throw new Error("No decoder for tag "+e)}function qe(r,t){let e=0;if((r[t.offset]&Rn)===Rn){let n=r[t.offset]&Ic,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function He(r,t){qe(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Pt(r,t);if(n===null)break;e.push(n)}return e}function Bc(r,t){let e=qe(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function _c(r,t){let e=qe(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let l=r[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let u=0;for(let f=0;f<c.length;f++)u+=c[f]<<f*7;a+=`.${u}`,c=[]}}return a}function Lc(r,t){return t.offset++,null}function Tc(r,t){let e=qe(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Pc(r,t){let e=qe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Cc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new X;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Kn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Cc(r.byteLength);return new X(Uint8Array.from([t.byteLength|Rn]),t)}function pt(r){let t=new X,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new X(Uint8Array.from([2]),Kn(t),t)}function vr(r){let t=Uint8Array.from([0]),e=new X(t,r);return new X(Uint8Array.from([3]),Kn(e),e)}function qt(r,t=48){let e=new X;for(let n of r)e.append(n);return new X(Uint8Array.from([t]),Kn(e),e)}async function ws(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Dc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Nc=Uint8Array.from([6,5,43,129,4,0,34]),Rc=Uint8Array.from([6,5,43,129,4,0,35]),Kc={ext:!0,kty:"EC",crv:"P-256"},Uc={ext:!0,kty:"EC",crv:"P-384"},kc={ext:!0,kty:"EC",crv:"P-521"},Un=32,kn=48,Mn=66;function On(r){let t=Pt(r);return xs(t)}function xs(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Un*2+1)return n=O(t.subarray(e,e+Un),"base64url"),o=O(t.subarray(e+Un),"base64url"),new we({...Kc,key_ops:["verify"],x:n,y:o});if(t.byteLength===kn*2+1)return n=O(t.subarray(e,e+kn),"base64url"),o=O(t.subarray(e+kn),"base64url"),new we({...Uc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Mn*2+1)return n=O(t.subarray(e,e+Mn),"base64url"),o=O(t.subarray(e+Mn),"base64url"),new we({...kc,key_ops:["verify"],x:n,y:o});throw new V(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Es(r){return qt([pt(Uint8Array.from([1])),qt([Mc(r.crv)],160),qt([vr(new X(Uint8Array.from([4]),M(r.x??"","base64url"),M(r.y??"","base64url")))],161)]).subarray()}function Mc(r){if(r==="P-256")return Dc;if(r==="P-384")return Nc;if(r==="P-521")return Rc;throw new V(`Invalid curve ${r}`)}var we=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Es(this.jwk)),this._raw}toMultihash(){return wt.digest(Ct(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}async verify(t,e,n){return ws(this.jwk,e,t,n)}};var Jt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ee(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ze(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ot(r,...t){if(!Ee(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function vs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");ze(r.outputLen),ze(r.blockLen)}function Se(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function As(r,t){ot(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Nt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Ar(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function xt(r,t){return r<<32-t|r>>>t}var Is=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Oc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function At(r){if(ot(r),Is)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Oc[r[e]];return t}var Dt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ss(r){if(r>=Dt._0&&r<=Dt._9)return r-Dt._0;if(r>=Dt.A&&r<=Dt.F)return r-(Dt.A-10);if(r>=Dt.a&&r<=Dt.f)return r-(Dt.a-10)}function ve(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Is)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Ss(r.charCodeAt(s)),a=Ss(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Bs(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Ve(r){return typeof r=="string"&&(r=Bs(r)),ot(r),r}function mt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ot(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var xe=class{};function Hn(r){let t=n=>r().update(Ve(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Qt(r=32){if(Jt&&typeof Jt.getRandomValues=="function")return Jt.getRandomValues(new Uint8Array(r));if(Jt&&typeof Jt.randomBytes=="function")return Uint8Array.from(Jt.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Hc(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}function _s(r,t,e){return r&t^~r&e}function Ls(r,t,e){return r&t^r&e^t&e}var Fe=class extends xe{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Ar(this.buffer)}update(t){Se(this),t=Ve(t),ot(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Ar(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Se(this),As(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Nt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;Hc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Ar(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Rt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var tt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ir=BigInt(4294967295),Ts=BigInt(32);function qc(r,t=!1){return t?{h:Number(r&Ir),l:Number(r>>Ts&Ir)}:{h:Number(r>>Ts&Ir)|0,l:Number(r&Ir)|0}}function Ps(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=qc(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var qn=(r,t,e)=>r>>>e,zn=(r,t,e)=>r<<32-e|t>>>e,te=(r,t,e)=>r>>>e|t<<32-e,ee=(r,t,e)=>r<<32-e|t>>>e,Ge=(r,t,e)=>r<<64-e|t>>>e-32,je=(r,t,e)=>r>>>e-32|t<<64-e;function It(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Cs=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ds=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ns=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Rs=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ks=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Us=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Vc=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),zt=new Uint32Array(64),Br=class extends Fe{constructor(t=32){super(64,t,8,!1),this.A=Rt[0]|0,this.B=Rt[1]|0,this.C=Rt[2]|0,this.D=Rt[3]|0,this.E=Rt[4]|0,this.F=Rt[5]|0,this.G=Rt[6]|0,this.H=Rt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)zt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let b=zt[f-15],p=zt[f-2],v=xt(b,7)^xt(b,18)^b>>>3,x=xt(p,17)^xt(p,19)^p>>>10;zt[f]=x+zt[f-7]+v+zt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let b=xt(a,6)^xt(a,11)^xt(a,25),p=u+b+_s(a,c,l)+Vc[f]+zt[f]|0,x=(xt(n,2)^xt(n,13)^xt(n,22))+Ls(n,o,s)|0;u=l,l=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,l,u)}roundClean(){Nt(zt)}destroy(){this.set(0,0,0,0,0,0,0,0),Nt(this.buffer)}};var ks=Ps(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Fc=ks[0],Gc=ks[1],Vt=new Uint32Array(80),Ft=new Uint32Array(80),Vn=class extends Fe{constructor(t=64){super(128,t,16,!1),this.Ah=tt[0]|0,this.Al=tt[1]|0,this.Bh=tt[2]|0,this.Bl=tt[3]|0,this.Ch=tt[4]|0,this.Cl=tt[5]|0,this.Dh=tt[6]|0,this.Dl=tt[7]|0,this.Eh=tt[8]|0,this.El=tt[9]|0,this.Fh=tt[10]|0,this.Fl=tt[11]|0,this.Gh=tt[12]|0,this.Gl=tt[13]|0,this.Hh=tt[14]|0,this.Hl=tt[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:b,Gh:p,Gl:v,Hh:x,Hl:d}=this;return[t,e,n,o,s,i,a,c,l,u,f,b,p,v,x,d]}set(t,e,n,o,s,i,a,c,l,u,f,b,p,v,x,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=b|0,this.Gh=p|0,this.Gl=v|0,this.Hh=x|0,this.Hl=d|0}process(t,e){for(let A=0;A<16;A++,e+=4)Vt[A]=t.getUint32(e),Ft[A]=t.getUint32(e+=4);for(let A=16;A<80;A++){let D=Vt[A-15]|0,y=Ft[A-15]|0,C=te(D,y,1)^te(D,y,8)^qn(D,y,7),P=ee(D,y,1)^ee(D,y,8)^zn(D,y,7),B=Vt[A-2]|0,h=Ft[A-2]|0,w=te(B,h,19)^Ge(B,h,61)^qn(B,h,6),m=ee(B,h,19)^je(B,h,61)^zn(B,h,6),g=Ns(P,m,Ft[A-7],Ft[A-16]),E=Rs(g,C,w,Vt[A-7],Vt[A-16]);Vt[A]=E|0,Ft[A]=g|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:b,Fh:p,Fl:v,Gh:x,Gl:d,Hh:S,Hl:L}=this;for(let A=0;A<80;A++){let D=te(f,b,14)^te(f,b,18)^Ge(f,b,41),y=ee(f,b,14)^ee(f,b,18)^je(f,b,41),C=f&p^~f&x,P=b&v^~b&d,B=Ks(L,y,P,Gc[A],Ft[A]),h=Us(B,S,D,C,Fc[A],Vt[A]),w=B|0,m=te(n,o,28)^Ge(n,o,34)^Ge(n,o,39),g=ee(n,o,28)^je(n,o,34)^je(n,o,39),E=n&s^n&a^s&a,_=o&i^o&c^i&c;S=x|0,L=d|0,x=p|0,d=v|0,p=f|0,v=b|0,{h:f,l:b}=It(l|0,u|0,h|0,w|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let I=Cs(w,g,_);n=Ds(I,h,m,E),o=I|0}({h:n,l:o}=It(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=It(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=It(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=It(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:b}=It(this.Eh|0,this.El|0,f|0,b|0),{h:p,l:v}=It(this.Fh|0,this.Fl|0,p|0,v|0),{h:x,l:d}=It(this.Gh|0,this.Gl|0,x|0,d|0),{h:S,l:L}=It(this.Hh|0,this.Hl|0,S|0,L|0),this.set(n,o,s,i,a,c,l,u,f,b,p,v,x,d,S,L)}roundClean(){Nt(Vt,Ft)}destroy(){Nt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var _r=Hn(()=>new Br);var Ms=Hn(()=>new Vn);var jn=BigInt(0),Gn=BigInt(1);function Kt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function Ze(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Os(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?jn:BigInt("0x"+r)}function Ae(r){return Os(At(r))}function re(r){return ot(r),Os(At(Uint8Array.from(r).reverse()))}function Lr(r,t){return ve(r.toString(16).padStart(t*2,"0"))}function Ie(r,t){return Lr(r,t).reverse()}function q(r,t,e){let n;if(typeof t=="string")try{n=ve(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Ee(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}var Fn=r=>typeof r=="bigint"&&jn<=r;function Hs(r,t,e){return Fn(r)&&Fn(t)&&Fn(e)&&t<=r&&r<e}function Gt(r,t,e,n){if(!Hs(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function qs(r){let t;for(t=0;r>jn;r>>=Gn,t+=1);return t}var ne=r=>(Gn<<BigInt(r))-Gn;function zs(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=p=>new Uint8Array(p),o=p=>Uint8Array.of(p),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},l=(...p)=>e(i,s,...p),u=(p=n(0))=>{i=l(o(0),p),s=l(),p.length!==0&&(i=l(o(1),p),s=l())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,v=[];for(;p<t;){s=l();let x=s.slice();v.push(x),p+=s.length}return mt(...v)};return(p,v)=>{c(),u(p);let x;for(;!(x=v(f()));)u();return c(),x}}function jt(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function Be(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var ut=BigInt(0),Q=BigInt(1),oe=BigInt(2),jc=BigInt(3),Gs=BigInt(4),js=BigInt(5),Zs=BigInt(8);function G(r,t){let e=r%t;return e>=ut?e:t+e}function z(r,t,e){let n=r;for(;t-- >ut;)n*=n,n%=e;return n}function Vs(r,t){if(r===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let e=G(r,t),n=t,o=ut,s=Q,i=Q,a=ut;for(;e!==ut;){let l=n/e,u=n%e,f=o-i*l,b=s-a*l;n=e,e=u,o=i,s=a,i=f,a=b}if(n!==Q)throw new Error("invert: does not exist");return G(o,t)}function $s(r,t){let e=(r.ORDER+Q)/Gs,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function Zc(r,t){let e=(r.ORDER-js)/Zs,n=r.mul(t,oe),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,oe),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function $c(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-Q,e=0;for(;t%oe===ut;)t/=oe,e++;let n=oe,o=Et(r);for(;Fs(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return $s;let s=o.pow(n,t),i=(t+Q)/oe;return function(c,l){if(c.is0(l))return l;if(Fs(c,l)!==1)throw new Error("Cannot find square root");let u=e,f=c.mul(c.ONE,s),b=c.pow(l,t),p=c.pow(l,i);for(;!c.eql(b,c.ONE);){if(c.is0(b))return c.ZERO;let v=1,x=c.sqr(b);for(;!c.eql(x,c.ONE);)if(v++,x=c.sqr(x),v===u)throw new Error("Cannot find square root");let d=Q<<BigInt(u-v-1),S=c.pow(f,d);u=v,f=c.sqr(S),b=c.mul(b,f),p=c.mul(p,S)}return p}}function Yc(r){return r%Gs===jc?$s:r%Zs===js?Zc:$c(r)}var Ys=(r,t)=>(G(r,t)&Q)===Q,Wc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Zn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=Wc.reduce((n,o)=>(n[o]="function",n),t);return jt(r,e),r}function Xc(r,t,e){if(e<ut)throw new Error("invalid exponent, negatives unsupported");if(e===ut)return r.ONE;if(e===Q)return t;let n=r.ONE,o=t;for(;e>ut;)e&Q&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Q;return n}function $e(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function Fs(r,t){let e=(r.ORDER-Q)/oe,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Ws(r,t){t!==void 0&&ze(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Et(r,t,e=!1,n={}){if(r<=ut)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(e=u.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Ws(r,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,l=Object.freeze({ORDER:r,isLE:e,BITS:i,BYTES:a,MASK:ne(i),ZERO:ut,ONE:Q,create:u=>G(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return ut<=u&&u<r},is0:u=>u===ut,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&Q)===Q,neg:u=>G(-u,r),eql:(u,f)=>u===f,sqr:u=>G(u*u,r),add:(u,f)=>G(u+f,r),sub:(u,f)=>G(u-f,r),mul:(u,f)=>G(u*f,r),pow:(u,f)=>Xc(l,u,f),div:(u,f)=>G(u*Vs(f,r),r),sqrN:u=>u*u,addN:(u,f)=>u+f,subN:(u,f)=>u-f,mulN:(u,f)=>u*f,inv:u=>Vs(u,r),sqrt:s||(u=>(c||(c=Yc(r)),c(l,u))),toBytes:u=>e?Ie(u,a):Lr(u,a),fromBytes:u=>{if(u.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);return e?re(u):Ae(u)},invertBatch:u=>$e(l,u),cmov:(u,f,b)=>b?f:u});return Object.freeze(l)}function Xs(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function $n(r){let t=Xs(r);return t+Math.ceil(t/2)}function Js(r,t,e=!1){let n=r.length,o=Xs(t),s=$n(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?re(r):Ae(r),a=G(i,t-Q)+Q;return e?Ie(a,o):Lr(a,o)}var Le=BigInt(0),se=BigInt(1);function _e(r,t){let e=t.negate();return r?e:t}function Tr(r,t,e){let n=t==="pz"?i=>i.pz:i=>i.ez,o=$e(r.Fp,e.map(n));return e.map((i,a)=>i.toAffine(o[a])).map(r.fromAffine)}function ri(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Yn(r,t){ri(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ne(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Qs(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=se);let l=t*n,u=l+Math.abs(a)-1,f=a===0,b=a<0,p=t%2!==0;return{nextN:c,offset:u,isZero:f,isNeg:b,isNegF:p,offsetF:l}}function Jc(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Qc(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var Wn=new WeakMap,ni=new WeakMap;function Xn(r){return ni.get(r)||1}function ti(r){if(r!==Le)throw new Error("invalid wNAF")}function Pr(r,t){return{constTimeNegate:_e,hasPrecomputes(e){return Xn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Le;)n&se&&(o=o.add(s)),s=s.double(),n>>=se;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Yn(n,t),i=[],a=e,c=a;for(let l=0;l<o;l++){c=a,i.push(c);for(let u=1;u<s;u++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=Yn(e,t);for(let c=0;c<a.windows;c++){let{nextN:l,offset:u,isZero:f,isNeg:b,isNegF:p,offsetF:v}=Qs(o,c,a);o=l,f?i=i.add(_e(p,n[v])):s=s.add(_e(b,n[u]))}return ti(o),{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=Yn(e,t);for(let a=0;a<i.windows&&o!==Le;a++){let{nextN:c,offset:l,isZero:u,isNeg:f}=Qs(o,a,i);if(o=c,!u){let b=n[l];s=s.add(f?b.negate():b)}}return ti(o),s},getPrecomputes(e,n,o){let s=Wn.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&(typeof o=="function"&&(s=o(s)),Wn.set(n,s))),s},wNAFCached(e,n,o){let s=Xn(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=Xn(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ri(n,t),ni.set(e,n),Wn.delete(e)}}}function oi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Le||n>Le;)e&se&&(s=s.add(o)),n&se&&(i=i.add(o)),o=o.double(),e>>=se,n>>=se;return{p1:s,p2:i}}function Cr(r,t,e,n){Jc(e,r),Qc(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=qs(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=ne(c),u=new Array(Number(l)+1).fill(i),f=Math.floor((t.BITS-1)/c)*c,b=i;for(let p=f;p>=0;p-=c){u.fill(i);for(let x=0;x<s;x++){let d=n[x],S=Number(d>>BigInt(p)&l);u[S]=u[S].add(e[x])}let v=i;for(let x=u.length-1,d=i;x>0;x--)d=d.add(u[x]),v=v.add(d);if(b=b.add(v),p!==0)for(let x=0;x<c;x++)b=b.double()}return b}function ei(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Zn(t),t}else return Et(r)}function Dr(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Le))throw new Error(`CURVE.${a} must be positive bigint`)}let n=ei(t.p,e.Fp),o=ei(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Bt=BigInt(0),ft=BigInt(1),Jn=BigInt(2),tu=BigInt(8),eu={zip215:!0};function ru(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function nu(r,t={}){let{Fp:e,Fn:n}=Dr("edwards",r,t),{h:o,n:s}=r;jt(t,{},{uvRatio:"function"});let i=Jn<<BigInt(n.BYTES*8)-ft,a=x=>e.create(x),c=t.uvRatio||((x,d)=>{try{return{isValid:!0,value:e.sqrt(e.div(x,d))}}catch{return{isValid:!1,value:Bt}}});if(!ru(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function l(x,d,S=!1){let L=S?ft:Bt;return Gt("coordinate "+x,d,L,i),d}function u(x){if(!(x instanceof p))throw new Error("ExtendedPoint expected")}let f=Be((x,d)=>{let{ex:S,ey:L,ez:A}=x,D=x.is0();d==null&&(d=D?tu:e.inv(A));let y=a(S*d),C=a(L*d),P=a(A*d);if(D)return{x:Bt,y:ft};if(P!==ft)throw new Error("invZ was invalid");return{x:y,y:C}}),b=Be(x=>{let{a:d,d:S}=r;if(x.is0())throw new Error("bad point: ZERO");let{ex:L,ey:A,ez:D,et:y}=x,C=a(L*L),P=a(A*A),B=a(D*D),h=a(B*B),w=a(C*d),m=a(B*a(w+P)),g=a(h+a(S*a(C*P)));if(m!==g)throw new Error("bad point: equation left != right (1)");let E=a(L*A),_=a(D*y);if(E!==_)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(d,S,L,A){this.ex=l("x",d),this.ey=l("y",S),this.ez=l("z",L,!0),this.et=l("t",A),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof p)throw new Error("extended point not allowed");let{x:S,y:L}=d||{};return l("x",S),l("y",L),new p(S,L,ft,a(S*L))}static normalizeZ(d){return Tr(p,"ez",d)}static msm(d,S){return Cr(p,n,d,S)}_setWindowSize(d){this.precompute(d)}precompute(d=8,S=!0){return v.setWindowSize(this,d),S||this.multiply(Jn),this}assertValidity(){b(this)}equals(d){u(d);let{ex:S,ey:L,ez:A}=this,{ex:D,ey:y,ez:C}=d,P=a(S*C),B=a(D*A),h=a(L*C),w=a(y*A);return P===B&&h===w}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:d}=r,{ex:S,ey:L,ez:A}=this,D=a(S*S),y=a(L*L),C=a(Jn*a(A*A)),P=a(d*D),B=S+L,h=a(a(B*B)-D-y),w=P+y,m=w-C,g=P-y,E=a(h*m),_=a(w*g),I=a(h*g),T=a(m*w);return new p(E,_,T,I)}add(d){u(d);let{a:S,d:L}=r,{ex:A,ey:D,ez:y,et:C}=this,{ex:P,ey:B,ez:h,et:w}=d,m=a(A*P),g=a(D*B),E=a(C*L*w),_=a(y*h),I=a((A+D)*(P+B)-m-g),T=_-E,R=_+E,N=a(g-S*m),Z=a(I*T),k=a(R*N),K=a(I*N),W=a(T*R);return new p(Z,k,W,K)}subtract(d){return this.add(d.negate())}multiply(d){let S=d;Gt("scalar",S,ft,s);let{p:L,f:A}=v.wNAFCached(this,S,p.normalizeZ);return p.normalizeZ([L,A])[0]}multiplyUnsafe(d,S=p.ZERO){let L=d;return Gt("scalar",L,Bt,s),L===Bt?p.ZERO:this.is0()||L===ft?this:v.wNAFCachedUnsafe(this,L,p.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return v.wNAFCachedUnsafe(this,s).is0()}toAffine(d){return f(this,d)}clearCofactor(){return o===ft?this:this.multiplyUnsafe(o)}static fromBytes(d,S=!1){return ot(d),this.fromHex(d,S)}static fromHex(d,S=!1){let{d:L,a:A}=r,D=e.BYTES;d=q("pointHex",d,D),Kt("zip215",S);let y=d.slice(),C=d[D-1];y[D-1]=C&-129;let P=re(y),B=S?i:e.ORDER;Gt("pointHex.y",P,Bt,B);let h=a(P*P),w=a(h-ft),m=a(L*h-A),{isValid:g,value:E}=c(w,m);if(!g)throw new Error("Point.fromHex: invalid y coordinate");let _=(E&ft)===ft,I=(C&128)!==0;if(!S&&E===Bt&&I)throw new Error("Point.fromHex: x=0 and x_0=1");return I!==_&&(E=a(-E)),p.fromAffine({x:E,y:P})}static fromPrivateScalar(d){return p.BASE.multiply(d)}toBytes(){let{x:d,y:S}=this.toAffine(),L=Ie(S,e.BYTES);return L[L.length-1]|=d&ft?128:0,L}toRawBytes(){return this.toBytes()}toHex(){return At(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}p.BASE=new p(r.Gx,r.Gy,ft,a(r.Gx*r.Gy)),p.ZERO=new p(Bt,ft,ft,Bt),p.Fp=e,p.Fn=n;let v=Pr(p,n.BYTES*8);return p}function ou(r,t){jt(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:e,hash:n}=t,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,c=t.randomBytes||Qt,l=t.adjustScalarBytes||(y=>y),u=t.domain||((y,C,P)=>{if(Kt("phflag",P),C.length||P)throw new Error("Contexts/pre-hash are not supported");return y});function f(y){return i.create(y)}function b(y){return f(re(y))}function p(y){let C=s.BYTES;y=q("private key",y,C);let P=q("hashed private key",n(y),2*C),B=l(P.slice(0,C)),h=P.slice(C,2*C),w=b(B);return{head:B,prefix:h,scalar:w}}function v(y){let{head:C,prefix:P,scalar:B}=p(y),h=o.multiply(B),w=h.toBytes();return{head:C,prefix:P,scalar:B,point:h,pointBytes:w}}function x(y){return v(y).pointBytes}function d(y=Uint8Array.of(),...C){let P=mt(...C);return b(n(u(P,q("context",y),!!e)))}function S(y,C,P={}){y=q("message",y),e&&(y=e(y));let{prefix:B,scalar:h,pointBytes:w}=v(C),m=d(P.context,B,y),g=o.multiply(m).toBytes(),E=d(P.context,g,w,y),_=f(m+E*h);Gt("signature.s",_,Bt,a);let I=s.BYTES,T=mt(g,Ie(_,I));return q("result",T,I*2)}let L=eu;function A(y,C,P,B=L){let{context:h,zip215:w}=B,m=s.BYTES;y=q("signature",y,2*m),C=q("message",C),P=q("publicKey",P,m),w!==void 0&&Kt("zip215",w),e&&(C=e(C));let g=re(y.slice(m,2*m)),E,_,I;try{E=r.fromHex(P,w),_=r.fromHex(y.slice(0,m),w),I=o.multiplyUnsafe(g)}catch{return!1}if(!w&&E.isSmallOrder())return!1;let T=d(h,_.toBytes(),E.toBytes(),C);return _.add(E.multiplyUnsafe(T)).subtract(I).clearCofactor().is0()}return o.precompute(8),{getPublicKey:x,sign:S,verify:A,utils:{getExtendedPublicKey:v,randomPrivateKey:()=>c(s.BYTES),precompute(y=8,C=r.BASE){return C.precompute(y,!1)}},Point:r}}function su(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Et(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={hash:r.hash,randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function iu(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function si(r){let{CURVE:t,curveOpts:e,eddsaOpts:n}=su(r),o=nu(t,e),s=ou(o,n);return iu(r,s)}var vh=BigInt(0),au=BigInt(1),ii=BigInt(2),Ah=BigInt(3),cu=BigInt(5),uu=BigInt(8),Nr={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:uu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function fu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Nr.p,a=r*r%s*r%s,c=z(a,ii,s)*a%s,l=z(c,au,s)*r%s,u=z(l,cu,s)*l%s,f=z(u,t,s)*u%s,b=z(f,e,s)*f%s,p=z(b,n,s)*b%s,v=z(p,o,s)*p%s,x=z(v,o,s)*p%s,d=z(x,t,s)*u%s;return{pow_p_5_8:z(d,ii,s)*r%s,b2:a}}function lu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ai=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function hu(r,t){let e=Nr.p,n=G(t*t*t,e),o=G(n*n*t,e),s=fu(r*o).pow_p_5_8,i=G(r*n*s,e),a=G(t*i*i,e),c=i,l=G(i*ai,e),u=a===r,f=a===G(-r,e),b=a===G(-r*ai,e);return u&&(i=c),(f||b)&&(i=l),Ys(i,e)&&(i=G(-i,e)),{isValid:u||f,value:i}}var du=Et(Nr.p,void 0,!0),pu={...Nr,Fp:du,hash:Ms,adjustScalarBytes:lu,uvRatio:hu},ci=si(pu);var Ye=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Rr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ui={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Rr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var bt=ui;var Kr=32;var Qn,mu=(async()=>{try{return await bt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function yu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await bt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await bt.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function bu(r,t,e){return ci.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function fi(r,t,e){return Qn==null&&(Qn=await mu),Qn?yu(r,t,e):bu(r,t,e)}function Ur(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var kr=class{type="Ed25519";raw;constructor(t){this.raw=to(t,Kr)}toMultihash(){return wt.digest(Ct(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=fi(this.raw,e,t);return Ur(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function eo(r){return r=to(r,Kr),new kr(r)}function to(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new V(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var wu=Math.pow(2,7),xu=Math.pow(2,14),Eu=Math.pow(2,21),ro=Math.pow(2,28),no=Math.pow(2,35),oo=Math.pow(2,42),so=Math.pow(2,49),U=128,st=127;function St(r){if(r<wu)return 1;if(r<xu)return 2;if(r<Eu)return 3;if(r<ro)return 4;if(r<no)return 5;if(r<oo)return 6;if(r<so)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function io(r,t,e=0){switch(St(r)){case 8:t[e++]=r&255|U,r/=128;case 7:t[e++]=r&255|U,r/=128;case 6:t[e++]=r&255|U,r/=128;case 5:t[e++]=r&255|U,r/=128;case 4:t[e++]=r&255|U,r>>>=7;case 3:t[e++]=r&255|U,r>>>=7;case 2:t[e++]=r&255|U,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Su(r,t,e=0){switch(St(r)){case 8:t.set(e++,r&255|U),r/=128;case 7:t.set(e++,r&255|U),r/=128;case 6:t.set(e++,r&255|U),r/=128;case 5:t.set(e++,r&255|U),r/=128;case 4:t.set(e++,r&255|U),r>>>=7;case 3:t.set(e++,r&255|U),r>>>=7;case 2:t.set(e++,r&255|U),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ao(r,t){let e=r[t],n=0;if(n+=e&st,e<U||(e=r[t+1],n+=(e&st)<<7,e<U)||(e=r[t+2],n+=(e&st)<<14,e<U)||(e=r[t+3],n+=(e&st)<<21,e<U)||(e=r[t+4],n+=(e&st)*ro,e<U)||(e=r[t+5],n+=(e&st)*no,e<U)||(e=r[t+6],n+=(e&st)*oo,e<U)||(e=r[t+7],n+=(e&st)*so,e<U))return n;throw new RangeError("Could not decode varint")}function vu(r,t){let e=r.get(t),n=0;if(n+=e&st,e<U||(e=r.get(t+1),n+=(e&st)<<7,e<U)||(e=r.get(t+2),n+=(e&st)<<14,e<U)||(e=r.get(t+3),n+=(e&st)<<21,e<U)||(e=r.get(t+4),n+=(e&st)*ro,e<U)||(e=r.get(t+5),n+=(e&st)*no,e<U)||(e=r.get(t+6),n+=(e&st)*oo,e<U)||(e=r.get(t+7),n+=(e&st)*so,e<U))return n;throw new RangeError("Could not decode varint")}function hi(r,t,e=0){return t==null&&(t=nt(St(r))),t instanceof Uint8Array?io(r,t,e):Su(r,t,e)}function di(r,t=0){return r instanceof Uint8Array?ao(r,t):vu(r,t)}var co=new Float32Array([-0]),Zt=new Uint8Array(co.buffer);function mi(r,t,e){co[0]=r,t[e]=Zt[0],t[e+1]=Zt[1],t[e+2]=Zt[2],t[e+3]=Zt[3]}function yi(r,t){return Zt[0]=r[t],Zt[1]=r[t+1],Zt[2]=r[t+2],Zt[3]=r[t+3],co[0]}var uo=new Float64Array([-0]),it=new Uint8Array(uo.buffer);function bi(r,t,e){uo[0]=r,t[e]=it[0],t[e+1]=it[1],t[e+2]=it[2],t[e+3]=it[3],t[e+4]=it[4],t[e+5]=it[5],t[e+6]=it[6],t[e+7]=it[7]}function gi(r,t){return it[0]=r[t],it[1]=r[t+1],it[2]=r[t+2],it[3]=r[t+3],it[4]=r[t+4],it[5]=r[t+5],it[6]=r[t+6],it[7]=r[t+7],uo[0]}var Au=BigInt(Number.MAX_SAFE_INTEGER),Iu=BigInt(Number.MIN_SAFE_INTEGER),yt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ie;if(t<Au&&t>Iu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>wi&&(o=0n,++n>wi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ie;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ie}},ie=new yt(0,0);ie.toBigInt=function(){return 0n};ie.zzEncode=ie.zzDecode=function(){return this};ie.length=function(){return 1};var wi=4294967296n;function xi(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ei(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function fo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function vt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Mr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var lo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,vt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw vt(this,4);return Mr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw vt(this,4);return Mr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw vt(this,4);let t=yi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw vt(this,4);let t=gi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw vt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ei(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw vt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw vt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new yt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw vt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw vt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw vt(this,8);let t=Mr(this.buf,this.pos+=4),e=Mr(this.buf,this.pos+=4);return new yt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ao(this.buf,this.pos);return this.pos+=St(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 ho(r){return new lo(r instanceof Uint8Array?r:r.subarray())}function Or(r,t,e){let n=ho(r);return t.decode(n,void 0,e)}function po(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return nt(i);o+i>t&&(n=nt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ae=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function mo(){}var bo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Bu=po();function _u(r){return globalThis.Buffer!=null?nt(r):Bu(r)}var Xe=class{len;head;tail;states;constructor(){this.len=0,this.head=new ae(mo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ae(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new go((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(Hr,10,yt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=yt.fromBigInt(t);return this._push(Hr,e.length(),e)}uint64Number(t){return this._push(io,St(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=yt.fromBigInt(t).zzEncode();return this._push(Hr,e.length(),e)}sint64Number(t){let e=yt.fromNumber(t).zzEncode();return this._push(Hr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(yo,1,t?1:0)}fixed32(t){return this._push(We,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=yt.fromBigInt(t);return this._push(We,4,e.lo)._push(We,4,e.hi)}fixed64Number(t){let e=yt.fromNumber(t);return this._push(We,4,e.lo)._push(We,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(mi,4,t)}double(t){return this._push(bi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(yo,1,0):this.uint32(e)._push(Tu,e,t)}string(t){let e=xi(t);return e!==0?this.uint32(e)._push(fo,e,t):this._push(yo,1,0)}fork(){return this.states=new bo(this),this.head=this.tail=new ae(mo,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 ae(mo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=_u(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function yo(r,t,e){t[e]=r&255}function Lu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var go=class extends ae{next;constructor(t,e){super(Lu,t,e),this.next=void 0}};function Hr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function We(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Tu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Xe.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Pu,t,r),this},Xe.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Cu,t,r),this});function Pu(r,t,e){t.set(r,e)}function Cu(r,t,e){r.length<40?fo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(M(r),e)}function wo(){return new Xe}function qr(r,t){let e=wo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Te;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Te||(Te={}));function zr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function xo(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return zr("enum",Te.VARINT,e,n)}function Vr(r,t){return zr("message",Te.LENGTH_DELIMITED,r,t)}var Y;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Y||(Y={}));var Eo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Eo||(Eo={}));(function(r){r.codec=()=>xo(Eo)})(Y||(Y={}));var _t;(function(r){let t;r.codec=()=>(t==null&&(t=Vr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Y.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=Y.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>qr(e,r.codec()),r.decode=(e,n)=>Or(e,r.codec(),n)})(_t||(_t={}));var So;(function(r){let t;r.codec=()=>(t==null&&(t=Vr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Y.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=Y.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>qr(e,r.codec()),r.decode=(e,n)=>Or(e,r.codec(),n)})(So||(So={}));function Fr(r){if(isNaN(r)||r<=0)throw new V("random bytes length must be a Number bigger than 0");return Qt(r)}var Qe={};ht(Qe,{MAX_RSA_KEY_SIZE:()=>vo,generateRSAKeyPair:()=>_i,jwkToJWKKeyPair:()=>Li,jwkToPkcs1:()=>Ku,jwkToPkix:()=>_o,jwkToRSAPrivateKey:()=>Co,pkcs1MessageToJwk:()=>Io,pkcs1MessageToRSAPrivateKey:()=>Lo,pkcs1ToJwk:()=>Ru,pkcs1ToRSAPrivateKey:()=>Bi,pkixMessageToJwk:()=>Bo,pkixMessageToRSAPublicKey:()=>Po,pkixToJwk:()=>Uu,pkixToRSAPublicKey:()=>To});var Gr=_r;var Pe=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Qe.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return rt.createV1(114,this._multihash)}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return Ii(this.jwk,e,t,n)}},Je=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Qe.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}sign(t,e){return Ai(this.jwk,t,e)}};var vo=8192,Ao=18,Du=1062,Nu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ru(r){let t=Pt(r);return Io(t)}function Io(r){return{n:O(r[1],"base64url"),e:O(r[2],"base64url"),d:O(r[3],"base64url"),p:O(r[4],"base64url"),q:O(r[5],"base64url"),dp:O(r[6],"base64url"),dq:O(r[7],"base64url"),qi:O(r[8],"base64url"),kty:"RSA"}}function Ku(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new V("JWK was missing components");return qt([pt(Uint8Array.from([0])),pt(M(r.n,"base64url")),pt(M(r.e,"base64url")),pt(M(r.d,"base64url")),pt(M(r.p,"base64url")),pt(M(r.q,"base64url")),pt(M(r.dp,"base64url")),pt(M(r.dq,"base64url")),pt(M(r.qi,"base64url"))]).subarray()}function Uu(r){let t=Pt(r,{offset:0});return Bo(t)}function Bo(r){let t=Pt(r[1],{offset:0});return{kty:"RSA",n:O(t[0],"base64url"),e:O(t[1],"base64url")}}function _o(r){if(r.n==null||r.e==null)throw new V("JWK was missing components");return qt([Nu,vr(qt([pt(M(r.n,"base64url")),pt(M(r.e,"base64url"))]))]).subarray()}function Bi(r){let t=Pt(r);return Lo(t)}function Lo(r){let t=Io(r);return Co(t)}function To(r,t){if(r.byteLength>=Du)throw new he("Key size is too large");let e=Pt(r,{offset:0});return Po(e,r,t)}function Po(r,t,e){let n=Bo(r);if(e==null){let o=Gr(_t.encode({Type:Y.RSA,Data:t}));e=gt(Ao,o)}return new Pe(n,e)}function Co(r){if(Pi(r)>vo)throw new V("Key size is too large");let t=Li(r),e=Gr(_t.encode({Type:Y.RSA,Data:_o(t.publicKey)})),n=gt(Ao,e);return new Je(t.privateKey,new Pe(t.publicKey,n))}async function _i(r){if(r>vo)throw new V("Key size is too large");let t=await Ti(r),e=Gr(_t.encode({Type:Y.RSA,Data:_o(t.publicKey)})),n=gt(Ao,e);return new Je(t.privateKey,new Pe(t.publicKey,n))}function Li(r){if(r==null)throw new V("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ti(r,t){let e=await bt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await ku(e,t);return{privateKey:n[0],publicKey:n[1]}}async function Ai(r,t,e){let n=await bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await bt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ii(r,t,e,n){let o=await bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await bt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function ku(r,t){if(r.privateKey==null||r.publicKey==null)throw new V("Private and public key are required");let e=await Promise.all([bt.get().subtle.exportKey("jwk",r.privateKey),bt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Pi(r){if(r.kty!=="RSA")throw new V("invalid key type");if(r.n==null)throw new V("invalid key modulus");return M(r.n,"base64url").length*8}var jr=class extends xe{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,vs(t);let n=Ve(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Nt(s)}update(t){return Se(this),this.iHash.update(t),this}digestInto(t){Se(this),ot(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Do=(r,t,e)=>new jr(r,t).update(e).digest();Do.create=(r,t)=>new jr(r,t);function Ci(r){r.lowS!==void 0&&Kt("lowS",r.lowS),r.prehash!==void 0&&Kt("prehash",r.prehash)}var No=class extends Error{constructor(t=""){super(t)}},Ut={Err:No,_tlv:{encode:(r,t)=>{let{Err:e}=Ut;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Ze(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Ze(o.length/2|128):"";return Ze(r)+s+o+t},decode(r,t){let{Err:e}=Ut,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Ut;if(r<tr)throw new t("integer: negative integers are not allowed");let e=Ze(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Ut;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ae(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Ut,o=q("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:l,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=Ut,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},tr=BigInt(0),er=BigInt(1),Mu=BigInt(2),Zr=BigInt(3),Ou=BigInt(4);function Hu(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function Di(r,t,e){let{BYTES:n}=r;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=q("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{i=r.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(e&&(i=r.create(i)),!r.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function qu(r,t={}){let{Fp:e,Fn:n}=Dr("weierstrass",r,t),{h:o,n:s}=r;jt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(B,h,w){let{x:m,y:g}=h.toAffine(),E=e.toBytes(m);if(Kt("isCompressed",w),w){a();let _=!e.isOdd(g);return mt(Ni(_),E)}else return mt(Uint8Array.of(4),E,e.toBytes(g))}function l(B){ot(B);let h=e.BYTES,w=h+1,m=2*h+1,g=B.length,E=B[0],_=B.subarray(1);if(g===w&&(E===2||E===3)){let I=e.fromBytes(_);if(!e.isValid(I))throw new Error("bad point: is not on curve, wrong x");let T=b(I),R;try{R=e.sqrt(T)}catch(k){let K=k instanceof Error?": "+k.message:"";throw new Error("bad point: is not on curve, sqrt error"+K)}a();let N=e.isOdd(R);return(E&1)===1!==N&&(R=e.neg(R)),{x:I,y:R}}else if(g===m&&E===4){let I=e.fromBytes(_.subarray(h*0,h*1)),T=e.fromBytes(_.subarray(h*1,h*2));if(!p(I,T))throw new Error("bad point: is not on curve");return{x:I,y:T}}else throw new Error(`bad point: got length ${g}, expected compressed=${w} or uncompressed=${m}`)}let u=t.toBytes||c,f=t.fromBytes||l,b=Hu(e,r.a,r.b);function p(B,h){let w=e.sqr(h),m=b(B);return e.eql(w,m)}if(!p(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let v=e.mul(e.pow(r.a,Zr),Ou),x=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(v,x)))throw new Error("bad curve params: a or b");function d(B,h,w=!1){if(!e.isValid(h)||w&&e.is0(h))throw new Error(`bad point coordinate ${B}`);return h}function S(B){if(!(B instanceof y))throw new Error("ProjectivePoint expected")}let L=Be((B,h)=>{let{px:w,py:m,pz:g}=B;if(e.eql(g,e.ONE))return{x:w,y:m};let E=B.is0();h==null&&(h=E?e.ONE:e.inv(g));let _=e.mul(w,h),I=e.mul(m,h),T=e.mul(g,h);if(E)return{x:e.ZERO,y:e.ZERO};if(!e.eql(T,e.ONE))throw new Error("invZ was invalid");return{x:_,y:I}}),A=Be(B=>{if(B.is0()){if(t.allowInfinityPoint&&!e.is0(B.py))return;throw new Error("bad point: ZERO")}let{x:h,y:w}=B.toAffine();if(!e.isValid(h)||!e.isValid(w))throw new Error("bad point: x or y not field elements");if(!p(h,w))throw new Error("bad point: equation left != right");if(!B.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function D(B,h,w,m,g){return w=new y(e.mul(w.px,B),w.py,w.pz),h=_e(m,h),w=_e(g,w),h.add(w)}class y{constructor(h,w,m){this.px=d("x",h),this.py=d("y",w,!0),this.pz=d("z",m),Object.freeze(this)}static fromAffine(h){let{x:w,y:m}=h||{};if(!h||!e.isValid(w)||!e.isValid(m))throw new Error("invalid affine point");if(h instanceof y)throw new Error("projective point not allowed");return e.is0(w)&&e.is0(m)?y.ZERO:new y(w,m,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){return Tr(y,"pz",h)}static fromBytes(h){return ot(h),y.fromHex(h)}static fromHex(h){let w=y.fromAffine(f(q("pointHex",h)));return w.assertValidity(),w}static fromPrivateKey(h){let w=Di(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return y.BASE.multiply(w(h))}static msm(h,w){return Cr(y,n,h,w)}precompute(h=8,w=!0){return P.setWindowSize(this,h),w||this.multiply(Zr),this}_setWindowSize(h){this.precompute(h)}assertValidity(){A(this)}hasEvenY(){let{y:h}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(h)}equals(h){S(h);let{px:w,py:m,pz:g}=this,{px:E,py:_,pz:I}=h,T=e.eql(e.mul(w,I),e.mul(E,g)),R=e.eql(e.mul(m,I),e.mul(_,g));return T&&R}negate(){return new y(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:w}=r,m=e.mul(w,Zr),{px:g,py:E,pz:_}=this,I=e.ZERO,T=e.ZERO,R=e.ZERO,N=e.mul(g,g),Z=e.mul(E,E),k=e.mul(_,_),K=e.mul(g,E);return K=e.add(K,K),R=e.mul(g,_),R=e.add(R,R),I=e.mul(h,R),T=e.mul(m,k),T=e.add(I,T),I=e.sub(Z,T),T=e.add(Z,T),T=e.mul(I,T),I=e.mul(K,I),R=e.mul(m,R),k=e.mul(h,k),K=e.sub(N,k),K=e.mul(h,K),K=e.add(K,R),R=e.add(N,N),N=e.add(R,N),N=e.add(N,k),N=e.mul(N,K),T=e.add(T,N),k=e.mul(E,_),k=e.add(k,k),N=e.mul(k,K),I=e.sub(I,N),R=e.mul(k,Z),R=e.add(R,R),R=e.add(R,R),new y(I,T,R)}add(h){S(h);let{px:w,py:m,pz:g}=this,{px:E,py:_,pz:I}=h,T=e.ZERO,R=e.ZERO,N=e.ZERO,Z=r.a,k=e.mul(r.b,Zr),K=e.mul(w,E),W=e.mul(m,_),J=e.mul(g,I),et=e.add(w,m),H=e.add(E,_);et=e.mul(et,H),H=e.add(K,W),et=e.sub(et,H),H=e.add(w,g);let ct=e.add(E,I);return H=e.mul(H,ct),ct=e.add(K,J),H=e.sub(H,ct),ct=e.add(m,g),T=e.add(_,I),ct=e.mul(ct,T),T=e.add(W,J),ct=e.sub(ct,T),N=e.mul(Z,H),T=e.mul(k,J),N=e.add(T,N),T=e.sub(W,N),N=e.add(W,N),R=e.mul(T,N),W=e.add(K,K),W=e.add(W,K),J=e.mul(Z,J),H=e.mul(k,H),W=e.add(W,J),J=e.sub(K,J),J=e.mul(Z,J),H=e.add(H,J),K=e.mul(W,H),R=e.add(R,K),K=e.mul(ct,H),T=e.mul(et,T),T=e.sub(T,K),K=e.mul(et,W),N=e.mul(ct,N),N=e.add(N,K),new y(T,R,N)}subtract(h){return this.add(h.negate())}is0(){return this.equals(y.ZERO)}multiply(h){let{endo:w}=t;if(!n.isValidNot0(h))throw new Error("invalid scalar: out of range");let m,g,E=_=>P.wNAFCached(this,_,y.normalizeZ);if(w){let{k1neg:_,k1:I,k2neg:T,k2:R}=w.splitScalar(h),{p:N,f:Z}=E(I),{p:k,f:K}=E(R);g=Z.add(K),m=D(w.beta,N,k,_,T)}else{let{p:_,f:I}=E(h);m=_,g=I}return y.normalizeZ([m,g])[0]}multiplyUnsafe(h){let{endo:w}=t,m=this;if(!n.isValid(h))throw new Error("invalid scalar: out of range");if(h===tr||m.is0())return y.ZERO;if(h===er)return m;if(P.hasPrecomputes(this))return this.multiply(h);if(w){let{k1neg:g,k1:E,k2neg:_,k2:I}=w.splitScalar(h),{p1:T,p2:R}=oi(y,m,E,I);return D(w.beta,T,R,g,_)}else return P.wNAFCachedUnsafe(m,h)}multiplyAndAddUnsafe(h,w,m){let g=this.multiplyUnsafe(w).add(h.multiplyUnsafe(m));return g.is0()?void 0:g}toAffine(h){return L(this,h)}isTorsionFree(){let{isTorsionFree:h}=t;return o===er?!0:h?h(y,this):P.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:h}=t;return o===er?this:h?h(y,this):this.multiplyUnsafe(o)}toBytes(h=!0){return Kt("isCompressed",h),this.assertValidity(),u(y,this,h)}toRawBytes(h=!0){return this.toBytes(h)}toHex(h=!0){return At(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}y.BASE=new y(r.Gx,r.Gy,e.ONE),y.ZERO=new y(e.ZERO,e.ONE,e.ZERO),y.Fp=e,y.Fn=n;let C=n.BITS,P=Pr(y,t.endo?Math.ceil(C/2):C);return y}function Ni(r){return Uint8Array.of(r?2:3)}function zu(r,t,e={}){jt(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||Qt,o=t.hmac||((m,...g)=>Do(t.hash,m,mt(...g))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i;function l(m){let g=a>>er;return m>g}function u(m){return l(m)?i.neg(m):m}function f(m,g){if(!i.isValidNot0(g))throw new Error(`invalid signature ${m}: out of range 1..CURVE.n`)}class b{constructor(g,E,_){f("r",g),f("s",E),this.r=g,this.s=E,_!=null&&(this.recovery=_),Object.freeze(this)}static fromCompact(g){let E=i.BYTES,_=q("compactSignature",g,E*2);return new b(i.fromBytes(_.subarray(0,E)),i.fromBytes(_.subarray(E,E*2)))}static fromDER(g){let{r:E,s:_}=Ut.toSig(q("DER",g));return new b(E,_)}assertValidity(){}addRecoveryBit(g){return new b(this.r,this.s,g)}recoverPublicKey(g){let E=s.ORDER,{r:_,s:I,recovery:T}=this;if(T==null||![0,1,2,3].includes(T))throw new Error("recovery id invalid");if(a*Mu<E&&T>1)throw new Error("recovery id is ambiguous for h>1 curve");let N=T===2||T===3?_+a:_;if(!s.isValid(N))throw new Error("recovery id 2 or 3 invalid");let Z=s.toBytes(N),k=r.fromHex(mt(Ni((T&1)===0),Z)),K=i.inv(N),W=A(q("msgHash",g)),J=i.create(-W*K),et=i.create(I*K),H=r.BASE.multiplyUnsafe(J).add(k.multiplyUnsafe(et));if(H.is0())throw new Error("point at infinify");return H.assertValidity(),H}hasHighS(){return l(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,i.neg(this.s),this.recovery):this}toBytes(g){if(g==="compact")return mt(i.toBytes(this.r),i.toBytes(this.s));if(g==="der")return ve(Ut.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return At(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return At(this.toBytes("compact"))}}let p=Di(i,e.allowedPrivateKeyLengths,e.wrapPrivateKey),v={isValidPrivateKey(m){try{return p(m),!0}catch{return!1}},normPrivateKeyToScalar:p,randomPrivateKey:()=>{let m=a;return Js(n($n(m)),m)},precompute(m=8,g=r.BASE){return g.precompute(m,!1)}};function x(m,g=!0){return r.fromPrivateKey(m).toBytes(g)}function d(m){if(typeof m=="bigint")return!1;if(m instanceof r)return!0;let E=q("key",m).length,_=s.BYTES,I=_+1,T=2*_+1;if(!(e.allowedPrivateKeyLengths||i.BYTES===I))return E===I||E===T}function S(m,g,E=!0){if(d(m)===!0)throw new Error("first arg must be private key");if(d(g)===!1)throw new Error("second arg must be public key");return r.fromHex(g).multiply(p(m)).toBytes(E)}let L=t.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let g=Ae(m),E=m.length*8-c;return E>0?g>>BigInt(E):g},A=t.bits2int_modN||function(m){return i.create(L(m))},D=ne(c);function y(m){return Gt("num < 2^"+c,m,tr,D),i.toBytes(m)}function C(m,g,E=P){if(["recovered","canonical"].some(et=>et in E))throw new Error("sign() legacy options not supported");let{hash:_}=t,{lowS:I,prehash:T,extraEntropy:R}=E;I==null&&(I=!0),m=q("msgHash",m),Ci(E),T&&(m=q("prehashed msgHash",_(m)));let N=A(m),Z=p(g),k=[y(Z),y(N)];if(R!=null&&R!==!1){let et=R===!0?n(s.BYTES):R;k.push(q("extraEntropy",et))}let K=mt(...k),W=N;function J(et){let H=L(et);if(!i.isValidNot0(H))return;let ct=i.inv(H),Re=r.BASE.multiply(H).toAffine(),fe=i.create(Re.x);if(fe===tr)return;let $t=i.create(ct*i.create(W+fe*Z));if($t===tr)return;let fn=(Re.x===fe?0:2)|Number(Re.y&er),le=$t;return I&&l($t)&&(le=u($t),fn^=1),new b(fe,le,fn)}return{seed:K,k2sig:J}}let P={lowS:t.lowS,prehash:!1},B={lowS:t.lowS,prehash:!1};function h(m,g,E=P){let{seed:_,k2sig:I}=C(m,g,E);return zs(t.hash.outputLen,i.BYTES,o)(_,I)}r.BASE.precompute(8);function w(m,g,E,_=B){let I=m;g=q("msgHash",g),E=q("publicKey",E),Ci(_);let{lowS:T,prehash:R,format:N}=_;if("strict"in _)throw new Error("options.strict was renamed to lowS");if(N!==void 0&&!["compact","der","js"].includes(N))throw new Error('format must be "compact", "der" or "js"');let Z=typeof I=="string"||Ee(I),k=!Z&&!N&&typeof I=="object"&&I!==null&&typeof I.r=="bigint"&&typeof I.s=="bigint";if(!Z&&!k)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let K,W;try{if(k)if(N===void 0||N==="js")K=new b(I.r,I.s);else throw new Error("invalid format");if(Z){try{N!=="compact"&&(K=b.fromDER(I))}catch(le){if(!(le instanceof Ut.Err))throw le}!K&&N!=="der"&&(K=b.fromCompact(I))}W=r.fromHex(E)}catch{return!1}if(!K||T&&K.hasHighS())return!1;R&&(g=t.hash(g));let{r:J,s:et}=K,H=A(g),ct=i.inv(et),Re=i.create(H*ct),fe=i.create(J*ct),$t=r.BASE.multiplyUnsafe(Re).add(W.multiplyUnsafe(fe));return $t.is0()?!1:i.create($t.x)===J}return Object.freeze({getPublicKey:x,getSharedSecret:S,sign:h,verify:w,utils:v,Point:r,Signature:b})}function Vu(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Et(t.n,r.nBitLength),o={Fp:e,Fn:n,allowedPrivateKeyLengths:r.allowedPrivateKeyLengths,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,wrapPrivateKey:r.wrapPrivateKey,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:o}}function Fu(r){let{CURVE:t,curveOpts:e}=Vu(r),n={hash:r.hash,hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,ecdsaOpts:n}}function Gu(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function Ri(r){let{CURVE:t,curveOpts:e,ecdsaOpts:n}=Fu(r),o=qu(t,e),s=zu(o,n,e);return Gu(r,s)}function Ki(r,t){let e=n=>Ri({...r,hash:n});return{...e(t),create:e}}var $r={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},dp=BigInt(0),ju=BigInt(1),Ro=BigInt(2),Ui=(r,t)=>(r+t/Ro)/t;function Zu(r){let t=$r.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=z(u,e,t)*u%t,b=z(f,e,t)*u%t,p=z(b,Ro,t)*l%t,v=z(p,o,t)*p%t,x=z(v,s,t)*v%t,d=z(x,a,t)*x%t,S=z(d,c,t)*d%t,L=z(S,a,t)*x%t,A=z(L,e,t)*u%t,D=z(A,i,t)*v%t,y=z(D,n,t)*l%t,C=z(y,Ro,t);if(!Ko.eql(Ko.sqr(C),r))throw new Error("Cannot find square root");return C}var Ko=Et($r.p,void 0,void 0,{sqrt:Zu}),Ce=Ki({...$r,Fp:Ko,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=$r.n,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-ju*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=Ui(s*r,t),c=Ui(-n*r,t),l=G(r-a*e-c*o,t),u=G(-a*n-c*s,t),f=l>i,b=u>i;if(f&&(l=t-l),b&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:b,k2:u}}}},_r);function ki(r,t,e,n){let o=Xt.digest(e instanceof Uint8Array?e:e.subarray());if(Ur(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ce.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new Ye(String(s))});try{return n?.signal?.throwIfAborted(),Ce.verify(t,o.digest,r)}catch(s){throw new Ye(String(s))}}var Yr=class{type="secp256k1";raw;_key;constructor(t){this._key=Oi(t),this.raw=Mi(this._key)}toMultihash(){return wt.digest(Ct(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return ki(this._key,e,t,n)}};function Uo(r){return new Yr(r)}function Mi(r){return Ce.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Oi(r){try{return Ce.ProjectivePoint.fromHex(r),r}catch(t){throw new he(String(t))}}function ko(r,t){let{Type:e,Data:n}=_t.decode(r),o=n??new Uint8Array;switch(e){case Y.RSA:return To(o,t);case Y.Ed25519:return eo(o);case Y.secp256k1:return Uo(o);case Y.ECDSA:return On(o);default:throw new Yt}}function Hi(r){let{Type:t,Data:e}=_t.decode(r.digest),n=e??new Uint8Array;switch(t){case Y.Ed25519:return eo(n);case Y.secp256k1:return Uo(n);case Y.ECDSA:return On(n);default:throw new Yt}}function Ct(r){return _t.encode({Type:Y[r.type],Data:r.raw})}var qi=Symbol.for("nodejs.util.inspect.custom"),$u=114,rr=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()})`}[ln]=!0;toString(){return this.string==null&&(this.string=F.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return rt.createV1($u,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return dt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return dt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[qi](){return`PeerId(${this.toString()})`}},nr=class extends rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},or=class extends rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},sr=class extends rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Yu=2336,Wr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=wt.digest(M(this.url))}[qi](){return`PeerId(${this.url})`}[ln]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return rt.createV1(Yu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=O(t)),t.toString()===this.toString())}};function Mo(r){if(r.type==="Ed25519")return new or({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new sr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new nr({multihash:r.toCID().multihash,publicKey:r});throw new Yt}function zi(r){return Mo(r.publicKey)}function ir(r){if(Xu(r))return new nr({multihash:r});if(Wu(r))try{let t=Hi(r);if(t.type==="Ed25519")return new or({multihash:r,publicKey:t});if(t.type==="secp256k1")return new sr({multihash:r,publicKey:t})}catch{let e=O(r.digest);return new Wr(new URL(e))}throw new gr("Supplied PeerID Multihash is invalid")}function Wu(r){return r.code===wt.code}function Xu(r){return r.code===Xt.code}function ce(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function Xr(r){let t=Ot(F.decode(`z${r}`));return ir(t)}var ar=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return ce(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return ce(this.map.values(),t=>t.key)}values(){return ce(this.map.values(),t=>t.value)}get size(){return this.map.size}};var cr=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return ce(this.set.entries(),t=>{let e=Xr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Xr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return ce(this.set.values(),t=>Xr(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function kt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Jr=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},De=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Jr(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Jr(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Oo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Qr(r={}){return Ju(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Ju(r,t){t=t??{};let e=t.onEnd,n=new De,o,s,i,a=kt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,S)=>{s=L=>{s=null,n.push(L);try{d(r(n))}catch(A){S(A)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=kt()})}},l=d=>s!=null?s(d):(n.push(d),o),u=d=>(n=new De,s!=null?s({error:d}):(n.push({error:d}),o)),f=d=>{if(i)return o;if(t?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:d})},b=d=>i?o:(i=!0,d!=null?u(d):l({done:!0})),p=()=>(n=new De,b(),{done:!0}),v=d=>(b(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:v,push:f,end:b,get readableLength(){return n.size},onEmpty:async d=>{let S=d?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let L,A;S!=null&&(L=new Promise((D,y)=>{A=()=>{y(new Oo)},S.addEventListener("abort",A)}));try{await Promise.race([a.promise,L])}finally{A!=null&&S!=null&&S?.removeEventListener("abort",A)}}},e==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(d){return x.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return x.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(d){return x.end(d),e!=null&&(e(d),e=void 0),o},get readableLength(){return x.readableLength},onEmpty:d=>x.onEmpty(d)},o}var tn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Vi(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new tn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new tn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Ho=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=kt(),this.haveNext=kt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=kt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=kt(),await Vi(this.readNext.promise,e?.signal,e)}};function Fi(){return new Ho}function Qu(r){return r[Symbol.asyncIterator]!=null}async function tf(r,t,e){try{await Promise.all(r.map(async n=>{for await(let o of n)await t.push(o,{signal:e}),e.throwIfAborted()})),await t.end(void 0,{signal:e})}catch(n){await t.end(n,{signal:e}).catch(()=>{})}}async function*ef(r){let t=new AbortController,e=Fi();tf(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*rf(r){for(let t of r)yield*t}function nf(...r){let t=[];for(let e of r)Qu(e)||t.push(e);return t.length===r.length?rf(t):ef(r)}var Gi=nf;function ur(r,...t){if(r==null)throw new Error("Empty pipeline");if(qo(r)){let n=r;r=()=>n.source}else if(Zi(r)||ji(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&qo(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)qo(e[n])&&(e[n]=sf(e[n]));return of(...e)}var of=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},ji=r=>r?.[Symbol.asyncIterator]!=null,Zi=r=>r?.[Symbol.iterator]!=null,qo=r=>r==null?!1:r.sink!=null&&r.source!=null,sf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Qr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(ji(s))o=async function*(){yield*s,n.end()};else if(Zi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Gi(n,o())}return r.source};var Vo=ya(Yi(),1);var lr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Fo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Wi=r=>globalThis.DOMException===void 0?new Fo(r):new DOMException(r),Xi=r=>{let t=r.reason===void 0?Wi("This operation was aborted."):r.reason;return t instanceof Error?t:Wi(t)};function Go(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,l=new Promise((u,f)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:p}=t;p.aborted&&f(Xi(p)),a=()=>{f(Xi(p))},p.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,f);return}let b=new lr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(p){f(p)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?f(o):(b.message=o??`Promise timed out after ${e} milliseconds`,f(b))},e),(async()=>{try{u(await r)}catch(p){f(p)}})()}).finally(()=>{l.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return l.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},l}function jo(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var hr=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let o=jo(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var dr=class extends Vo.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#w=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:hr,...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})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#x(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},e)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#x&&this.#E){let e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}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.#u=t,this.#l()}async#I(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#w++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=Go(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#I(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof lr&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function Ji(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function Qi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function ta(r,t){let e=Ji(r).return?.();Qi(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var rn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ne=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},nn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},pr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function on(r){return r[Symbol.asyncIterator]!=null}function ea(r,t){if(r.byteLength>t)throw new Ne("Message length too long")}var an=r=>{let t=St(r),e=nt(t);return hi(r,e),an.bytes=t,e};an.bytes=0;function cn(r,t){t=t??{};let e=t.lengthEncoder??an,n=t?.maxDataLength??4194304;function*o(s){ea(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return on(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}cn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??an,n=t?.maxDataLength??4194304;return ea(r,n),new X(e(r.byteLength),r)};var ue;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ue||(ue={}));var Zo=r=>{let t=di(r);return Zo.bytes=St(t),t};Zo.bytes=0;function mr(r,t){let e=new X,n=ue.LENGTH,o=-1,s=t?.lengthDecoder??Zo,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===ue.LENGTH)try{if(o=s(e),o<0)throw new rn("Invalid message length");if(o>a)throw new Ne("Message length too long");let l=s.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=ue.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw new nn("Message length length too long");break}throw l}if(n===ue.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=ue.LENGTH}}}return on(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw new pr("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw new pr("Unexpected end of input")}()}mr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return mr(n,{...t??{},onLength:s=>{e=s}})};var un=class extends de{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=e.id,this.protocol=e.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let e=this.id.toString();throw new Error("No writable connection to "+e)}this.outboundStream.push(t instanceof Uint8Array?new X(t):t)}attachInboundStream(t,e){let n=()=>{ta(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=ur(this._rawInboundStream,o=>mr(o,e)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let e=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=Qr({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),ur(this.outboundStream,n=>cn(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),e==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function ra(){return BigInt(`0x${O(Fr(8),"base16")}`)}var na=(r,t)=>{let e=M(t.toString(16).padStart(16,"0"),"base16"),n=Ct(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},oa=r=>Xt.encode(r);var sa=function(r){return Array.isArray(r)?r:[r]},lf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=ir(Ot(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return Mo(ko(e)).equals(t)}return!1},ia=async r=>{if(r.from==null)throw new $("RPC message was missing from");if(!await lf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=ir(Ot(r.from)),e=r.key??t.publicKey;if(e==null)throw new $("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:df(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?ko(e):e}},yr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:hf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Ct(r.key):void 0}:{data:r.data,topic:r.topic},hf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),M(t,"base16")},df=r=>BigInt(`0x${O(r,"base16")}`);var aa=M("libp2p-pubsub:");async function ca(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:zi(r)},o=Wt([aa,e(yr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function ua(r,t){if(r.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(r.signature==null)throw new Error("Message must contain a signature to be verified");if(r.from==null)throw new Error("Message must contain a from property to be verified");let e=Wt([aa,t({...yr(r),signature:void 0,key:void 0}).subarray()]);return pf(r).verify(e,r.signature)}function pf(r){if(r.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(r.from==null)throw new Error("Could not get the public key from the originator id");if(r.key!=null)return r.key;if(r.from.publicKey!=null)return r.from.publicKey;throw new Error("Could not get the public key from the originator id")}var $o=class extends de{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,e){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:a=10,maxInboundStreams:c=1,maxOutboundStreams:l=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=sa(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new ar,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new dr({concurrency:a}),this.maxInboundStreams=c,this.maxOutboundStreams=l,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let e={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.multicodecs.map(async e=>{await t.unhandle(e)})),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:e,connection:n}=t,o=n.remotePeer;if(e.protocol==null){e.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,e.protocol),i=s.attachInboundStream(e);this.processMessages(o,i,s).catch(a=>{this.log(a)})}_onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await e.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new un(this.components,{id:t,protocol:e});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return e}}async processMessages(t,e,n){try{await ur(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),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(t,n,{subscriptions:(i.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,e,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.id,subscriptions:o.map(({topic:i,subscribe:a})=>({topic:`${i??""}`,subscribe:!!a}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),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 a=await ia(i);await this.processMessage(t,a)}catch(a){this.log.error(a)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new cr,this.topics.set(n,o)),e.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,e){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,e)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new $('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new $("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new $("Need key when signature policy is StrictSign but it was missing");return na(t.key,t.sequenceNumber);case"StrictNoSign":return oa(t.data);default:throw new $("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,e){let{messages:n,subscriptions:o,subscribe:s}=e;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(yr)})}sendRpc(t,e){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(e))}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new $('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new $("StrictNoSigning: signature should not be present");if(e.key!=null)throw new $("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new $("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new $('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new $("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new $("StrictSigning: Signing required and no sequenceNumber was present");if(!await ua(e,this.encodeMessage.bind(this)))throw new $("StrictSigning: Invalid message signature");break;default:throw new $("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===Ke.Reject||s===Ke.Ignore)throw new $("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return ca(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new $("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new wr("not started yet");if(t==null)throw new V("Topic is required");let e=this.topics.get(t.toString());return e==null?[]:Array.from(e.values())}async publish(t,e){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:e??new Uint8Array(0),sequenceNumber:ra()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let e=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,e),e){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{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())}};return ba(mf);})();
2
+ "use strict";var Libp2PPubsub=(()=>{var Ta=Object.create;var Dr=Object.defineProperty;var Da=Object.getOwnPropertyDescriptor;var Pa=Object.getOwnPropertyNames;var Ca=Object.getPrototypeOf,Ra=Object.prototype.hasOwnProperty;var Ka=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ht=(r,t)=>{for(var e in t)Dr(r,e,{get:t[e],enumerable:!0})},ps=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pa(t))!Ra.call(r,o)&&o!==e&&Dr(r,o,{get:()=>t[o],enumerable:!(n=Da(t,o))||n.enumerable});return r};var Na=(r,t,e)=>(e=r!=null?Ta(Ca(r)):{},ps(t||!r||!r.__esModule?Dr(e,"default",{value:r,enumerable:!0}):e,r)),Ua=r=>ps(Dr({},"__esModule",{value:!0}),r);var pa=Ka((ym,ss)=>{"use strict";var Pf=Object.prototype.hasOwnProperty,lt="~";function vr(){}Object.create&&(vr.prototype=Object.create(null),new vr().__proto__||(lt=!1));function Cf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function da(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new Cf(e,n||r,o),i=lt?lt+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function dn(r,t){--r._eventsCount===0?r._events=new vr:delete r._events[t]}function ut(){this._events=new vr,this._eventsCount=0}ut.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Pf.call(e,n)&&t.push(lt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};ut.prototype.listeners=function(t){var e=lt?lt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};ut.prototype.listenerCount=function(t){var e=lt?lt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};ut.prototype.emit=function(t,e,n,o,s,i){var a=lt?lt+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,d,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,s),!0;case 6:return c.fn.call(c.context,e,n,o,s,i),!0}for(l=1,d=new Array(f-1);l<f;l++)d[l-1]=arguments[l];c.fn.apply(c.context,d)}else{var u=c.length,h;for(l=0;l<u;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,e);break;case 3:c[l].fn.call(c[l].context,e,n);break;case 4:c[l].fn.call(c[l].context,e,n,o);break;default:if(!d)for(h=1,d=new Array(f-1);h<f;h++)d[h-1]=arguments[h];c[l].fn.apply(c[l].context,d)}}return!0};ut.prototype.on=function(t,e,n){return da(this,t,e,n,!1)};ut.prototype.once=function(t,e,n){return da(this,t,e,n,!0)};ut.prototype.removeListener=function(t,e,n,o){var s=lt?lt+t:t;if(!this._events[s])return this;if(!e)return dn(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&dn(this,s);else{for(var a=0,c=[],f=i.length;a<f;a++)(i[a].fn!==e||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:dn(this,s)}return this};ut.prototype.removeAllListeners=function(t){var e;return t?(e=lt?lt+t:t,this._events[e]&&dn(this,e)):(this._events=new vr,this._eventsCount=0),this};ut.prototype.off=ut.prototype.removeListener;ut.prototype.addListener=ut.prototype.on;ut.prefixed=lt;ut.EventEmitter=ut;typeof ss<"u"&&(ss.exports=ut)});var Mf={};ht(Mf,{PubSubBaseProtocol:()=>ls});var En=Symbol.for("@libp2p/peer-id");var Ye;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ye||(Ye={}));var Vf=Symbol.for("@libp2p/pubsub");var j=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 Pr=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 Cr=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 Ie=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Bn={};ht(Bn,{base58btc:()=>Y,base58flickr:()=>Fa});var Zf=new Uint8Array(0);function ms(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Pt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ys(r){return new TextEncoder().encode(r)}function bs(r){return new TextDecoder().decode(r)}function ka(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var w=0,p=0,S=0,B=g.length;S!==B&&g[S]===0;)S++,w++;for(var v=(B-S)*d+1>>>0,T=new Uint8Array(v);S!==B;){for(var R=g[S],_=0,U=v-1;(R!==0||_<p)&&U!==-1;U--,_++)R+=256*T[U]>>>0,T[U]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");p=_,S++}for(var k=v-p;k!==v&&T[k]===0;)k++;for(var D=c.repeat(w);k<v;++k)D+=r.charAt(T[k]);return D}function u(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var w=0;if(g[w]!==" "){for(var p=0,S=0;g[w]===c;)p++,w++;for(var B=(g.length-w)*f+1>>>0,v=new Uint8Array(B);g[w];){var T=e[g.charCodeAt(w)];if(T===255)return;for(var R=0,_=B-1;(T!==0||R<S)&&_!==-1;_--,R++)T+=a*v[_]>>>0,v[_]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");S=R,w++}if(g[w]!==" "){for(var U=B-S;U!==B&&v[U]===0;)U++;for(var k=new Uint8Array(p+(B-U)),D=p;U!==B;)k[D++]=v[U++];return k}}}function h(g){var w=u(g);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:u,decode:h}}var Oa=ka,Ma=Oa,ws=Ma;var Sn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},vn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return xs(this,t)}},An=class{decoders;constructor(t){this.decoders=t}or(t){return xs(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function xs(r,t){return new An({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var In=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sn(t,e,n),this.decoder=new vn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Be({name:r,prefix:t,encode:e,decode:n}){return new In(r,t,e,n)}function Xt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ws(e,r);return Be({prefix:t,name:r,encode:n,decode:s=>Pt(o(s))})}function qa(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let d=t[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ha(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Va(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function X({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Va(n);return Be({prefix:t,name:r,encode(s){return Ha(s,n,e)},decode(s){return qa(s,o,e,r)}})}var Y=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Fa=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _n={};ht(_n,{base32:()=>_e,base32hex:()=>ja,base32hexpad:()=>Xa,base32hexpadupper:()=>$a,base32hexupper:()=>Ya,base32pad:()=>Ga,base32padupper:()=>Za,base32upper:()=>za,base32z:()=>Wa});var _e=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),za=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ga=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Za=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ja=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ya=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Xa=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),$a=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Wa=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ln={};ht(Ln,{base36:()=>Xe,base36upper:()=>Ja});var Xe=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ja=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Qa=vs,Es=128,tc=127,ec=~tc,rc=Math.pow(2,31);function vs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=rc;)t[e++]=r&255|Es,r/=128;for(;r&ec;)t[e++]=r&255|Es,r>>>=7;return t[e]=r|0,vs.bytes=e-n+1,t}var nc=Tn,oc=128,Ss=127;function Tn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Tn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Ss)<<o:(i&Ss)*Math.pow(2,o),o+=7}while(i>=oc);return Tn.bytes=s-n,e}var sc=Math.pow(2,7),ic=Math.pow(2,14),ac=Math.pow(2,21),cc=Math.pow(2,28),uc=Math.pow(2,35),fc=Math.pow(2,42),lc=Math.pow(2,49),hc=Math.pow(2,56),dc=Math.pow(2,63),pc=function(r){return r<sc?1:r<ic?2:r<ac?3:r<cc?4:r<uc?5:r<fc?6:r<lc?7:r<hc?8:r<dc?9:10},mc={encode:Qa,decode:nc,encodingLength:pc},yc=mc,$e=yc;function We(r,t=0){return[$e.decode(r,t),$e.decode.bytes]}function Le(r,t,e=0){return $e.encode(r,t,e),t}function Te(r){return $e.encodingLength(r)}function vt(r,t){let e=t.byteLength,n=Te(r),o=n+Te(e),s=new Uint8Array(o+e);return Le(r,s,0),Le(e,s,n),s.set(t,o),new De(r,e,t,s)}function $t(r){let t=Pt(r),[e,n]=We(t),[o,s]=We(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new De(e,o,i,t)}function As(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ms(r.bytes,e.bytes)}}var De=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Is(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return gc(e,Dn(r),t??Y.encoder);default:return wc(e,Dn(r),t??_e.encoder)}}var Bs=new WeakMap;function Dn(r){let t=Bs.get(r);if(t==null){let e=new Map;return Bs.set(r,e),e}return t}var st=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Je)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==xc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=vt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&As(t.multihash,n.multihash)}toString(t){return Is(this,t)}toJSON(){return{"/":Is(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??_s(n,o,s.bytes))}else if(e[Ec]===!0){let{version:n,multihash:o,code:s}=e,i=$t(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Je)throw new Error(`Version 0 CID must use dag-pb (code: ${Je}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=_s(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Je,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Pt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new De(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,u]=We(t.subarray(e));return e+=u,l},o=n(),s=Je;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,d=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,e){let[n,o]=bc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Dn(s).set(n,t),s}};function bc(r,t){switch(r[0]){case"Q":{let e=t??Y;return[Y.prefix,e.decode(`${Y.prefix}${r}`)]}case Y.prefix:{let e=t??Y;return[Y.prefix,e.decode(r)]}case _e.prefix:{let e=t??_e;return[_e.prefix,e.decode(r)]}case Xe.prefix:{let e=t??Xe;return[Xe.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function gc(r,t,e){let{prefix:n}=e;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function wc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Je=112,xc=18;function _s(r,t,e){let n=Te(r),o=n+Te(t),s=new Uint8Array(o+e.byteLength);return Le(r,s,0),Le(t,s,n),s.set(e,o),s}var Ec=Symbol.for("@ipld/js-cid/CID");var Pn={};ht(Pn,{identity:()=>At});var Ls=0,Sc="identity",Ts=Pt;function vc(r){return vt(Ls,Ts(r))}var At={code:Ls,name:Sc,encode:Ts,digest:vc};function dt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ct(r=0){return new Uint8Array(r)}function it(r=0){return new Uint8Array(r)}function ue(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=it(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Ps=Symbol.for("@achingbrain/uint8arraylist");function Ds(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Kr(r){return!!r?.[Ps]}var et=class r{bufs;length;[Ps]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Kr(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Kr(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Ds(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ds(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Kr(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return ue(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ue(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,d=e>a&&e<=c;if(f&&d){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Kr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,d;for(let l=e;l<=c;l+=d){d=0;for(let u=f;u>=0;u--){let h=this.get(l+u);if(n[u]!==h){d=Math.max(1,u-a[h]);break}}if(d===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=it(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Ct(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Ct(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Ct(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=it(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Ct(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Ct(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Ct(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Ct(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Ct(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!dt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Cn={};ht(Cn,{base10:()=>Ac});var Ac=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var Rn={};ht(Rn,{base16:()=>Ic,base16upper:()=>Bc});var Ic=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bc=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Kn={};ht(Kn,{base2:()=>_c});var _c=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Nn={};ht(Nn,{base256emoji:()=>Cc});var Cs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Lc=Cs.reduce((r,t,e)=>(r[e]=t,r),[]),Tc=Cs.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Dc(r){return r.reduce((t,e)=>(t+=Lc[e],t),"")}function Pc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Tc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Cc=Be({prefix:"\u{1F680}",name:"base256emoji",encode:Dc,decode:Pc});var Un={};ht(Un,{base64:()=>Rc,base64pad:()=>Kc,base64url:()=>Nc,base64urlpad:()=>Uc});var Rc=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Kc=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Nc=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Uc=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var kn={};ht(kn,{base8:()=>kc});var kc=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var On={};ht(On,{identity:()=>Oc});var Oc=Be({prefix:"\0",name:"identity",encode:r=>bs(r),decode:r=>ys(r)});var Tl=new TextEncoder,Dl=new TextDecoder;var Hn={};ht(Hn,{sha256:()=>fe,sha512:()=>Hc});function qn({name:r,code:t,encode:e}){return new Mn(r,t,e)}var Mn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?vt(this.code,e):e.then(n=>vt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ks(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var fe=qn({name:"sha2-256",code:18,encode:Ks("SHA-256")}),Hc=qn({name:"sha2-512",code:19,encode:Ks("SHA-512")});var Vn={...On,...Kn,...kn,...Cn,...Rn,..._n,...Ln,...Bn,...Un,...Nn},Vl={...Hn,...Pn};function Us(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ns=Us("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Fn=Us("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=it(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Vc={utf8:Ns,"utf-8":Ns,hex:Vn.base16,latin1:Fn,ascii:Fn,binary:Fn,...Vn},Nr=Vc;function F(r,t="utf8"){let e=Nr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function z(r,t="utf8"){let e=Nr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Fc=parseInt("11111",2),zn=parseInt("10000000",2),zc=parseInt("01111111",2),ks={0:Qe,1:Qe,2:Gc,3:Yc,4:Xc,5:jc,6:Zc,16:Qe,22:Qe,48:Qe};function Rt(r,t={offset:0}){let e=r[t.offset]&Fc;if(t.offset++,ks[e]!=null)return ks[e](r,t);throw new Error("No decoder for tag "+e)}function tr(r,t){let e=0;if((r[t.offset]&zn)===zn){let n=r[t.offset]&zc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Qe(r,t){tr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Rt(r,t);if(n===null)break;e.push(n)}return e}function Gc(r,t){let e=tr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Zc(r,t){let e=tr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let d=0;for(let l=0;l<c.length;l++)d+=c[l]<<l*7;a+=`.${d}`,c=[]}}return a}function jc(r,t){return t.offset++,null}function Yc(r,t){let e=tr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Xc(r,t){let e=tr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function $c(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new et;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Gn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=$c(r.byteLength);return new et(Uint8Array.from([t.byteLength|zn]),t)}function pt(r){let t=new et,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new et(Uint8Array.from([2]),Gn(t),t)}function Ur(r){let t=Uint8Array.from([0]),e=new et(t,r);return new et(Uint8Array.from([3]),Gn(e),e)}function Jt(r,t=48){let e=new et;for(let n of r)e.append(n);return new et(Uint8Array.from([t]),Gn(e),e)}async function Os(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Wc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Jc=Uint8Array.from([6,5,43,129,4,0,34]),Qc=Uint8Array.from([6,5,43,129,4,0,35]),tu={ext:!0,kty:"EC",crv:"P-256"},eu={ext:!0,kty:"EC",crv:"P-384"},ru={ext:!0,kty:"EC",crv:"P-521"},Zn=32,jn=48,Yn=66;function Xn(r){let t=Rt(r);return Ms(t)}function Ms(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Zn*2+1)return n=z(t.subarray(e,e+Zn),"base64url"),o=z(t.subarray(e+Zn),"base64url"),new Pe({...tu,key_ops:["verify"],x:n,y:o});if(t.byteLength===jn*2+1)return n=z(t.subarray(e,e+jn),"base64url"),o=z(t.subarray(e+jn),"base64url"),new Pe({...eu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Yn*2+1)return n=z(t.subarray(e,e+Yn),"base64url"),o=z(t.subarray(e+Yn),"base64url"),new Pe({...ru,key_ops:["verify"],x:n,y:o});throw new j(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function qs(r){return Jt([pt(Uint8Array.from([1])),Jt([nu(r.crv)],160),Jt([Ur(new et(Uint8Array.from([4]),F(r.x??"","base64url"),F(r.y??"","base64url")))],161)]).subarray()}function nu(r){if(r==="P-256")return Wc;if(r==="P-384")return Jc;if(r==="P-521")return Qc;throw new j(`Invalid curve ${r}`)}var Pe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=qs(this.jwk)),this._raw}toMultihash(){return At.digest(Kt(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}async verify(t,e,n){return Os(this.jwk,e,t,n)}};var le=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function he(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function er(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function $(r,...t){if(!he(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function kr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");er(r.outputLen),er(r.blockLen)}function Re(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Vs(r,t){$(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Ut(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Or(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function It(r,t){return r<<32-t|r>>>t}var Fs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ou=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Et(r){if($(r),Fs)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=ou[r[e]];return t}var Nt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Hs(r){if(r>=Nt._0&&r<=Nt._9)return r-Nt._0;if(r>=Nt.A&&r<=Nt.F)return r-(Nt.A-10);if(r>=Nt.a&&r<=Nt.f)return r-(Nt.a-10)}function de(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Fs)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Hs(r.charCodeAt(s)),a=Hs(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function $n(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function rr(r){return typeof r=="string"&&(r=$n(r)),$(r),r}function mt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];$(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Ce=class{};function Wn(r){let t=n=>r().update(rr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function pe(r=32){if(le&&typeof le.getRandomValues=="function")return le.getRandomValues(new Uint8Array(r));if(le&&typeof le.randomBytes=="function")return Uint8Array.from(le.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function su(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,f=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+f,a,n)}function zs(r,t,e){return r&t^~r&e}function Gs(r,t,e){return r&t^r&e^t&e}var nr=class extends Ce{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Or(this.buffer)}update(t){Re(this),t=rr(t),$(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Or(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),Vs(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Ut(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;su(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Or(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,d=this.get();if(f>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,d[l],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},kt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Mr=BigInt(4294967295),Zs=BigInt(32);function iu(r,t=!1){return t?{h:Number(r&Mr),l:Number(r>>Zs&Mr)}:{h:Number(r>>Zs&Mr)|0,l:Number(r&Mr)|0}}function js(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=iu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Jn=(r,t,e)=>r>>>e,Qn=(r,t,e)=>r<<32-e|t>>>e,me=(r,t,e)=>r>>>e|t<<32-e,ye=(r,t,e)=>r<<32-e|t>>>e,or=(r,t,e)=>r<<64-e|t>>>e-32,sr=(r,t,e)=>r>>>e-32|t<<64-e;function Lt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ys=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Xs=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,$s=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Ws=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Js=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Qs=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var cu=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]),Qt=new Uint32Array(64),qr=class extends nr{constructor(t=32){super(64,t,8,!1),this.A=kt[0]|0,this.B=kt[1]|0,this.C=kt[2]|0,this.D=kt[3]|0,this.E=kt[4]|0,this.F=kt[5]|0,this.G=kt[6]|0,this.H=kt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)Qt[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let u=Qt[l-15],h=Qt[l-2],g=It(u,7)^It(u,18)^u>>>3,w=It(h,17)^It(h,19)^h>>>10;Qt[l]=w+Qt[l-7]+g+Qt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:d}=this;for(let l=0;l<64;l++){let u=It(a,6)^It(a,11)^It(a,25),h=d+u+zs(a,c,f)+cu[l]+Qt[l]|0,w=(It(n,2)^It(n,13)^It(n,22))+Gs(n,o,s)|0;d=f,f=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,f,d)}roundClean(){Ut(Qt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}};var ti=js(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),uu=ti[0],fu=ti[1],te=new Uint32Array(80),ee=new Uint32Array(80),to=class extends nr{constructor(t=64){super(128,t,16,!1),this.Ah=ot[0]|0,this.Al=ot[1]|0,this.Bh=ot[2]|0,this.Bl=ot[3]|0,this.Ch=ot[4]|0,this.Cl=ot[5]|0,this.Dh=ot[6]|0,this.Dl=ot[7]|0,this.Eh=ot[8]|0,this.El=ot[9]|0,this.Fh=ot[10]|0,this.Fl=ot[11]|0,this.Gh=ot[12]|0,this.Gl=ot[13]|0,this.Hh=ot[14]|0,this.Hl=ot[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:d,Fh:l,Fl:u,Gh:h,Gl:g,Hh:w,Hl:p}=this;return[t,e,n,o,s,i,a,c,f,d,l,u,h,g,w,p]}set(t,e,n,o,s,i,a,c,f,d,l,u,h,g,w,p){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=d|0,this.Fh=l|0,this.Fl=u|0,this.Gh=h|0,this.Gl=g|0,this.Hh=w|0,this.Hl=p|0}process(t,e){for(let v=0;v<16;v++,e+=4)te[v]=t.getUint32(e),ee[v]=t.getUint32(e+=4);for(let v=16;v<80;v++){let T=te[v-15]|0,R=ee[v-15]|0,_=me(T,R,1)^me(T,R,8)^Jn(T,R,7),U=ye(T,R,1)^ye(T,R,8)^Qn(T,R,7),k=te[v-2]|0,D=ee[v-2]|0,y=me(k,D,19)^or(k,D,61)^Jn(k,D,6),m=ye(k,D,19)^sr(k,D,61)^Qn(k,D,6),E=$s(U,m,ee[v-7],ee[v-16]),A=Ws(E,_,y,te[v-7],te[v-16]);te[v]=A|0,ee[v]=E|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:d,Eh:l,El:u,Fh:h,Fl:g,Gh:w,Gl:p,Hh:S,Hl:B}=this;for(let v=0;v<80;v++){let T=me(l,u,14)^me(l,u,18)^or(l,u,41),R=ye(l,u,14)^ye(l,u,18)^sr(l,u,41),_=l&h^~l&w,U=u&g^~u&p,k=Js(B,R,U,fu[v],ee[v]),D=Qs(k,S,T,_,uu[v],te[v]),y=k|0,m=me(n,o,28)^or(n,o,34)^or(n,o,39),E=ye(n,o,28)^sr(n,o,34)^sr(n,o,39),A=n&s^n&a^s&a,P=o&i^o&c^i&c;S=w|0,B=p|0,w=h|0,p=g|0,h=l|0,g=u|0,{h:l,l:u}=Lt(f|0,d|0,D|0,y|0),f=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let C=Ys(y,E,P);n=Xs(C,D,m,A),o=C|0}({h:n,l:o}=Lt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Lt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Lt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:d}=Lt(this.Dh|0,this.Dl|0,f|0,d|0),{h:l,l:u}=Lt(this.Eh|0,this.El|0,l|0,u|0),{h,l:g}=Lt(this.Fh|0,this.Fl|0,h|0,g|0),{h:w,l:p}=Lt(this.Gh|0,this.Gl|0,w|0,p|0),{h:S,l:B}=Lt(this.Hh|0,this.Hl|0,S|0,B|0),this.set(n,o,s,i,a,c,f,d,l,u,h,g,w,p,S,B)}roundClean(){Ut(te,ee)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Hr=Wn(()=>new qr);var ei=Wn(()=>new to);var no=BigInt(0),ro=BigInt(1);function Ot(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function ir(r){let t=r.toString(16);return t.length&1?"0"+t:t}function ri(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?no:BigInt("0x"+r)}function Ke(r){return ri(Et(r))}function Mt(r){return $(r),ri(Et(Uint8Array.from(r).reverse()))}function Vr(r,t){return de(r.toString(16).padStart(t*2,"0"))}function qt(r,t){return Vr(r,t).reverse()}function H(r,t,e){let n;if(typeof t=="string")try{n=de(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(he(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function ni(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}var eo=r=>typeof r=="bigint"&&no<=r;function oi(r,t,e){return eo(r)&&eo(t)&&eo(e)&&t<=r&&r<e}function re(r,t,e,n){if(!oi(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Fr(r){let t;for(t=0;r>no;r>>=ro,t+=1);return t}var ne=r=>(ro<<BigInt(r))-ro;function si(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},f=(...h)=>e(i,s,...h),d=(h=n(0))=>{i=f(o(0),h),s=f(),h.length!==0&&(i=f(o(1),h),s=f())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,g=[];for(;h<t;){s=f();let w=s.slice();g.push(w),h+=s.length}return mt(...g)};return(h,g)=>{c(),d(h);let w;for(;!(w=g(l()));)d();return c(),w}}function oe(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function Ne(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var ft=BigInt(0),nt=BigInt(1),be=BigInt(2),ci=BigInt(3),ui=BigInt(4),fi=BigInt(5),lu=BigInt(7),li=BigInt(8),hu=BigInt(9),hi=BigInt(16);function W(r,t){let e=r%t;return e>=ft?e:t+e}function Z(r,t,e){let n=r;for(;t-- >ft;)n*=n,n%=e;return n}function ii(r,t){if(r===ft)throw new Error("invert: expected non-zero number");if(t<=ft)throw new Error("invert: expected positive modulus, got "+t);let e=W(r,t),n=t,o=ft,s=nt,i=nt,a=ft;for(;e!==ft;){let f=n/e,d=n%e,l=o-i*f,u=s-a*f;n=e,e=d,o=i,s=a,i=l,a=u}if(n!==nt)throw new Error("invert: does not exist");return W(o,t)}function oo(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function di(r,t){let e=(r.ORDER+nt)/ui,n=r.pow(t,e);return oo(r,n,t),n}function du(r,t){let e=(r.ORDER-fi)/li,n=r.mul(t,be),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,be),o),a=r.mul(s,r.sub(i,r.ONE));return oo(r,a,t),a}function pu(r){let t=gt(r),e=pi(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+lu)/hi;return(a,c)=>{let f=a.pow(c,i),d=a.mul(f,n),l=a.mul(f,o),u=a.mul(f,s),h=a.eql(a.sqr(d),c),g=a.eql(a.sqr(l),c);f=a.cmov(f,d,h),d=a.cmov(u,l,g);let w=a.eql(a.sqr(d),c),p=a.cmov(f,d,w);return oo(a,p,c),p}}function pi(r){if(r<ci)throw new Error("sqrt is not defined for small field");let t=r-nt,e=0;for(;t%be===ft;)t/=be,e++;let n=be,o=gt(r);for(;ai(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return di;let s=o.pow(n,t),i=(t+nt)/be;return function(c,f){if(c.is0(f))return f;if(ai(c,f)!==1)throw new Error("Cannot find square root");let d=e,l=c.mul(c.ONE,s),u=c.pow(f,t),h=c.pow(f,i);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let g=1,w=c.sqr(u);for(;!c.eql(w,c.ONE);)if(g++,w=c.sqr(w),g===d)throw new Error("Cannot find square root");let p=nt<<BigInt(d-g-1),S=c.pow(l,p);d=g,l=c.sqr(S),u=c.mul(u,l),h=c.mul(h,S)}return h}}function mu(r){return r%ui===ci?di:r%li===fi?du:r%hi===hu?pu(r):pi(r)}var Ht=(r,t)=>(W(r,t)&nt)===nt,yu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function so(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=yu.reduce((n,o)=>(n[o]="function",n),t);return oe(r,e),r}function bu(r,t,e){if(e<ft)throw new Error("invalid exponent, negatives unsupported");if(e===ft)return r.ONE;if(e===nt)return t;let n=r.ONE,o=t;for(;e>ft;)e&nt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=nt;return n}function ar(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function ai(r,t){let e=(r.ORDER-nt)/be,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function mi(r,t){t!==void 0&&er(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function gt(r,t,e=!1,n={}){if(r<=ft)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(e=u.isLE),typeof u.modOnDecode=="boolean"&&(i=u.modOnDecode),a=u.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:f}=mi(r,o);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,l=Object.freeze({ORDER:r,isLE:e,BITS:c,BYTES:f,MASK:ne(c),ZERO:ft,ONE:nt,allowedLengths:a,create:u=>W(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return ft<=u&&u<r},is0:u=>u===ft,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&nt)===nt,neg:u=>W(-u,r),eql:(u,h)=>u===h,sqr:u=>W(u*u,r),add:(u,h)=>W(u+h,r),sub:(u,h)=>W(u-h,r),mul:(u,h)=>W(u*h,r),pow:(u,h)=>bu(l,u,h),div:(u,h)=>W(u*ii(h,r),r),sqrN:u=>u*u,addN:(u,h)=>u+h,subN:(u,h)=>u-h,mulN:(u,h)=>u*h,inv:u=>ii(u,r),sqrt:s||(u=>(d||(d=mu(r)),d(l,u))),toBytes:u=>e?qt(u,f):Vr(u,f),fromBytes:(u,h=!0)=>{if(a){if(!a.includes(u.length)||u.length>f)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);let w=new Uint8Array(f);w.set(u,e?0:w.length-u.length),u=w}if(u.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+u.length);let g=e?Mt(u):Ke(u);if(i&&(g=W(g,r)),!h&&!l.isValid(g))throw new Error("invalid field element: outside of range 0..ORDER");return g},invertBatch:u=>ar(l,u),cmov:(u,h,g)=>g?h:u});return Object.freeze(l)}function yi(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function io(r){let t=yi(r);return t+Math.ceil(t/2)}function ao(r,t,e=!1){let n=r.length,o=yi(t),s=io(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Mt(r):Ke(r),a=W(i,t-nt)+nt;return e?qt(a,o):Vr(a,o)}var Ue=BigInt(0),ge=BigInt(1);function cr(r,t){let e=t.negate();return r?e:t}function Vt(r,t){let e=ar(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function xi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function co(r,t){xi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ne(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function bi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ge);let f=t*n,d=f+Math.abs(a)-1,l=a===0,u=a<0,h=t%2!==0;return{nextN:c,offset:d,isZero:l,isNeg:u,isNegF:h,offsetF:f}}function gu(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function wu(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var uo=new WeakMap,Ei=new WeakMap;function fo(r){return Ei.get(r)||1}function gi(r){if(r!==Ue)throw new Error("invalid wNAF")}var ke=class{constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>Ue;)e&ge&&(n=n.add(o)),o=o.double(),e>>=ge;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=co(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=co(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:d,isNeg:l,isNegF:u,offsetF:h}=bi(n,a,i);n=c,d?s=s.add(cr(u,e[h])):o=o.add(cr(l,e[f]))}return gi(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=co(t,this.bits);for(let i=0;i<s.windows&&n!==Ue;i++){let{nextN:a,offset:c,isZero:f,isNeg:d}=bi(n,i,s);if(n=a,!f){let l=e[c];o=o.add(d?l.negate():l)}}return gi(n),o}getPrecomputes(t,e,n){let o=uo.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),uo.set(e,o))),o}cached(t,e,n){let o=fo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=fo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){xi(e,this.bits),Ei.set(t,e),uo.delete(t)}hasCache(t){return fo(t)!==1}};function Si(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Ue||n>Ue;)e&ge&&(s=s.add(o)),n&ge&&(i=i.add(o)),o=o.double(),e>>=ge,n>>=ge;return{p1:s,p2:i}}function Oe(r,t,e,n){gu(e,r),wu(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=Fr(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=ne(c),d=new Array(Number(f)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,u=i;for(let h=l;h>=0;h-=c){d.fill(i);for(let w=0;w<s;w++){let p=n[w],S=Number(p>>BigInt(h)&f);d[S]=d[S].add(e[w])}let g=i;for(let w=d.length-1,p=i;w>0;w--)p=p.add(d[w]),g=g.add(p);if(u=u.add(g),h!==0)for(let w=0;w<c;w++)u=u.double()}return u}function wi(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return so(t),t}else return gt(r)}function zr(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Ue))throw new Error(`CURVE.${a} must be positive bigint`)}let n=wi(t.p,e.Fp),o=wi(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Tt=BigInt(0),rt=BigInt(1),lo=BigInt(2),xu=BigInt(8);function Eu(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Su(r,t={}){let{Fp:e,Fn:n}=zr("edwards",r,t),{h:o,n:s}=r;oe(t,{},{uvRatio:"function"});let i=lo<<BigInt(n.BYTES*8)-rt,a=w=>e.create(w),c=t.uvRatio||((w,p)=>{try{return{isValid:!0,value:e.sqrt(e.div(w,p))}}catch{return{isValid:!1,value:Tt}}});if(!Eu(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function f(w,p,S=!1){let B=S?rt:Tt;return re("coordinate "+w,p,B,i),p}function d(w){if(!(w instanceof h))throw new Error("ExtendedPoint expected")}let l=Ne((w,p)=>{let{X:S,Y:B,Z:v}=w,T=w.is0();p==null&&(p=T?xu:e.inv(v));let R=a(S*p),_=a(B*p),U=e.mul(v,p);if(T)return{x:Tt,y:rt};if(U!==rt)throw new Error("invZ was invalid");return{x:R,y:_}}),u=Ne(w=>{let{a:p,d:S}=r;if(w.is0())throw new Error("bad point: ZERO");let{X:B,Y:v,Z:T,T:R}=w,_=a(B*B),U=a(v*v),k=a(T*T),D=a(k*k),y=a(_*p),m=a(k*a(y+U)),E=a(D+a(S*a(_*U)));if(m!==E)throw new Error("bad point: equation left != right (1)");let A=a(B*v),P=a(T*R);if(A!==P)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(p,S,B,v){this.X=f("x",p),this.Y=f("y",S),this.Z=f("z",B,!0),this.T=f("t",v),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(p){return Vt(h,p)}static msm(p,S){return Oe(h,n,p,S)}_setWindowSize(p){this.precompute(p)}static fromAffine(p){if(p instanceof h)throw new Error("extended point not allowed");let{x:S,y:B}=p||{};return f("x",S),f("y",B),new h(S,B,rt,a(S*B))}precompute(p=8,S=!0){return g.createCache(this,p),S||this.multiply(lo),this}assertValidity(){u(this)}equals(p){d(p);let{X:S,Y:B,Z:v}=this,{X:T,Y:R,Z:_}=p,U=a(S*_),k=a(T*v),D=a(B*_),y=a(R*v);return U===k&&D===y}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:p}=r,{X:S,Y:B,Z:v}=this,T=a(S*S),R=a(B*B),_=a(lo*a(v*v)),U=a(p*T),k=S+B,D=a(a(k*k)-T-R),y=U+R,m=y-_,E=U-R,A=a(D*m),P=a(y*E),C=a(D*E),x=a(m*y);return new h(A,P,x,C)}add(p){d(p);let{a:S,d:B}=r,{X:v,Y:T,Z:R,T:_}=this,{X:U,Y:k,Z:D,T:y}=p,m=a(v*U),E=a(T*k),A=a(_*B*y),P=a(R*D),C=a((v+T)*(U+k)-m-E),x=P-A,b=P+A,I=a(E-S*m),L=a(C*x),K=a(b*I),N=a(C*I),O=a(x*b);return new h(L,K,O,N)}subtract(p){return this.add(p.negate())}multiply(p){let S=p;re("scalar",S,rt,s);let{p:B,f:v}=g.cached(this,S,T=>Vt(h,T));return Vt(h,[B,v])[0]}multiplyUnsafe(p,S=h.ZERO){let B=p;return re("scalar",B,Tt,s),B===Tt?h.ZERO:this.is0()||B===rt?this:g.unsafe(this,B,v=>Vt(h,v),S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return g.unsafe(this,s).is0()}toAffine(p){return l(this,p)}clearCofactor(){return o===rt?this:this.multiplyUnsafe(o)}static fromBytes(p,S=!1){return $(p),h.fromHex(p,S)}static fromHex(p,S=!1){let{d:B,a:v}=r,T=e.BYTES;p=H("pointHex",p,T),Ot("zip215",S);let R=p.slice(),_=p[T-1];R[T-1]=_&-129;let U=Mt(R),k=S?i:e.ORDER;re("pointHex.y",U,Tt,k);let D=a(U*U),y=a(D-rt),m=a(B*D-v),{isValid:E,value:A}=c(y,m);if(!E)throw new Error("Point.fromHex: invalid y coordinate");let P=(A&rt)===rt,C=(_&128)!==0;if(!S&&A===Tt&&C)throw new Error("Point.fromHex: x=0 and x_0=1");return C!==P&&(A=a(-A)),h.fromAffine({x:A,y:U})}toBytes(){let{x:p,y:S}=this.toAffine(),B=qt(S,e.BYTES);return B[B.length-1]|=p&rt?128:0,B}toRawBytes(){return this.toBytes()}toHex(){return Et(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}h.BASE=new h(r.Gx,r.Gy,rt,a(r.Gx*r.Gy)),h.ZERO=new h(Tt,rt,rt,Tt),h.Fp=e,h.Fn=n;let g=new ke(h,n.BYTES*8);return h}var Gr=class{constructor(t){this.ep=t}static fromBytes(t){throw new Error("fromBytes must be implemented by subclass")}static fromHex(t){throw new Error("fromHex must be implemented by subclass")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toRawBytes(){return this.toBytes()}toHex(){return Et(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,e){return this.init(this.ep.precompute(t,e))}};function vu(r,t,e){if(typeof t!="function")throw new Error('"hash" function param is required');oe(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,c=e.randomBytes||pe,f=e.adjustScalarBytes||(m=>m),d=e.domain||((m,E,A)=>{if(Ot("phflag",A),E.length||A)throw new Error("Contexts/pre-hash are not supported");return m});function l(m){return i.create(m)}function u(m){return l(Mt(m))}function h(m){let E=s.BYTES;m=H("private key",m,E);let A=H("hashed private key",t(m),2*E),P=f(A.slice(0,E)),C=A.slice(E,2*E),x=u(P);return{head:P,prefix:C,scalar:x}}function g(m){let{head:E,prefix:A,scalar:P}=h(m),C=o.multiply(P),x=C.toBytes();return{head:E,prefix:A,scalar:P,point:C,pointBytes:x}}function w(m){return g(m).pointBytes}function p(m=Uint8Array.of(),...E){let A=mt(...E);return u(t(d(A,H("context",m),!!n)))}function S(m,E,A={}){m=H("message",m),n&&(m=n(m));let{prefix:P,scalar:C,pointBytes:x}=g(E),b=p(A.context,P,m),I=o.multiply(b).toBytes(),L=p(A.context,I,x,m),K=l(b+L*C);re("signature.s",K,Tt,a);let N=s.BYTES,O=mt(I,qt(K,N));return H("result",O,N*2)}let B={zip215:!0};function v(m,E,A,P=B){let{context:C,zip215:x}=P,b=s.BYTES;m=H("signature",m,2*b),E=H("message",E),A=H("publicKey",A,b),x!==void 0&&Ot("zip215",x),n&&(E=n(E));let I=Mt(m.slice(b,2*b)),L,K,N;try{L=r.fromHex(A,x),K=r.fromHex(m.slice(0,b),x),N=o.multiplyUnsafe(I)}catch{return!1}if(!x&&L.isSmallOrder())return!1;let O=p(C,K.toBytes(),L.toBytes(),E);return K.add(L.multiplyUnsafe(O)).subtract(N).clearCofactor().is0()}o.precompute(8);let T=s.BYTES,R={secret:T,public:T,signature:2*T,seed:T};function _(m=c(R.seed)){return m}let U={getExtendedPublicKey:g,randomSecretKey:_,isValidSecretKey:D,isValidPublicKey:y,randomPrivateKey:_,toMontgomery(m){let{y:E}=r.fromBytes(m),A=T===32;if(!A&&T!==57)throw new Error("only defined for 25519 and 448");let P=A?s.div(rt+E,rt-E):s.div(E-rt,E+rt);return s.toBytes(P)},toMontgomeryPriv(m){$(m,T);let E=t(m.subarray(0,T));return f(E).subarray(0,T)},precompute(m=8,E=r.BASE){return E.precompute(m,!1)}};function k(m){let E=U.randomSecretKey(m);return{secretKey:E,publicKey:w(E)}}function D(m){try{return!!i.fromBytes(m,!1)}catch{return!1}}function y(m,E){try{return!!r.fromBytes(m,E)}catch{return!1}}return Object.freeze({keygen:k,getPublicKey:w,sign:S,verify:v,utils:U,Point:r,info:{type:"edwards",lengths:R}})}function Au(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=gt(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,hash:r.hash,eddsaOpts:s}}function Iu(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function vi(r){let{CURVE:t,curveOpts:e,hash:n,eddsaOpts:o}=Au(r),s=Su(t,e),i=vu(s,n,o);return Iu(r,i)}var Bu=BigInt(0),Ft=BigInt(1),Ai=BigInt(2),$h=BigInt(3),_u=BigInt(5),Lu=BigInt(8),ur={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Lu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Tu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=ur.p,a=r*r%s*r%s,c=Z(a,Ai,s)*a%s,f=Z(c,Ft,s)*r%s,d=Z(f,_u,s)*f%s,l=Z(d,t,s)*d%s,u=Z(l,e,s)*l%s,h=Z(u,n,s)*u%s,g=Z(h,o,s)*h%s,w=Z(g,o,s)*h%s,p=Z(w,t,s)*d%s;return{pow_p_5_8:Z(p,Ai,s)*r%s,b2:a}}function Du(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ho=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function yo(r,t){let e=ur.p,n=W(t*t*t,e),o=W(n*n*t,e),s=Tu(r*o).pow_p_5_8,i=W(r*n*s,e),a=W(t*i*i,e),c=i,f=W(i*ho,e),d=a===r,l=a===W(-r,e),u=a===W(-r*ho,e);return d&&(i=c),(l||u)&&(i=f),Ht(i,e)&&(i=W(-i,e)),{isValid:d||l,value:i}}var we=gt(ur.p,{isLE:!0}),Pu=gt(ur.n,{isLE:!0}),Cu={...ur,Fp:we,hash:ei,adjustScalarBytes:Du,uvRatio:yo},wt=vi(Cu);var po=ho,Ru=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Ku=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Nu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Uu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ii=r=>yo(Ft,r),ku=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),mo=r=>wt.CURVE.Fp.create(Mt(r)&ku);function Bi(r){let{d:t}=wt.CURVE,e=wt.CURVE.Fp.ORDER,n=wt.CURVE.Fp.create,o=n(po*r*r),s=n((o+Ft)*Nu),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:f}=yo(s,a),d=n(f*r);Ht(d,e)||(d=n(-d)),c||(f=d),c||(i=o);let l=n(i*(o-Ft)*Uu-a),u=f*f,h=n((f+f)*a),g=n(l*Ru),w=n(Ft-u),p=n(Ft+u);return new wt.Point(n(h*p),n(w*g),n(g*p),n(h*w))}function Ou(r){$(r,64);let t=mo(r.subarray(0,32)),e=Bi(t),n=mo(r.subarray(32,64)),o=Bi(n);return new zt(e.add(o))}var zt=class r extends Gr{constructor(t){super(t)}static fromAffine(t){return new r(wt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static hashToCurve(t){return Ou(H("ristrettoHash",t,64))}static fromBytes(t){$(t,32);let{a:e,d:n}=wt.CURVE,o=we.ORDER,s=we.create,i=mo(t);if(!ni(qt(i,32),t)||Ht(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Ft+e*a),f=s(Ft-e*a),d=s(c*c),l=s(f*f),u=s(e*n*d-l),{isValid:h,value:g}=Ii(s(u*l)),w=s(g*f),p=s(g*w*u),S=s((i+i)*w);Ht(S,o)&&(S=s(-S));let B=s(c*p),v=s(S*B);if(!h||Ht(v,o)||B===Bu)throw new Error("invalid ristretto255 encoding 2");return new r(new wt.Point(S,B,Ft,v))}static fromHex(t){return r.fromBytes(H("ristrettoHex",t,32))}static msm(t,e){return Oe(r,wt.Point.Fn,t,e)}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=we.ORDER,i=we.create,a=i(i(n+e)*i(n-e)),c=i(t*e),f=i(c*c),{value:d}=Ii(i(a*f)),l=i(d*a),u=i(d*c),h=i(l*u*o),g;if(Ht(o*h,s)){let p=i(e*po),S=i(t*po);t=p,e=S,g=i(l*Ku)}else g=u;Ht(t*h,s)&&(e=i(-e));let w=i((n-e)*g);return Ht(w,s)&&(w=i(-w)),qt(w,32)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=we.create,a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};zt.BASE=new zt(wt.Point.BASE);zt.ZERO=new zt(wt.Point.ZERO);zt.Fp=we;zt.Fn=Pu;var fr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var _i={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Zr("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 St=_i;var jr=32;var bo,Mu=(async()=>{try{return await St.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function qu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await St.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await St.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Hu(r,t,e){return wt.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Li(r,t,e){return bo==null&&(bo=await Mu),bo?qu(r,t,e):Hu(r,t,e)}function Yr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Xr=class{type="Ed25519";raw;constructor(t){this.raw=go(t,jr)}toMultihash(){return At.digest(Kt(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Li(this.raw,e,t);return Yr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function wo(r){return r=go(r,jr),new Xr(r)}function go(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new j(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Fu=Math.pow(2,7),zu=Math.pow(2,14),Gu=Math.pow(2,21),xo=Math.pow(2,28),Eo=Math.pow(2,35),So=Math.pow(2,42),vo=Math.pow(2,49),M=128,at=127;function Bt(r){if(r<Fu)return 1;if(r<zu)return 2;if(r<Gu)return 3;if(r<xo)return 4;if(r<Eo)return 5;if(r<So)return 6;if(r<vo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ao(r,t,e=0){switch(Bt(r)){case 8:t[e++]=r&255|M,r/=128;case 7:t[e++]=r&255|M,r/=128;case 6:t[e++]=r&255|M,r/=128;case 5:t[e++]=r&255|M,r/=128;case 4:t[e++]=r&255|M,r>>>=7;case 3:t[e++]=r&255|M,r>>>=7;case 2:t[e++]=r&255|M,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Zu(r,t,e=0){switch(Bt(r)){case 8:t.set(e++,r&255|M),r/=128;case 7:t.set(e++,r&255|M),r/=128;case 6:t.set(e++,r&255|M),r/=128;case 5:t.set(e++,r&255|M),r/=128;case 4:t.set(e++,r&255|M),r>>>=7;case 3:t.set(e++,r&255|M),r>>>=7;case 2:t.set(e++,r&255|M),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Io(r,t){let e=r[t],n=0;if(n+=e&at,e<M||(e=r[t+1],n+=(e&at)<<7,e<M)||(e=r[t+2],n+=(e&at)<<14,e<M)||(e=r[t+3],n+=(e&at)<<21,e<M)||(e=r[t+4],n+=(e&at)*xo,e<M)||(e=r[t+5],n+=(e&at)*Eo,e<M)||(e=r[t+6],n+=(e&at)*So,e<M)||(e=r[t+7],n+=(e&at)*vo,e<M))return n;throw new RangeError("Could not decode varint")}function ju(r,t){let e=r.get(t),n=0;if(n+=e&at,e<M||(e=r.get(t+1),n+=(e&at)<<7,e<M)||(e=r.get(t+2),n+=(e&at)<<14,e<M)||(e=r.get(t+3),n+=(e&at)<<21,e<M)||(e=r.get(t+4),n+=(e&at)*xo,e<M)||(e=r.get(t+5),n+=(e&at)*Eo,e<M)||(e=r.get(t+6),n+=(e&at)*So,e<M)||(e=r.get(t+7),n+=(e&at)*vo,e<M))return n;throw new RangeError("Could not decode varint")}function Di(r,t,e=0){return t==null&&(t=it(Bt(r))),t instanceof Uint8Array?Ao(r,t,e):Zu(r,t,e)}function Pi(r,t=0){return r instanceof Uint8Array?Io(r,t):ju(r,t)}var Bo=new Float32Array([-0]),se=new Uint8Array(Bo.buffer);function Ri(r,t,e){Bo[0]=r,t[e]=se[0],t[e+1]=se[1],t[e+2]=se[2],t[e+3]=se[3]}function Ki(r,t){return se[0]=r[t],se[1]=r[t+1],se[2]=r[t+2],se[3]=r[t+3],Bo[0]}var _o=new Float64Array([-0]),ct=new Uint8Array(_o.buffer);function Ni(r,t,e){_o[0]=r,t[e]=ct[0],t[e+1]=ct[1],t[e+2]=ct[2],t[e+3]=ct[3],t[e+4]=ct[4],t[e+5]=ct[5],t[e+6]=ct[6],t[e+7]=ct[7]}function Ui(r,t){return ct[0]=r[t],ct[1]=r[t+1],ct[2]=r[t+2],ct[3]=r[t+3],ct[4]=r[t+4],ct[5]=r[t+5],ct[6]=r[t+6],ct[7]=r[t+7],_o[0]}var Yu=BigInt(Number.MAX_SAFE_INTEGER),Xu=BigInt(Number.MIN_SAFE_INTEGER),xt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return xe;if(t<Yu&&t>Xu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>ki&&(o=0n,++n>ki&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return xe;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):xe}},xe=new xt(0,0);xe.toBigInt=function(){return 0n};xe.zzEncode=xe.zzDecode=function(){return this};xe.length=function(){return 1};var ki=4294967296n;function Oi(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Mi(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Lo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function _t(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function $r(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var To=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,_t(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 _t(this,4);return $r(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw _t(this,4);return $r(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw _t(this,4);let t=Ki(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw _t(this,4);let t=Ui(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw _t(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Mi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw _t(this,t);this.pos+=t}else do if(this.pos>=this.len)throw _t(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 xt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw _t(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw _t(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw _t(this,8);let t=$r(this.buf,this.pos+=4),e=$r(this.buf,this.pos+=4);return new xt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Io(this.buf,this.pos);return this.pos+=Bt(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 Do(r){return new To(r instanceof Uint8Array?r:r.subarray())}function Wr(r,t,e){let n=Do(r);return t.decode(n,void 0,e)}function Po(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return it(i);o+i>t&&(n=it(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ee=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Co(){}var Ko=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},$u=Po();function Wu(r){return globalThis.Buffer!=null?it(r):$u(r)}var hr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ee(Co,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ee(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new No((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(Jr,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=xt.fromBigInt(t);return this._push(Jr,e.length(),e)}uint64Number(t){return this._push(Ao,Bt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=xt.fromBigInt(t).zzEncode();return this._push(Jr,e.length(),e)}sint64Number(t){let e=xt.fromNumber(t).zzEncode();return this._push(Jr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ro,1,t?1:0)}fixed32(t){return this._push(lr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=xt.fromBigInt(t);return this._push(lr,4,e.lo)._push(lr,4,e.hi)}fixed64Number(t){let e=xt.fromNumber(t);return this._push(lr,4,e.lo)._push(lr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ri,4,t)}double(t){return this._push(Ni,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ro,1,0):this.uint32(e)._push(Qu,e,t)}string(t){let e=Oi(t);return e!==0?this.uint32(e)._push(Lo,e,t):this._push(Ro,1,0)}fork(){return this.states=new Ko(this),this.head=this.tail=new Ee(Co,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 Ee(Co,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Wu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ro(r,t,e){t[e]=r&255}function Ju(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var No=class extends Ee{next;constructor(t,e){super(Ju,t,e),this.next=void 0}};function Jr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function lr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Qu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(hr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(tf,t,r),this},hr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ef,t,r),this});function tf(r,t,e){t.set(r,e)}function ef(r,t,e){r.length<40?Lo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(F(r),e)}function Uo(){return new hr}function Qr(r,t){let e=Uo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Me;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Me||(Me={}));function tn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ko(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return tn("enum",Me.VARINT,e,n)}function en(r,t){return tn("message",Me.LENGTH_DELIMITED,r,t)}var Q;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Q||(Q={}));var Oo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Oo||(Oo={}));(function(r){r.codec=()=>ko(Oo)})(Q||(Q={}));var Dt;(function(r){let t;r.codec=()=>(t==null&&(t=en((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Q.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=Q.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Qr(e,r.codec()),r.decode=(e,n)=>Wr(e,r.codec(),n)})(Dt||(Dt={}));var Mo;(function(r){let t;r.codec=()=>(t==null&&(t=en((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Q.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=Q.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Qr(e,r.codec()),r.decode=(e,n)=>Wr(e,r.codec(),n)})(Mo||(Mo={}));function rn(r){if(isNaN(r)||r<=0)throw new j("random bytes length must be a Number bigger than 0");return pe(r)}var pr={};ht(pr,{MAX_RSA_KEY_SIZE:()=>qo,generateRSAKeyPair:()=>Gi,jwkToJWKKeyPair:()=>Zi,jwkToPkcs1:()=>sf,jwkToPkix:()=>zo,jwkToRSAPrivateKey:()=>Yo,pkcs1MessageToJwk:()=>Vo,pkcs1MessageToRSAPrivateKey:()=>Go,pkcs1ToJwk:()=>of,pkcs1ToRSAPrivateKey:()=>zi,pkixMessageToJwk:()=>Fo,pkixMessageToRSAPublicKey:()=>jo,pkixToJwk:()=>af,pkixToRSAPublicKey:()=>Zo});var nn=Hr;var qe=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return st.createV1(114,this._multihash)}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return Fi(this.jwk,e,t,n)}},dr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}sign(t,e){return Vi(this.jwk,t,e)}};var qo=8192,Ho=18,rf=1062,nf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function of(r){let t=Rt(r);return Vo(t)}function Vo(r){return{n:z(r[1],"base64url"),e:z(r[2],"base64url"),d:z(r[3],"base64url"),p:z(r[4],"base64url"),q:z(r[5],"base64url"),dp:z(r[6],"base64url"),dq:z(r[7],"base64url"),qi:z(r[8],"base64url"),kty:"RSA"}}function sf(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new j("JWK was missing components");return Jt([pt(Uint8Array.from([0])),pt(F(r.n,"base64url")),pt(F(r.e,"base64url")),pt(F(r.d,"base64url")),pt(F(r.p,"base64url")),pt(F(r.q,"base64url")),pt(F(r.dp,"base64url")),pt(F(r.dq,"base64url")),pt(F(r.qi,"base64url"))]).subarray()}function af(r){let t=Rt(r,{offset:0});return Fo(t)}function Fo(r){let t=Rt(r[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function zo(r){if(r.n==null||r.e==null)throw new j("JWK was missing components");return Jt([nf,Ur(Jt([pt(F(r.n,"base64url")),pt(F(r.e,"base64url"))]))]).subarray()}function zi(r){let t=Rt(r);return Go(t)}function Go(r){let t=Vo(r);return Yo(t)}function Zo(r,t){if(r.byteLength>=rf)throw new Ae("Key size is too large");let e=Rt(r,{offset:0});return jo(e,r,t)}function jo(r,t,e){let n=Fo(r);if(e==null){let o=nn(Dt.encode({Type:Q.RSA,Data:t}));e=vt(Ho,o)}return new qe(n,e)}function Yo(r){if(Yi(r)>qo)throw new j("Key size is too large");let t=Zi(r),e=nn(Dt.encode({Type:Q.RSA,Data:zo(t.publicKey)})),n=vt(Ho,e);return new dr(t.privateKey,new qe(t.publicKey,n))}async function Gi(r){if(r>qo)throw new j("Key size is too large");let t=await ji(r),e=nn(Dt.encode({Type:Q.RSA,Data:zo(t.publicKey)})),n=vt(Ho,e);return new dr(t.privateKey,new qe(t.publicKey,n))}function Zi(r){if(r==null)throw new j("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function ji(r,t){let e=await St.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await cf(e,t);return{privateKey:n[0],publicKey:n[1]}}async function Vi(r,t,e){let n=await St.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await St.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Fi(r,t,e,n){let o=await St.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await St.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function cf(r,t){if(r.privateKey==null||r.publicKey==null)throw new j("Private and public key are required");let e=await Promise.all([St.get().subtle.exportKey("jwk",r.privateKey),St.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Yi(r){if(r.kty!=="RSA")throw new j("invalid key type");if(r.n==null)throw new j("invalid key modulus");return F(r.n,"base64url").length*8}var on=class extends Ce{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,kr(t);let n=rr(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Ut(s)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(this),$(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Xo=(r,t,e)=>new on(r,t).update(e).digest();Xo.create=(r,t)=>new on(r,t);var Xi=(r,t)=>(r+(r>=0?t:-t)/Wi)/t;function uf(r,t,e){let[[n,o],[s,i]]=t,a=Xi(i*r,e),c=Xi(-o*r,e),f=r-a*n-c*s,d=-a*o-c*i,l=f<Zt,u=d<Zt;l&&(f=-f),u&&(d=-d);let h=ne(Math.ceil(Fr(e)/2))+Ve;if(f<Zt||f>=h||d<Zt||d>=h)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:l,k1:f,k2neg:u,k2:d}}function $i(r){r.lowS!==void 0&&Ot("lowS",r.lowS),r.prehash!==void 0&&Ot("prehash",r.prehash)}var $o=class extends Error{constructor(t=""){super(t)}},Gt={Err:$o,_tlv:{encode:(r,t)=>{let{Err:e}=Gt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=ir(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ir(o.length/2|128):"";return ir(r)+s+o+t},decode(r,t){let{Err:e}=Gt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let d of f)i=i<<8|d;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Gt;if(r<Zt)throw new t("integer: negative integers are not allowed");let e=ir(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Gt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ke(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Gt,o=H("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=Gt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Zt=BigInt(0),Ve=BigInt(1),Wi=BigInt(2),sn=BigInt(3),ff=BigInt(4);function lf(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function He(r,t){let{BYTES:e}=r,n;if(typeof t=="bigint")n=t;else{let o=H("private key",t);try{n=r.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${e}, got ${typeof t}`)}}if(!r.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function hf(r,t={}){let{Fp:e,Fn:n}=zr("weierstrass",r,t),{h:o,n:s}=r;oe(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||!Array.isArray(i.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(D,y,m){let{x:E,y:A}=y.toAffine(),P=e.toBytes(E);if(Ot("isCompressed",m),m){a();let C=!e.isOdd(A);return mt(Ji(C),P)}else return mt(Uint8Array.of(4),P,e.toBytes(A))}function f(D){$(D);let y=e.BYTES,m=y+1,E=2*y+1,A=D.length,P=D[0],C=D.subarray(1);if(A===m&&(P===2||P===3)){let x=e.fromBytes(C);if(!e.isValid(x))throw new Error("bad point: is not on curve, wrong x");let b=u(x),I;try{I=e.sqrt(b)}catch(N){let O=N instanceof Error?": "+N.message:"";throw new Error("bad point: is not on curve, sqrt error"+O)}a();let L=e.isOdd(I);return(P&1)===1!==L&&(I=e.neg(I)),{x,y:I}}else if(A===E&&P===4){let x=e.fromBytes(C.subarray(y*0,y*1)),b=e.fromBytes(C.subarray(y*1,y*2));if(!h(x,b))throw new Error("bad point: is not on curve");return{x,y:b}}else throw new Error(`bad point: got length ${A}, expected compressed=${m} or uncompressed=${E}`)}let d=t.toBytes||c,l=t.fromBytes||f,u=lf(e,r.a,r.b);function h(D,y){let m=e.sqr(y),E=u(D);return e.eql(m,E)}if(!h(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let g=e.mul(e.pow(r.a,sn),ff),w=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(g,w)))throw new Error("bad curve params: a or b");function p(D,y,m=!1){if(!e.isValid(y)||m&&e.is0(y))throw new Error(`bad point coordinate ${D}`);return y}function S(D){if(!(D instanceof _))throw new Error("ProjectivePoint expected")}function B(D){if(!i||!i.basises)throw new Error("no endo");return uf(D,i.basises,n.ORDER)}let v=Ne((D,y)=>{let{X:m,Y:E,Z:A}=D;if(e.eql(A,e.ONE))return{x:m,y:E};let P=D.is0();y==null&&(y=P?e.ONE:e.inv(A));let C=e.mul(m,y),x=e.mul(E,y),b=e.mul(A,y);if(P)return{x:e.ZERO,y:e.ZERO};if(!e.eql(b,e.ONE))throw new Error("invZ was invalid");return{x:C,y:x}}),T=Ne(D=>{if(D.is0()){if(t.allowInfinityPoint&&!e.is0(D.Y))return;throw new Error("bad point: ZERO")}let{x:y,y:m}=D.toAffine();if(!e.isValid(y)||!e.isValid(m))throw new Error("bad point: x or y not field elements");if(!h(y,m))throw new Error("bad point: equation left != right");if(!D.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(D,y,m,E,A){return m=new _(e.mul(m.X,D),m.Y,m.Z),y=cr(E,y),m=cr(A,m),y.add(m)}class _{constructor(y,m,E){this.X=p("x",y),this.Y=p("y",m,!0),this.Z=p("z",E),Object.freeze(this)}static fromAffine(y){let{x:m,y:E}=y||{};if(!y||!e.isValid(m)||!e.isValid(E))throw new Error("invalid affine point");if(y instanceof _)throw new Error("projective point not allowed");return e.is0(m)&&e.is0(E)?_.ZERO:new _(m,E,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}static normalizeZ(y){return Vt(_,y)}static fromBytes(y){return $(y),_.fromHex(y)}static fromHex(y){let m=_.fromAffine(l(H("pointHex",y)));return m.assertValidity(),m}static fromPrivateKey(y){return _.BASE.multiply(He(n,y))}static msm(y,m){return Oe(_,n,y,m)}_setWindowSize(y){this.precompute(y)}precompute(y=8,m=!0){return k.createCache(this,y),m||this.multiply(sn),this}assertValidity(){T(this)}hasEvenY(){let{y}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(y)}equals(y){S(y);let{X:m,Y:E,Z:A}=this,{X:P,Y:C,Z:x}=y,b=e.eql(e.mul(m,x),e.mul(P,A)),I=e.eql(e.mul(E,x),e.mul(C,A));return b&&I}negate(){return new _(this.X,e.neg(this.Y),this.Z)}double(){let{a:y,b:m}=r,E=e.mul(m,sn),{X:A,Y:P,Z:C}=this,x=e.ZERO,b=e.ZERO,I=e.ZERO,L=e.mul(A,A),K=e.mul(P,P),N=e.mul(C,C),O=e.mul(A,P);return O=e.add(O,O),I=e.mul(A,C),I=e.add(I,I),x=e.mul(y,I),b=e.mul(E,N),b=e.add(x,b),x=e.sub(K,b),b=e.add(K,b),b=e.mul(x,b),x=e.mul(O,x),I=e.mul(E,I),N=e.mul(y,N),O=e.sub(L,N),O=e.mul(y,O),O=e.add(O,I),I=e.add(L,L),L=e.add(I,L),L=e.add(L,N),L=e.mul(L,O),b=e.add(b,L),N=e.mul(P,C),N=e.add(N,N),L=e.mul(N,O),x=e.sub(x,L),I=e.mul(N,K),I=e.add(I,I),I=e.add(I,I),new _(x,b,I)}add(y){S(y);let{X:m,Y:E,Z:A}=this,{X:P,Y:C,Z:x}=y,b=e.ZERO,I=e.ZERO,L=e.ZERO,K=r.a,N=e.mul(r.b,sn),O=e.mul(m,P),G=e.mul(E,C),V=e.mul(A,x),yt=e.add(m,E),q=e.add(P,C);yt=e.mul(yt,q),q=e.add(O,G),yt=e.sub(yt,q),q=e.add(m,A);let tt=e.add(P,x);return q=e.mul(q,tt),tt=e.add(O,V),q=e.sub(q,tt),tt=e.add(E,A),b=e.add(C,x),tt=e.mul(tt,b),b=e.add(G,V),tt=e.sub(tt,b),L=e.mul(K,q),b=e.mul(N,V),L=e.add(b,L),b=e.sub(G,L),L=e.add(G,L),I=e.mul(b,L),G=e.add(O,O),G=e.add(G,O),V=e.mul(K,V),q=e.mul(N,q),G=e.add(G,V),V=e.sub(O,V),V=e.mul(K,V),q=e.add(q,V),O=e.mul(G,q),I=e.add(I,O),O=e.mul(tt,q),b=e.mul(yt,b),b=e.sub(b,O),O=e.mul(yt,G),L=e.mul(tt,L),L=e.add(L,O),new _(b,I,L)}subtract(y){return this.add(y.negate())}is0(){return this.equals(_.ZERO)}multiply(y){let{endo:m}=t;if(!n.isValidNot0(y))throw new Error("invalid scalar: out of range");let E,A,P=C=>k.cached(this,C,x=>Vt(_,x));if(m){let{k1neg:C,k1:x,k2neg:b,k2:I}=B(y),{p:L,f:K}=P(x),{p:N,f:O}=P(I);A=K.add(O),E=R(m.beta,L,N,C,b)}else{let{p:C,f:x}=P(y);E=C,A=x}return Vt(_,[E,A])[0]}multiplyUnsafe(y){let{endo:m}=t,E=this;if(!n.isValid(y))throw new Error("invalid scalar: out of range");if(y===Zt||E.is0())return _.ZERO;if(y===Ve)return E;if(k.hasCache(this))return this.multiply(y);if(m){let{k1neg:A,k1:P,k2neg:C,k2:x}=B(y),{p1:b,p2:I}=Si(_,E,P,x);return R(m.beta,b,I,A,C)}else return k.unsafe(E,y)}multiplyAndAddUnsafe(y,m,E){let A=this.multiplyUnsafe(m).add(y.multiplyUnsafe(E));return A.is0()?void 0:A}toAffine(y){return v(this,y)}isTorsionFree(){let{isTorsionFree:y}=t;return o===Ve?!0:y?y(_,this):k.unsafe(this,s).is0()}clearCofactor(){let{clearCofactor:y}=t;return o===Ve?this:y?y(_,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(y=!0){return Ot("isCompressed",y),this.assertValidity(),d(_,this,y)}toRawBytes(y=!0){return this.toBytes(y)}toHex(y=!0){return Et(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}_.BASE=new _(r.Gx,r.Gy,e.ONE),_.ZERO=new _(e.ZERO,e.ONE,e.ZERO),_.Fp=e,_.Fn=n;let U=n.BITS,k=new ke(_,t.endo?Math.ceil(U/2):U);return _}function Ji(r){return Uint8Array.of(r?2:3)}function df(r,t,e={}){kr(t),oe(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=e.randomBytes||pe,o=e.hmac||((x,...b)=>Xo(t,x,mt(...b))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,f=io(a),d={secret:i.BYTES,public:1+s.BYTES,publicUncompressed:1+2*s.BYTES,signature:2*i.BYTES,seed:f};function l(x){let b=a>>Ve;return x>b}function u(x){return l(x)?i.neg(x):x}function h(x,b){if(!i.isValidNot0(b))throw new Error(`invalid signature ${x}: out of range 1..CURVE.n`)}class g{constructor(b,I,L){h("r",b),h("s",I),this.r=b,this.s=I,L!=null&&(this.recovery=L),Object.freeze(this)}static fromBytes(b,I="compact"){if(I==="compact"){let L=i.BYTES;$(b,L*2);let K=b.subarray(0,L),N=b.subarray(L,L*2);return new g(i.fromBytes(K),i.fromBytes(N))}if(I==="der"){$(b);let{r:L,s:K}=Gt.toSig(b);return new g(L,K)}throw new Error("invalid format")}static fromHex(b,I){return this.fromBytes(de(b),I)}addRecoveryBit(b){return new g(this.r,this.s,b)}recoverPublicKey(b){let I=s.ORDER,{r:L,s:K,recovery:N}=this;if(N==null||![0,1,2,3].includes(N))throw new Error("recovery id invalid");if(a*Wi<I&&N>1)throw new Error("recovery id is ambiguous for h>1 curve");let G=N===2||N===3?L+a:L;if(!s.isValid(G))throw new Error("recovery id 2 or 3 invalid");let V=s.toBytes(G),yt=r.fromHex(mt(Ji((N&1)===0),V)),q=i.inv(G),tt=U(H("msgHash",b)),bt=i.create(-tt*q),Yt=i.create(K*q),ie=r.BASE.multiplyUnsafe(bt).add(yt.multiplyUnsafe(Yt));if(ie.is0())throw new Error("point at infinify");return ie.assertValidity(),ie}hasHighS(){return l(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,i.neg(this.s),this.recovery):this}toBytes(b="compact"){if(b==="compact")return mt(i.toBytes(this.r),i.toBytes(this.s));if(b==="der")return de(Gt.hexFromSig(this));throw new Error("invalid format")}toHex(b){return Et(this.toBytes(b))}assertValidity(){}static fromCompact(b){return g.fromBytes(H("sig",b),"compact")}static fromDER(b){return g.fromBytes(H("sig",b),"der")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Et(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Et(this.toBytes("compact"))}}function w(x){try{return!!He(i,x)}catch{return!1}}function p(x,b){try{let I=x.length;return b===!0&&I!==d.public||b===!1&&I!==d.publicUncompressed?!1:!!r.fromBytes(x)}catch{return!1}}function S(x=n(f)){return ao(x,a)}let B={isValidSecretKey:w,isValidPublicKey:p,randomSecretKey:S,isValidPrivateKey:w,randomPrivateKey:S,normPrivateKeyToScalar:x=>He(i,x),precompute(x=8,b=r.BASE){return b.precompute(x,!1)}};function v(x,b=!0){return r.BASE.multiply(He(i,x)).toBytes(b)}function T(x){if(typeof x=="bigint")return!1;if(x instanceof r)return!0;if(i.allowedLengths||d.secret===d.public)return;let b=H("key",x).length;return b===d.public||b===d.publicUncompressed}function R(x,b,I=!0){if(T(x)===!0)throw new Error("first arg must be private key");if(T(b)===!1)throw new Error("second arg must be public key");let L=He(i,x);return r.fromHex(b).multiply(L).toBytes(I)}let _=e.bits2int||function(x){if(x.length>8192)throw new Error("input is too large");let b=Ke(x),I=x.length*8-c;return I>0?b>>BigInt(I):b},U=e.bits2int_modN||function(x){return i.create(_(x))},k=ne(c);function D(x){return re("num < 2^"+c,x,Zt,k),i.toBytes(x)}function y(x,b,I=m){if(["recovered","canonical"].some(bt=>bt in I))throw new Error("sign() legacy options not supported");let{lowS:L,prehash:K,extraEntropy:N}=I;L==null&&(L=!0),x=H("msgHash",x),$i(I),K&&(x=H("prehashed msgHash",t(x)));let O=U(x),G=He(i,b),V=[D(G),D(O)];if(N!=null&&N!==!1){let bt=N===!0?n(d.secret):N;V.push(H("extraEntropy",bt))}let yt=mt(...V),q=O;function tt(bt){let Yt=_(bt);if(!i.isValidNot0(Yt))return;let ie=i.inv(Yt),Ze=r.BASE.multiply(Yt).toAffine(),ae=i.create(Ze.x);if(ae===Zt)return;let je=i.create(ie*i.create(q+ae*G));if(je===Zt)return;let hs=(Ze.x===ae?0:2)|Number(Ze.y&Ve),ds=je;return L&&l(je)&&(ds=u(je),hs^=1),new g(ae,ds,hs)}return{seed:yt,k2sig:tt}}let m={lowS:e.lowS,prehash:!1},E={lowS:e.lowS,prehash:!1};function A(x,b,I=m){let{seed:L,k2sig:K}=y(x,b,I);return si(t.outputLen,i.BYTES,o)(L,K)}r.BASE.precompute(8);function P(x,b,I,L=E){let K=x;b=H("msgHash",b),I=H("publicKey",I),$i(L);let{lowS:N,prehash:O,format:G}=L;if("strict"in L)throw new Error("options.strict was renamed to lowS");let V,yt;if(G===void 0){let q=typeof K=="string"||he(K),tt=!q&&K!==null&&typeof K=="object"&&typeof K.r=="bigint"&&typeof K.s=="bigint";if(!q&&!tt)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(tt)V=new g(K.r,K.s);else if(q){try{V=g.fromDER(K)}catch(bt){if(!(bt instanceof Gt.Err))throw bt}if(!V)try{V=g.fromCompact(K)}catch{return!1}}}else if(G==="compact"||G==="der"){if(typeof K!="string"&&!he(K))throw new Error('"der" / "compact" format expects Uint8Array signature');V=g.fromBytes(H("sig",K),G)}else if(G==="js"){if(!(K instanceof g))throw new Error('"js" format expects Signature instance');V=K}else throw new Error('format must be "compact", "der" or "js"');if(!V)return!1;try{if(yt=r.fromHex(I),N&&V.hasHighS())return!1;O&&(b=t(b));let{r:q,s:tt}=V,bt=U(b),Yt=i.inv(tt),ie=i.create(bt*Yt),Ze=i.create(q*Yt),ae=r.BASE.multiplyUnsafe(ie).add(yt.multiplyUnsafe(Ze));return ae.is0()?!1:i.create(ae.x)===q}catch{return!1}}function C(x){let b=B.randomSecretKey(x);return{secretKey:b,publicKey:v(b)}}return Object.freeze({keygen:C,getPublicKey:v,sign:A,verify:P,getSharedSecret:R,utils:B,Point:r,Signature:g,info:{type:"weierstrass",lengths:d,publicKeyHasPrefix:!0}})}function pf(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=r.allowedPrivateKeyLengths?Array.from(new Set(r.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=gt(t.n,{BITS:r.nBitLength,allowedLengths:n,modOnDecode:r.wrapPrivateKey}),s={Fp:e,Fn:o,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:s}}function mf(r){let{CURVE:t,curveOpts:e}=pf(r),n={hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,hash:r.hash,ecdsaOpts:n}}function yf(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function Qi(r){let{CURVE:t,curveOpts:e,hash:n,ecdsaOpts:o}=mf(r),s=hf(t,e),i=df(s,n,o);return yf(r,i)}function ta(r,t){let e=n=>Qi({...r,hash:n});return{...e(t),create:e}}var Jo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},bf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ea=BigInt(2);function gf(r){let t=Jo.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,d=f*f*r%t,l=Z(d,e,t)*d%t,u=Z(l,e,t)*d%t,h=Z(u,ea,t)*f%t,g=Z(h,o,t)*h%t,w=Z(g,s,t)*g%t,p=Z(w,a,t)*w%t,S=Z(p,c,t)*p%t,B=Z(S,a,t)*w%t,v=Z(B,e,t)*d%t,T=Z(v,i,t)*g%t,R=Z(T,n,t)*f%t,_=Z(R,ea,t);if(!Wo.eql(Wo.sqr(_),r))throw new Error("Cannot find square root");return _}var Wo=gt(Jo.p,void 0,void 0,{sqrt:gf}),Fe=ta({...Jo,Fp:Wo,lowS:!0,endo:bf},Hr);function ra(r,t,e,n){let o=fe.digest(e instanceof Uint8Array?e:e.subarray());if(Yr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Fe.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new fr(String(s))});try{return n?.signal?.throwIfAborted(),Fe.verify(t,o.digest,r)}catch(s){throw new fr(String(s))}}var an=class{type="secp256k1";raw;_key;constructor(t){this._key=oa(t),this.raw=na(this._key)}toMultihash(){return At.digest(Kt(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return ra(this._key,e,t,n)}};function Qo(r){return new an(r)}function na(r){return Fe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function oa(r){try{return Fe.ProjectivePoint.fromHex(r),r}catch(t){throw new Ae(String(t))}}function ts(r,t){let{Type:e,Data:n}=Dt.decode(r),o=n??new Uint8Array;switch(e){case Q.RSA:return Zo(o,t);case Q.Ed25519:return wo(o);case Q.secp256k1:return Qo(o);case Q.ECDSA:return Xn(o);default:throw new ce}}function sa(r){let{Type:t,Data:e}=Dt.decode(r.digest),n=e??new Uint8Array;switch(t){case Q.Ed25519:return wo(n);case Q.secp256k1:return Qo(n);case Q.ECDSA:return Xn(n);default:throw new ce}}function Kt(r){return Dt.encode({Type:Q[r.type],Data:r.raw})}var ia=Symbol.for("nodejs.util.inspect.custom"),wf=114,mr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[En]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return st.createV1(wf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return dt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return dt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ia](){return`PeerId(${this.toString()})`}},yr=class extends mr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},br=class extends mr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},gr=class extends mr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},xf=2336,cn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(F(this.url))}[ia](){return`PeerId(${this.url})`}[En]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return st.createV1(xf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function es(r){if(r.type==="Ed25519")return new br({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new gr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new yr({multihash:r.toCID().multihash,publicKey:r});throw new ce}function aa(r){return es(r.publicKey)}function wr(r){if(Sf(r))return new yr({multihash:r});if(Ef(r))try{let t=sa(r);if(t.type==="Ed25519")return new br({multihash:r,publicKey:t});if(t.type==="secp256k1")return new gr({multihash:r,publicKey:t})}catch{let e=z(r.digest);return new cn(new URL(e))}throw new Pr("Supplied PeerID Multihash is invalid")}function Ef(r){return r.code===At.code}function Sf(r){return r.code===fe.code}function Se(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function un(r){let t=$t(Y.decode(`z${r}`));return wr(t)}var xr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return Se(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return Se(this.map.values(),t=>t.key)}values(){return Se(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Er=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Se(this.set.entries(),t=>{let e=un(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=un(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Se(this.set.values(),t=>un(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function jt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var fn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},ze=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new fn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new fn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var rs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ln(r={}){return vf(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function vf(r,t){t=t??{};let e=t.onEnd,n=new ze,o,s,i,a=jt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,S)=>{s=B=>{s=null,n.push(B);try{p(r(n))}catch(v){S(v)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=jt()})}},f=p=>s!=null?s(p):(n.push(p),o),d=p=>(n=new ze,s!=null?s({error:p}):(n.push({error:p}),o)),l=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:p})},u=p=>i?o:(i=!0,p!=null?d(p):f({done:!0})),h=()=>(n=new ze,u(),{done:!0}),g=p=>(u(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:g,push:l,end:u,get readableLength(){return n.size},onEmpty:async p=>{let S=p?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let B,v;S!=null&&(B=new Promise((T,R)=>{v=()=>{R(new rs)},S.addEventListener("abort",v)}));try{await Promise.race([a.promise,B])}finally{v!=null&&S!=null&&S?.removeEventListener("abort",v)}}},e==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(p){return w.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return w.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(p){return w.end(p),e!=null&&(e(p),e=void 0),o},get readableLength(){return w.readableLength},onEmpty:p=>w.onEmpty(p)},o}var hn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function ca(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new hn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new hn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var ns=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=jt(),this.haveNext=jt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=jt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=jt(),await ca(this.readNext.promise,e?.signal,e)}};function ua(){return new ns}function Af(r){return r[Symbol.asyncIterator]!=null}async function If(r,t,e){try{await Promise.all(r.map(async n=>{for await(let o of n)await t.push(o,{signal:e}),e.throwIfAborted()})),await t.end(void 0,{signal:e})}catch(n){await t.end(n,{signal:e}).catch(()=>{})}}async function*Bf(r){let t=new AbortController,e=ua();If(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*_f(r){for(let t of r)yield*t}function Lf(...r){let t=[];for(let e of r)Af(e)||t.push(e);return t.length===r.length?_f(t):Bf(r)}var fa=Lf;function Sr(r,...t){if(r==null)throw new Error("Empty pipeline");if(os(r)){let n=r;r=()=>n.source}else if(ha(r)||la(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&os(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)os(e[n])&&(e[n]=Df(e[n]));return Tf(...e)}var Tf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},la=r=>r?.[Symbol.asyncIterator]!=null,ha=r=>r?.[Symbol.iterator]!=null,os=r=>r==null?!1:r.sink!=null&&r.source!=null,Df=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=ln({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(la(s))o=async function*(){yield*s,n.end()};else if(ha(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return fa(n,o())}return r.source};var is=Na(pa(),1);var Ar=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},as=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},ma=r=>globalThis.DOMException===void 0?new as(r):new DOMException(r),ya=r=>{let t=r.reason===void 0?ma("This operation was aborted."):r.reason;return t instanceof Error?t:ma(t)};function cs(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,f=new Promise((d,l)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:h}=t;h.aborted&&l(ya(h)),a=()=>{l(ya(h))},h.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(d,l);return}let u=new Ar;i=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(h){l(h)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?d():o instanceof Error?l(o):(u.message=o??`Promise timed out after ${e} milliseconds`,l(u))},e),(async()=>{try{d(await r)}catch(h){l(h)}})()}).finally(()=>{f.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}function us(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var Ir=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let o=us(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var Br=class extends is.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#w=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ir,...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})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#x(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},e)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#x&&this.#E){let e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}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.#u=t,this.#l()}async#I(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#w++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=cs(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#I(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof Ar&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function ba(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function ga(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function wa(r,t){let e=ba(r).return?.();ga(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var pn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ge=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},mn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},_r=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function yn(r){return r[Symbol.asyncIterator]!=null}function xa(r,t){if(r.byteLength>t)throw new Ge("Message length too long")}var gn=r=>{let t=Bt(r),e=it(t);return Di(r,e),gn.bytes=t,e};gn.bytes=0;function wn(r,t){t=t??{};let e=t.lengthEncoder??gn,n=t?.maxDataLength??4194304;function*o(s){xa(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return yn(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}wn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??gn,n=t?.maxDataLength??4194304;return xa(r,n),new et(e(r.byteLength),r)};var ve;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ve||(ve={}));var fs=r=>{let t=Pi(r);return fs.bytes=Bt(t),t};fs.bytes=0;function Lr(r,t){let e=new et,n=ve.LENGTH,o=-1,s=t?.lengthDecoder??fs,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===ve.LENGTH)try{if(o=s(e),o<0)throw new pn("Invalid message length");if(o>a)throw new Ge("Message length too long");let f=s.bytes;e.consume(f),t?.onLength!=null&&t.onLength(o),n=ve.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>i)throw new mn("Message length length too long");break}throw f}if(n===ve.DATA){if(e.byteLength<o)break;let f=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(f),yield f,n=ve.LENGTH}}}return yn(r)?async function*(){for await(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new _r("Unexpected end of input")}():function*(){for(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new _r("Unexpected end of input")}()}Lr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return Lr(n,{...t??{},onLength:s=>{e=s}})};var xn=class extends Ie{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=e.id,this.protocol=e.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let e=this.id.toString();throw new Error("No writable connection to "+e)}this.outboundStream.push(t instanceof Uint8Array?new et(t):t)}attachInboundStream(t,e){let n=()=>{wa(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=Sr(this._rawInboundStream,o=>Lr(o,e)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let e=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=ln({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),Sr(this.outboundStream,n=>wn(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),e==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function Ea(){return BigInt(`0x${z(rn(8),"base16")}`)}var Sa=(r,t)=>{let e=F(t.toString(16).padStart(16,"0"),"base16"),n=Kt(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},va=r=>fe.encode(r);var Aa=function(r){return Array.isArray(r)?r:[r]},Nf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=wr($t(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return es(ts(e)).equals(t)}return!1},Ia=async r=>{if(r.from==null)throw new J("RPC message was missing from");if(!await Nf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=wr($t(r.from)),e=r.key??t.publicKey;if(e==null)throw new J("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:kf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?ts(e):e}},Tr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:Uf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Kt(r.key):void 0}:{data:r.data,topic:r.topic},Uf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},kf=r=>BigInt(`0x${z(r,"base16")}`);var Ba=F("libp2p-pubsub:");async function _a(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:aa(r)},o=ue([Ba,e(Tr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function La(r,t){if(r.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(r.signature==null)throw new Error("Message must contain a signature to be verified");if(r.from==null)throw new Error("Message must contain a from property to be verified");let e=ue([Ba,t({...Tr(r),signature:void 0,key:void 0}).subarray()]);return Of(r).verify(e,r.signature)}function Of(r){if(r.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(r.from==null)throw new Error("Could not get the public key from the originator id");if(r.key!=null)return r.key;if(r.from.publicKey!=null)return r.from.publicKey;throw new Error("Could not get the public key from the originator id")}var ls=class extends Ie{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,e){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:a=10,maxInboundStreams:c=1,maxOutboundStreams:f=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=Aa(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new xr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new Br({concurrency:a}),this.maxInboundStreams=c,this.maxOutboundStreams=f,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let e={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.multicodecs.map(async e=>{await t.unhandle(e)})),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:e,connection:n}=t,o=n.remotePeer;if(e.protocol==null){e.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,e.protocol),i=s.attachInboundStream(e);this.processMessages(o,i,s).catch(a=>{this.log(a)})}_onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await e.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new xn(this.components,{id:t,protocol:e});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return e}}async processMessages(t,e,n){try{await Sr(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),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(t,n,{subscriptions:(i.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,e,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.id,subscriptions:o.map(({topic:i,subscribe:a})=>({topic:`${i??""}`,subscribe:!!a}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),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 a=await Ia(i);await this.processMessage(t,a)}catch(a){this.log.error(a)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new Er,this.topics.set(n,o)),e.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,e){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,e)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new J("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new J("Need key when signature policy is StrictSign but it was missing");return Sa(t.key,t.sequenceNumber);case"StrictNoSign":return va(t.data);default:throw new J("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,e){let{messages:n,subscriptions:o,subscribe:s}=e;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(Tr)})}sendRpc(t,e){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(e))}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new J('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new J("StrictNoSigning: signature should not be present");if(e.key!=null)throw new J("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new J("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new J("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new J("StrictSigning: Signing required and no sequenceNumber was present");if(!await La(e,this.encodeMessage.bind(this)))throw new J("StrictSigning: Invalid message signature");break;default:throw new J("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===Ye.Reject||s===Ye.Ignore)throw new J("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return _a(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 Cr("not started yet");if(t==null)throw new j("Topic is required");let e=this.topics.get(t.toString());return e==null?[]:Array.from(e.values())}async publish(t,e){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:e??new Uint8Array(0),sequenceNumber:Ea()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let e=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,e),e){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{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())}};return Ua(Mf);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: