@libp2p/pubsub 10.1.17-ce6b542a8 → 10.1.17-cf9aab5c8

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 Ka=Object.create;var Tr=Object.defineProperty;var Ra=Object.getOwnPropertyDescriptor;var Na=Object.getOwnPropertyNames;var Ua=Object.getPrototypeOf,ka=Object.prototype.hasOwnProperty;var Oa=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yt=(e,t)=>{for(var r in t)Tr(e,r,{get:t[r],enumerable:!0})},ws=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Na(t))!ka.call(e,o)&&o!==r&&Tr(e,o,{get:()=>t[o],enumerable:!(n=Ra(t,o))||n.enumerable});return e};var Ma=(e,t,r)=>(r=e!=null?Ka(Ua(e)):{},ws(t||!e||!e.__esModule?Tr(r,"default",{value:e,enumerable:!0}):r,e)),qa=e=>ws(Tr({},"__esModule",{value:!0}),e);var ga=Oa((xm,fs)=>{"use strict";var Nf=Object.prototype.hasOwnProperty,pt="~";function Er(){}Object.create&&(Er.prototype=Object.create(null),new Er().__proto__||(pt=!1));function Uf(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function ba(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new Uf(r,n||e,o),i=pt?pt+t:t;return e._events[i]?e._events[i].fn?e._events[i]=[e._events[i],s]:e._events[i].push(s):(e._events[i]=s,e._eventsCount++),e}function dn(e,t){--e._eventsCount===0?e._events=new Er:delete e._events[t]}function lt(){this._events=new Er,this._eventsCount=0}lt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)Nf.call(r,n)&&t.push(pt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};lt.prototype.listeners=function(t){var r=pt?pt+t:t,n=this._events[r];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};lt.prototype.listenerCount=function(t){var r=pt?pt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};lt.prototype.emit=function(t,r,n,o,s,i){var c=pt?pt+t:t;if(!this._events[c])return!1;var a=this._events[c],f=arguments.length,p,l;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),f){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,r),!0;case 3:return a.fn.call(a.context,r,n),!0;case 4:return a.fn.call(a.context,r,n,o),!0;case 5:return a.fn.call(a.context,r,n,o,s),!0;case 6:return a.fn.call(a.context,r,n,o,s,i),!0}for(l=1,p=new Array(f-1);l<f;l++)p[l-1]=arguments[l];a.fn.apply(a.context,p)}else{var u=a.length,h;for(l=0;l<u;l++)switch(a[l].once&&this.removeListener(t,a[l].fn,void 0,!0),f){case 1:a[l].fn.call(a[l].context);break;case 2:a[l].fn.call(a[l].context,r);break;case 3:a[l].fn.call(a[l].context,r,n);break;case 4:a[l].fn.call(a[l].context,r,n,o);break;default:if(!p)for(h=1,p=new Array(f-1);h<f;h++)p[h-1]=arguments[h];a[l].fn.apply(a[l].context,p)}}return!0};lt.prototype.on=function(t,r,n){return ba(this,t,r,n,!1)};lt.prototype.once=function(t,r,n){return ba(this,t,r,n,!0)};lt.prototype.removeListener=function(t,r,n,o){var s=pt?pt+t:t;if(!this._events[s])return this;if(!r)return dn(this,s),this;var i=this._events[s];if(i.fn)i.fn===r&&(!o||i.once)&&(!n||i.context===n)&&dn(this,s);else{for(var c=0,a=[],f=i.length;c<f;c++)(i[c].fn!==r||o&&!i[c].once||n&&i[c].context!==n)&&a.push(i[c]);a.length?this._events[s]=a.length===1?a[0]:a:dn(this,s)}return this};lt.prototype.removeAllListeners=function(t){var r;return t?(r=pt?pt+t:t,this._events[r]&&dn(this,r)):(this._events=new Er,this._eventsCount=0),this};lt.prototype.off=lt.prototype.removeListener;lt.prototype.addListener=lt.prototype.on;lt.prefixed=pt;lt.EventEmitter=lt;typeof fs<"u"&&(fs.exports=lt)});var Ff={};yt(Ff,{PubSubBaseProtocol:()=>ys});var En=Symbol.for("@libp2p/peer-id");var Ge;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(Ge||(Ge={}));var Zf=Symbol.for("@libp2p/pubsub");var Z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Se=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Cr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Q=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Pr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ue=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ve=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var In={};yt(In,{base58btc:()=>j,base58flickr:()=>ja});var $f=new Uint8Array(0);function xs(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Dt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Es(e){return new TextEncoder().encode(e)}function Ss(e){return new TextDecoder().decode(e)}function Ha(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),f=Math.log(c)/Math.log(256),p=Math.log(256)/Math.log(c);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var E=0,S=0,b=0,A=d.length;b!==A&&d[b]===0;)b++,E++;for(var w=(A-b)*p+1>>>0,L=new Uint8Array(w);b!==A;){for(var D=d[b],O=0,k=w-1;(D!==0||O<S)&&k!==-1;k--,O++)D+=256*L[k]>>>0,L[k]=D%c>>>0,D=D/c>>>0;if(D!==0)throw new Error("Non-zero carry");S=O,b++}for(var R=w-S;R!==w&&L[R]===0;)R++;for(var x=a.repeat(E);R<w;++R)x+=e.charAt(L[R]);return x}function u(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var E=0;if(d[E]!==" "){for(var S=0,b=0;d[E]===a;)S++,E++;for(var A=(d.length-E)*f+1>>>0,w=new Uint8Array(A);d[E];){var L=r[d.charCodeAt(E)];if(L===255)return;for(var D=0,O=A-1;(L!==0||D<b)&&O!==-1;O--,D++)L+=c*w[O]>>>0,w[O]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");b=D,E++}if(d[E]!==" "){for(var k=A-b;k!==A&&w[k]===0;)k++;for(var R=new Uint8Array(S+(A-k)),x=S;k!==A;)R[x++]=w[k++];return R}}}function h(d){var E=u(d);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:u,decode:h}}var Va=Ha,Fa=Va,As=Fa;var Sn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},vn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.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 Bs(this,t)}},An=class{decoders;constructor(t){this.decoders=t}or(t){return Bs(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Bs(e,t){return new An({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Bn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sn(t,r,n),this.decoder=new vn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ae({name:e,prefix:t,encode:r,decode:n}){return new Bn(e,t,r,n)}function $t({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=As(r,e);return Ae({prefix:t,name:e,encode:n,decode:s=>Dt(o(s))})}function za(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let f=0;f<o;++f){let p=t[e[f]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|p,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ga(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Za(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function W({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Za(n);return Ae({prefix:t,name:e,encode(s){return Ga(s,n,r)},decode(s){return za(s,o,r,e)}})}var j=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ja=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _n={};yt(_n,{base32:()=>Be,base32hex:()=>Wa,base32hexpad:()=>Qa,base32hexpadupper:()=>tc,base32hexupper:()=>Ja,base32pad:()=>Xa,base32padupper:()=>$a,base32upper:()=>Ya,base32z:()=>ec});var Be=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ya=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xa=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),$a=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wa=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ja=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Qa=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tc=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ec=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ln={};yt(Ln,{base36:()=>Ze,base36upper:()=>rc});var Ze=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rc=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var nc=Ls,Is=128,oc=127,sc=~oc,ic=Math.pow(2,31);function Ls(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ic;)t[r++]=e&255|Is,e/=128;for(;e&sc;)t[r++]=e&255|Is,e>>>=7;return t[r]=e|0,Ls.bytes=r-n+1,t}var ac=Tn,cc=128,_s=127;function Tn(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw Tn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&_s)<<o:(i&_s)*Math.pow(2,o),o+=7}while(i>=cc);return Tn.bytes=s-n,r}var uc=Math.pow(2,7),fc=Math.pow(2,14),lc=Math.pow(2,21),hc=Math.pow(2,28),dc=Math.pow(2,35),pc=Math.pow(2,42),mc=Math.pow(2,49),yc=Math.pow(2,56),bc=Math.pow(2,63),gc=function(e){return e<uc?1:e<fc?2:e<lc?3:e<hc?4:e<dc?5:e<pc?6:e<mc?7:e<yc?8:e<bc?9:10},wc={encode:nc,decode:ac,encodingLength:gc},xc=wc,je=xc;function Ye(e,t=0){return[je.decode(e,t),je.decode.bytes]}function Ie(e,t,r=0){return je.encode(e,t,r),t}function _e(e){return je.encodingLength(e)}function Bt(e,t){let r=t.byteLength,n=_e(e),o=n+_e(r),s=new Uint8Array(o+r);return Ie(e,s,0),Ie(r,s,n),s.set(t,o),new Le(e,r,t,s)}function Wt(e){let t=Dt(e),[r,n]=Ye(t),[o,s]=Ye(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Le(r,o,i,t)}function Ts(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&xs(e.bytes,r.bytes)}}var Le=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Cs(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Sc(r,Cn(e),t??j.encoder);default:return vc(r,Cn(e),t??Be.encoder)}}var Ps=new WeakMap;function Cn(e){let t=Ps.get(e);if(t==null){let r=new Map;return Ps.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,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:r}=this;if(t!==Xe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ac)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Bt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Ts(t.multihash,n.multihash)}toString(t){return Cs(this,t)}toJSON(){return{"/":Cs(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Ds(n,o,s.bytes))}else if(r[Bc]===!0){let{version:n,multihash:o,code:s}=r,i=Wt(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Xe)throw new Error(`Version 0 CID must use dag-pb (code: ${Xe}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ds(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Xe,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Dt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Le(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,u]=Ye(t.subarray(r));return r+=u,l},o=n(),s=Xe;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),f=r+a,p=f-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:p,size:f}}static parse(t,r){let[n,o]=Ec(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Cn(s).set(n,t),s}};function Ec(e,t){switch(e[0]){case"Q":{let r=t??j;return[j.prefix,r.decode(`${j.prefix}${e}`)]}case j.prefix:{let r=t??j;return[j.prefix,r.decode(e)]}case Be.prefix:{let r=t??Be;return[Be.prefix,r.decode(e)]}case Ze.prefix:{let r=t??Ze;return[Ze.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Sc(e,t,r){let{prefix:n}=r;if(n!==j.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function vc(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Xe=112,Ac=18;function Ds(e,t,r){let n=_e(e),o=n+_e(t),s=new Uint8Array(o+r.byteLength);return Ie(e,s,0),Ie(t,s,n),s.set(r,o),s}var Bc=Symbol.for("@ipld/js-cid/CID");var Pn={};yt(Pn,{identity:()=>It});var Ks=0,Ic="identity",Rs=Dt;function _c(e){return Bt(Ks,Rs(e))}var It={code:Ks,name:Ic,encode:Rs,digest:_c};function bt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Kt(e=0){return new Uint8Array(e)}function ct(e=0){return new Uint8Array(e)}function fe(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ct(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Us=Symbol.for("@achingbrain/uint8arraylist");function Ns(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Kr(e){return!!e?.[Us]}var rt=class e{bufs;length;[Us]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Kr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Kr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Ns(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ns(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Kr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return fe(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:fe(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let f=t>=c&&t<a,p=r>c&&r<=a;if(f&&p){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(p){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=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(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let 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 c=i,a=this.byteLength-n.byteLength,f=n.byteLength-1,p;for(let l=r;l<=a;l+=p){p=0;for(let u=f;u>=0;u--){let h=this.get(l+u);if(n[u]!==h){p=Math.max(1,u-c[h]);break}}if(p===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!bt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Dn={};yt(Dn,{base10:()=>Lc});var Lc=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var Kn={};yt(Kn,{base16:()=>Tc,base16upper:()=>Cc});var Tc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Cc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Rn={};yt(Rn,{base2:()=>Pc});var Pc=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Nn={};yt(Nn,{base256emoji:()=>Uc});var ks=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}"),Dc=ks.reduce((e,t,r)=>(e[r]=t,e),[]),Kc=ks.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Rc(e){return e.reduce((t,r)=>(t+=Dc[r],t),"")}function Nc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Kc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Uc=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:Rc,decode:Nc});var Un={};yt(Un,{base64:()=>kc,base64pad:()=>Oc,base64url:()=>Mc,base64urlpad:()=>qc});var kc=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Oc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Mc=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),qc=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var kn={};yt(kn,{base8:()=>Hc});var Hc=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var On={};yt(On,{identity:()=>Vc});var Vc=Ae({prefix:"\0",name:"identity",encode:e=>Ss(e),decode:e=>Es(e)});var Kl=new TextEncoder,Rl=new TextDecoder;var Hn={};yt(Hn,{sha256:()=>le,sha512:()=>Gc});function qn({name:e,code:t,encode:r}){return new Mn(e,t,r)}var Mn=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?Bt(this.code,r):r.then(n=>Bt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ms(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var le=qn({name:"sha2-256",code:18,encode:Ms("SHA-256")}),Gc=qn({name:"sha2-512",code:19,encode:Ms("SHA-512")});var Vn={...On,...Rn,...kn,...Dn,...Kn,..._n,...Ln,...In,...Un,...Nn},Zl={...Hn,...Pn};function Hs(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var qs=Hs("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Fn=Hs("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ct(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Zc={utf8:qs,"utf-8":qs,hex:Vn.base16,latin1:Fn,ascii:Fn,binary:Fn,...Vn},Rr=Zc;function F(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var jc=parseInt("11111",2),zn=parseInt("10000000",2),Yc=parseInt("01111111",2),Vs={0:$e,1:$e,2:Xc,3:Jc,4:Qc,5:Wc,6:$c,16:$e,22:$e,48:$e};function Rt(e,t={offset:0}){let r=e[t.offset]&jc;if(t.offset++,Vs[r]!=null)return Vs[r](e,t);throw new Error("No decoder for tag "+r)}function We(e,t){let r=0;if((e[t.offset]&zn)===zn){let n=e[t.offset]&Yc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function $e(e,t){We(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Rt(e,t);if(n===null)break;r.push(n)}return r}function Xc(e,t){let r=We(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function $c(e,t){let r=We(e,t),n=t.offset+r,o=e[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 c=`${s}.${i}`,a=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,a.push(f&127),f<128){a.reverse();let p=0;for(let l=0;l<a.length;l++)p+=a[l]<<l*7;c+=`.${p}`,a=[]}}return c}function Wc(e,t){return t.offset++,null}function Jc(e,t){let r=We(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Qc(e,t){let r=We(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function tu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new rt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Gn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=tu(e.byteLength);return new rt(Uint8Array.from([t.byteLength|zn]),t)}function gt(e){let t=new rt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new rt(Uint8Array.from([2]),Gn(t),t)}function Nr(e){let t=Uint8Array.from([0]),r=new rt(t,e);return new rt(Uint8Array.from([3]),Gn(r),r)}function Qt(e,t=48){let r=new rt;for(let n of e)r.append(n);return new rt(Uint8Array.from([t]),Gn(r),r)}async function Fs(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var eu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ru=Uint8Array.from([6,5,43,129,4,0,34]),nu=Uint8Array.from([6,5,43,129,4,0,35]),ou={ext:!0,kty:"EC",crv:"P-256"},su={ext:!0,kty:"EC",crv:"P-384"},iu={ext:!0,kty:"EC",crv:"P-521"},Zn=32,jn=48,Yn=66;function Xn(e){let t=Rt(e);return zs(t)}function zs(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Zn*2+1)return n=z(t.subarray(r,r+Zn),"base64url"),o=z(t.subarray(r+Zn),"base64url"),new Te({...ou,key_ops:["verify"],x:n,y:o});if(t.byteLength===jn*2+1)return n=z(t.subarray(r,r+jn),"base64url"),o=z(t.subarray(r+jn),"base64url"),new Te({...su,key_ops:["verify"],x:n,y:o});if(t.byteLength===Yn*2+1)return n=z(t.subarray(r,r+Yn),"base64url"),o=z(t.subarray(r+Yn),"base64url"),new Te({...iu,key_ops:["verify"],x:n,y:o});throw new Z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Gs(e){return Qt([gt(Uint8Array.from([1])),Qt([au(e.crv)],160),Qt([Nr(new rt(Uint8Array.from([4]),F(e.x??"","base64url"),F(e.y??"","base64url")))],161)]).subarray()}function au(e){if(e==="P-256")return eu;if(e==="P-384")return ru;if(e==="P-521")return nu;throw new Z(`Invalid curve ${e}`)}var Te=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Gs(this.jwk)),this._raw}toMultihash(){return It.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}async verify(t,r,n){return Fs(this.jwk,r,t,n)}};var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function kt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Je(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function wt(e,...t){if(!kt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Ur(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Je(e.outputLen),Je(e.blockLen)}function Pe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function js(e,t){wt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Ot(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function kr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function _t(e,t){return e<<32-t|e>>>t}var Ys=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",cu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function vt(e){if(wt(e),Ys)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=cu[e[r]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function Zs(e){if(e>=Ut._0&&e<=Ut._9)return e-Ut._0;if(e>=Ut.A&&e<=Ut.F)return e-(Ut.A-10);if(e>=Ut.a&&e<=Ut.f)return e-(Ut.a-10)}function de(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ys)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Zs(e.charCodeAt(s)),c=Zs(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function $n(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Qe(e){return typeof e=="string"&&(e=$n(e)),wt(e),e}function ht(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];wt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Ce=class{};function Wn(e){let t=n=>e().update(Qe(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function te(e=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(e));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function uu(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,f=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+f,c,n)}function Xs(e,t,r){return e&t^~e&r}function $s(e,t,r){return e&t^e&r^t&r}var tr=class extends Ce{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=kr(this.buffer)}update(t){Pe(this),t=Qe(t),wt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=kr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Pe(this),js(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ot(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;uu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=kr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,p=this.get();if(f>p.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)c.setUint32(4*l,p[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Or=BigInt(4294967295),Ws=BigInt(32);function fu(e,t=!1){return t?{h:Number(e&Or),l:Number(e>>Ws&Or)}:{h:Number(e>>Ws&Or)|0,l:Number(e&Or)|0}}function Js(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=fu(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Jn=(e,t,r)=>e>>>r,Qn=(e,t,r)=>e<<32-r|t>>>r,pe=(e,t,r)=>e>>>r|t<<32-r,me=(e,t,r)=>e<<32-r|t>>>r,er=(e,t,r)=>e<<64-r|t>>>r-32,rr=(e,t,r)=>e>>>r-32|t<<64-r;function Ct(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Qs=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ti=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ei=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ri=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ni=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),oi=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var hu=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]),ee=new Uint32Array(64),Mr=class extends tr{constructor(t=32){super(64,t,8,!1),this.A=Mt[0]|0,this.B=Mt[1]|0,this.C=Mt[2]|0,this.D=Mt[3]|0,this.E=Mt[4]|0,this.F=Mt[5]|0,this.G=Mt[6]|0,this.H=Mt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)ee[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let u=ee[l-15],h=ee[l-2],d=_t(u,7)^_t(u,18)^u>>>3,E=_t(h,17)^_t(h,19)^h>>>10;ee[l]=E+ee[l-7]+d+ee[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:f,H:p}=this;for(let l=0;l<64;l++){let u=_t(c,6)^_t(c,11)^_t(c,25),h=p+u+Xs(c,a,f)+hu[l]+ee[l]|0,E=(_t(n,2)^_t(n,13)^_t(n,22))+$s(n,o,s)|0;p=f,f=a,a=c,c=i+h|0,i=s,s=o,o=n,n=h+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,p=p+this.H|0,this.set(n,o,s,i,c,a,f,p)}roundClean(){Ot(ee)}destroy(){this.set(0,0,0,0,0,0,0,0),Ot(this.buffer)}};var si=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(e=>BigInt(e))),du=si[0],pu=si[1],re=new Uint32Array(80),ne=new Uint32Array(80),to=class extends tr{constructor(t=64){super(128,t,16,!1),this.Ah=st[0]|0,this.Al=st[1]|0,this.Bh=st[2]|0,this.Bl=st[3]|0,this.Ch=st[4]|0,this.Cl=st[5]|0,this.Dh=st[6]|0,this.Dl=st[7]|0,this.Eh=st[8]|0,this.El=st[9]|0,this.Fh=st[10]|0,this.Fl=st[11]|0,this.Gh=st[12]|0,this.Gl=st[13]|0,this.Hh=st[14]|0,this.Hl=st[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:f,El:p,Fh:l,Fl:u,Gh:h,Gl:d,Hh:E,Hl:S}=this;return[t,r,n,o,s,i,c,a,f,p,l,u,h,d,E,S]}set(t,r,n,o,s,i,c,a,f,p,l,u,h,d,E,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=f|0,this.El=p|0,this.Fh=l|0,this.Fl=u|0,this.Gh=h|0,this.Gl=d|0,this.Hh=E|0,this.Hl=S|0}process(t,r){for(let w=0;w<16;w++,r+=4)re[w]=t.getUint32(r),ne[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let L=re[w-15]|0,D=ne[w-15]|0,O=pe(L,D,1)^pe(L,D,8)^Jn(L,D,7),k=me(L,D,1)^me(L,D,8)^Qn(L,D,7),R=re[w-2]|0,x=ne[w-2]|0,T=pe(R,x,19)^er(R,x,61)^Jn(R,x,6),N=me(R,x,19)^rr(R,x,61)^Qn(R,x,6),C=ei(k,N,ne[w-7],ne[w-16]),g=ri(C,O,T,re[w-7],re[w-16]);re[w]=g|0,ne[w]=C|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:f,Dl:p,Eh:l,El:u,Fh:h,Fl:d,Gh:E,Gl:S,Hh:b,Hl:A}=this;for(let w=0;w<80;w++){let L=pe(l,u,14)^pe(l,u,18)^er(l,u,41),D=me(l,u,14)^me(l,u,18)^rr(l,u,41),O=l&h^~l&E,k=u&d^~u&S,R=ni(A,D,k,pu[w],ne[w]),x=oi(R,b,L,O,du[w],re[w]),T=R|0,N=pe(n,o,28)^er(n,o,34)^er(n,o,39),C=me(n,o,28)^rr(n,o,34)^rr(n,o,39),g=n&s^n&c^s&c,m=o&i^o&a^i&a;b=E|0,A=S|0,E=h|0,S=d|0,h=l|0,d=u|0,{h:l,l:u}=Ct(f|0,p|0,x|0,T|0),f=c|0,p=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let y=Qs(T,C,m);n=ti(y,x,N,g),o=y|0}({h:n,l:o}=Ct(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ct(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Ct(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l:p}=Ct(this.Dh|0,this.Dl|0,f|0,p|0),{h:l,l:u}=Ct(this.Eh|0,this.El|0,l|0,u|0),{h,l:d}=Ct(this.Fh|0,this.Fl|0,h|0,d|0),{h:E,l:S}=Ct(this.Gh|0,this.Gl|0,E|0,S|0),{h:b,l:A}=Ct(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,c,a,f,p,l,u,h,d,E,S,b,A)}roundClean(){Ot(re,ne)}destroy(){Ot(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var qr=Wn(()=>new Mr);var ii=Wn(()=>new to);var no=BigInt(0),ro=BigInt(1);function qt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function xt(e,t,r=""){let n=kt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function nr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function ai(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?no:BigInt("0x"+e)}function De(e){return ai(vt(e))}function Ht(e){return wt(e),ai(vt(Uint8Array.from(e).reverse()))}function Hr(e,t){return de(e.toString(16).padStart(t*2,"0"))}function oo(e,t){return Hr(e,t).reverse()}function H(e,t,r){let n;if(typeof t=="string")try{n=de(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(kt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function ci(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function so(e){return Uint8Array.from(e)}var eo=e=>typeof e=="bigint"&&no<=e;function ui(e,t,r){return eo(e)&&eo(t)&&eo(r)&&t<=e&&e<r}function or(e,t,r,n){if(!ui(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Vr(e){let t;for(t=0;e>no;e>>=ro,t+=1);return t}var oe=e=>(ro<<BigInt(e))-ro;function fi(e,t,r){if(typeof e!="number"||e<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 r!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},f=(...h)=>r(i,s,...h),p=(h=n(0))=>{i=f(o(0),h),s=f(),h.length!==0&&(i=f(o(1),h),s=f())},l=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,d=[];for(;h<t;){s=f();let E=s.slice();d.push(E),h+=s.length}return ht(...d)};return(h,d)=>{a(),p(h);let E;for(;!(E=d(l()));)p();return a(),E}}function se(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var io=()=>{throw new Error("not implemented")};function Ke(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var dt=BigInt(0),nt=BigInt(1),ye=BigInt(2),di=BigInt(3),pi=BigInt(4),mi=BigInt(5),mu=BigInt(7),yi=BigInt(8),yu=BigInt(9),bi=BigInt(16);function J(e,t){let r=e%t;return r>=dt?r:t+r}function G(e,t,r){let n=e;for(;t-- >dt;)n*=n,n%=r;return n}function li(e,t){if(e===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,o=dt,s=nt,i=nt,c=dt;for(;r!==dt;){let f=n/r,p=n%r,l=o-i*f,u=s-c*f;n=r,r=p,o=i,s=c,i=l,c=u}if(n!==nt)throw new Error("invert: does not exist");return J(o,t)}function ao(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function gi(e,t){let r=(e.ORDER+nt)/pi,n=e.pow(t,r);return ao(e,n,t),n}function bu(e,t){let r=(e.ORDER-mi)/yi,n=e.mul(t,ye),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,ye),o),c=e.mul(s,e.sub(i,e.ONE));return ao(e,c,t),c}function gu(e){let t=Et(e),r=wi(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+mu)/bi;return(c,a)=>{let f=c.pow(a,i),p=c.mul(f,n),l=c.mul(f,o),u=c.mul(f,s),h=c.eql(c.sqr(p),a),d=c.eql(c.sqr(l),a);f=c.cmov(f,p,h),p=c.cmov(u,l,d);let E=c.eql(c.sqr(p),a),S=c.cmov(f,p,E);return ao(c,S,a),S}}function wi(e){if(e<di)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%ye===dt;)t/=ye,r++;let n=ye,o=Et(e);for(;hi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return gi;let s=o.pow(n,t),i=(t+nt)/ye;return function(a,f){if(a.is0(f))return f;if(hi(a,f)!==1)throw new Error("Cannot find square root");let p=r,l=a.mul(a.ONE,s),u=a.pow(f,t),h=a.pow(f,i);for(;!a.eql(u,a.ONE);){if(a.is0(u))return a.ZERO;let d=1,E=a.sqr(u);for(;!a.eql(E,a.ONE);)if(d++,E=a.sqr(E),d===p)throw new Error("Cannot find square root");let S=nt<<BigInt(p-d-1),b=a.pow(l,S);p=d,l=a.sqr(b),u=a.mul(u,l),h=a.mul(h,b)}return h}}function wu(e){return e%pi===di?gi:e%yi===mi?bu:e%bi===yu?gu(e):wi(e)}var Vt=(e,t)=>(J(e,t)&nt)===nt,xu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function co(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=xu.reduce((n,o)=>(n[o]="function",n),t);return se(e,r),e}function Eu(e,t,r){if(r<dt)throw new Error("invalid exponent, negatives unsupported");if(r===dt)return e.ONE;if(r===nt)return t;let n=e.ONE,o=t;for(;r>dt;)r&nt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=nt;return n}function sr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function hi(e,t){let r=(e.ORDER-nt)/ye,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Fr(e,t){t!==void 0&&Je(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Et(e,t,r=!1,n={}){if(e<=dt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)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"&&(r=u.isLE),typeof u.modFromBytes=="boolean"&&(i=u.modFromBytes),c=u.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:f}=Fr(e,o);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let p,l=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:f,MASK:oe(a),ZERO:dt,ONE:nt,allowedLengths:c,create:u=>J(u,e),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return dt<=u&&u<e},is0:u=>u===dt,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&nt)===nt,neg:u=>J(-u,e),eql:(u,h)=>u===h,sqr:u=>J(u*u,e),add:(u,h)=>J(u+h,e),sub:(u,h)=>J(u-h,e),mul:(u,h)=>J(u*h,e),pow:(u,h)=>Eu(l,u,h),div:(u,h)=>J(u*li(h,e),e),sqrN:u=>u*u,addN:(u,h)=>u+h,subN:(u,h)=>u-h,mulN:(u,h)=>u*h,inv:u=>li(u,e),sqrt:s||(u=>(p||(p=wu(e)),p(l,u))),toBytes:u=>r?oo(u,f):Hr(u,f),fromBytes:(u,h=!0)=>{if(c){if(!c.includes(u.length)||u.length>f)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+u.length);let E=new Uint8Array(f);E.set(u,r?0:E.length-u.length),u=E}if(u.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+u.length);let d=r?Ht(u):De(u);if(i&&(d=J(d,e)),!h&&!l.isValid(d))throw new Error("invalid field element: outside of range 0..ORDER");return d},invertBatch:u=>sr(l,u),cmov:(u,h,d)=>d?h:u});return Object.freeze(l)}function xi(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function uo(e){let t=xi(e);return t+Math.ceil(t/2)}function fo(e,t,r=!1){let n=e.length,o=xi(t),s=uo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ht(e):De(e),c=J(i,t-nt)+nt;return r?oo(c,o):Hr(c,o)}var Re=BigInt(0),be=BigInt(1);function ir(e,t){let r=t.negate();return e?r:t}function Ft(e,t){let r=sr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Ai(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function lo(e,t){Ai(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=oe(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ei(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=be);let f=t*n,p=f+Math.abs(c)-1,l=c===0,u=c<0,h=t%2!==0;return{nextN:a,offset:p,isZero:l,isNeg:u,isNegF:h,offsetF:f}}function Su(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function vu(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var ho=new WeakMap,Bi=new WeakMap;function po(e){return Bi.get(e)||1}function Si(e){if(e!==Re)throw new Error("invalid wNAF")}var Ne=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Re;)r&be&&(n=n.add(o)),o=o.double(),r>>=be;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=lo(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let f=1;f<o;f++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=lo(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:f,isZero:p,isNeg:l,isNegF:u,offsetF:h}=Ei(n,c,i);n=a,p?s=s.add(ir(u,r[h])):o=o.add(ir(l,r[f]))}return Si(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=lo(t,this.bits);for(let i=0;i<s.windows&&n!==Re;i++){let{nextN:c,offset:a,isZero:f,isNeg:p}=Ei(n,i,s);if(n=c,!f){let l=r[a];o=o.add(p?l.negate():l)}}return Si(n),o}getPrecomputes(t,r,n){let o=ho.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ho.set(r,o))),o}cached(t,r,n){let o=po(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=po(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Ai(r,this.bits),Bi.set(t,r),ho.delete(t)}hasCache(t){return po(t)!==1}};function Ii(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Re||n>Re;)r&be&&(s=s.add(o)),n&be&&(i=i.add(o)),o=o.double(),r>>=be,n>>=be;return{p1:s,p2:i}}function Ue(e,t,r,n){Su(r,e),vu(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Vr(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let f=oe(a),p=new Array(Number(f)+1).fill(i),l=Math.floor((t.BITS-1)/a)*a,u=i;for(let h=l;h>=0;h-=a){p.fill(i);for(let E=0;E<s;E++){let S=n[E],b=Number(S>>BigInt(h)&f);p[b]=p[b].add(r[E])}let d=i;for(let E=p.length-1,S=i;E>0;E--)S=S.add(p[E]),d=d.add(S);if(u=u.add(d),h!==0)for(let E=0;E<a;E++)u=u.double()}return u}function vi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return co(t),t}else return Et(e,{isLE:r})}function zr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let f=t[a];if(!(typeof f=="bigint"&&f>Re))throw new Error(`CURVE.${a} must be positive bigint`)}let o=vi(t.p,r.Fp,n),s=vi(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var ie=BigInt(0),ot=BigInt(1),mo=BigInt(2),Au=BigInt(8);function Bu(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function Iu(e,t={}){let r=zr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;se(t,{},{uvRatio:"function"});let c=mo<<BigInt(o.BYTES*8)-ot,a=S=>n.create(S),f=t.uvRatio||((S,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,b))}}catch{return{isValid:!1,value:ie}}});if(!Bu(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function p(S,b,A=!1){let w=A?ot:ie;return or("coordinate "+S,b,w,c),b}function l(S){if(!(S instanceof d))throw new Error("ExtendedPoint expected")}let u=Ke((S,b)=>{let{X:A,Y:w,Z:L}=S,D=S.is0();b==null&&(b=D?Au:n.inv(L));let O=a(A*b),k=a(w*b),R=n.mul(L,b);if(D)return{x:ie,y:ot};if(R!==ot)throw new Error("invZ was invalid");return{x:O,y:k}}),h=Ke(S=>{let{a:b,d:A}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:w,Y:L,Z:D,T:O}=S,k=a(w*w),R=a(L*L),x=a(D*D),T=a(x*x),N=a(k*b),C=a(x*a(N+R)),g=a(T+a(A*a(k*R)));if(C!==g)throw new Error("bad point: equation left != right (1)");let m=a(w*L),y=a(D*O);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(b,A,w,L){this.X=p("x",b),this.Y=p("y",A),this.Z=p("z",w,!0),this.T=p("t",L),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof d)throw new Error("extended point not allowed");let{x:A,y:w}=b||{};return p("x",A),p("y",w),new d(A,w,ot,a(A*w))}static fromBytes(b,A=!1){let w=n.BYTES,{a:L,d:D}=s;b=so(xt(b,w,"point")),qt(A,"zip215");let O=so(b),k=b[w-1];O[w-1]=k&-129;let R=Ht(O),x=A?c:n.ORDER;or("point.y",R,ie,x);let T=a(R*R),N=a(T-ot),C=a(D*T-L),{isValid:g,value:m}=f(N,C);if(!g)throw new Error("bad point: invalid y coordinate");let y=(m&ot)===ot,v=(k&128)!==0;if(!A&&m===ie&&v)throw new Error("bad point: x=0 and x_0=1");return v!==y&&(m=a(-m)),d.fromAffine({x:m,y:R})}static fromHex(b,A=!1){return d.fromBytes(H("point",b),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,A=!0){return E.createCache(this,b),A||this.multiply(mo),this}assertValidity(){h(this)}equals(b){l(b);let{X:A,Y:w,Z:L}=this,{X:D,Y:O,Z:k}=b,R=a(A*k),x=a(D*L),T=a(w*k),N=a(O*L);return R===x&&T===N}is0(){return this.equals(d.ZERO)}negate(){return new d(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:b}=s,{X:A,Y:w,Z:L}=this,D=a(A*A),O=a(w*w),k=a(mo*a(L*L)),R=a(b*D),x=A+w,T=a(a(x*x)-D-O),N=R+O,C=N-k,g=R-O,m=a(T*C),y=a(N*g),v=a(T*g),B=a(C*N);return new d(m,y,B,v)}add(b){l(b);let{a:A,d:w}=s,{X:L,Y:D,Z:O,T:k}=this,{X:R,Y:x,Z:T,T:N}=b,C=a(L*R),g=a(D*x),m=a(k*w*N),y=a(O*T),v=a((L+D)*(R+x)-C-g),B=y-m,P=y+m,I=a(g-A*C),_=a(v*B),K=a(P*I),U=a(v*I),Y=a(B*P);return new d(_,K,Y,U)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=E.cached(this,b,L=>Ft(d,L));return Ft(d,[A,w])[0]}multiplyUnsafe(b,A=d.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===ie?d.ZERO:this.is0()||b===ot?this:E.unsafe(this,b,w=>Ft(d,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(b){return u(this,b)}clearCofactor(){return i===ot?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=b&ot?128:0,w}toHex(){return vt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(b){return Ft(d,b)}static msm(b,A){return Ue(d,o,b,A)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}d.BASE=new d(s.Gx,s.Gy,ot,a(s.Gx*s.Gy)),d.ZERO=new d(ie,ot,ot,ie),d.Fp=n,d.Fn=o;let E=new Ne(d,o.BITS);return d.BASE.precompute(8),d}var Gr=class{constructor(t){this.ep=t}static fromBytes(t){io()}static fromHex(t){io()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return vt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function _u(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');se(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||te,a=r.adjustScalarBytes||(x=>x),f=r.domain||((x,T,N)=>{if(qt(N,"phflag"),T.length||N)throw new Error("Contexts/pre-hash are not supported");return x});function p(x){return i.create(Ht(x))}function l(x){let T=w.secretKey;x=H("private key",x,T);let N=H("hashed private key",t(x),2*T),C=a(N.slice(0,T)),g=N.slice(T,2*T),m=p(C);return{head:C,prefix:g,scalar:m}}function u(x){let{head:T,prefix:N,scalar:C}=l(x),g=o.multiply(C),m=g.toBytes();return{head:T,prefix:N,scalar:C,point:g,pointBytes:m}}function h(x){return u(x).pointBytes}function d(x=Uint8Array.of(),...T){let N=ht(...T);return p(t(f(N,H("context",x),!!n)))}function E(x,T,N={}){x=H("message",x),n&&(x=n(x));let{prefix:C,scalar:g,pointBytes:m}=u(T),y=d(N.context,C,x),v=o.multiply(y).toBytes(),B=d(N.context,v,m,x),P=i.create(y+B*g);if(!i.isValid(P))throw new Error("sign failed: invalid s");let I=ht(v,i.toBytes(P));return xt(I,w.signature,"result")}let S={zip215:!0};function b(x,T,N,C=S){let{context:g,zip215:m}=C,y=w.signature;x=H("signature",x,y),T=H("message",T),N=H("publicKey",N,w.publicKey),m!==void 0&&qt(m,"zip215"),n&&(T=n(T));let v=y/2,B=x.subarray(0,v),P=Ht(x.subarray(v,y)),I,_,K;try{I=e.fromBytes(N,m),_=e.fromBytes(B,m),K=o.multiplyUnsafe(P)}catch{return!1}if(!m&&I.isSmallOrder())return!1;let U=d(g,_.toBytes(),I.toBytes(),T);return _.add(I.multiplyUnsafe(U)).subtract(K).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function L(x=c(w.seed)){return xt(x,w.seed,"seed")}function D(x){let T=R.randomSecretKey(x);return{secretKey:T,publicKey:h(T)}}function O(x){return kt(x)&&x.length===i.BYTES}function k(x,T){try{return!!e.fromBytes(x,T)}catch{return!1}}let R={getExtendedPublicKey:u,randomSecretKey:L,isValidSecretKey:O,isValidPublicKey:k,toMontgomery(x){let{y:T}=e.fromBytes(x),N=w.publicKey,C=N===32;if(!C&&N!==57)throw new Error("only defined for 25519 and 448");let g=C?s.div(ot+T,ot-T):s.div(T-ot,T+ot);return s.toBytes(g)},toMontgomeryPriv(x){let T=w.secretKey;xt(x,T);let N=t(x.subarray(0,T));return a(N).subarray(0,T)},randomPrivateKey:L,precompute(x=8,T=e.BASE){return T.precompute(x,!1)}};return Object.freeze({keygen:D,getPublicKey:h,sign:E,verify:b,utils:R,Point:e,lengths:w})}function Lu(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=Et(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function Tu(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function _i(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=Lu(e),s=Iu(t,r),i=_u(s,n,o);return Tu(e,i)}var Cu=BigInt(0),zt=BigInt(1),Li=BigInt(2),td=BigInt(3),Pu=BigInt(5),Du=BigInt(8),ke=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ar={p:ke,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Du,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Ku(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ke,c=e*e%s*e%s,a=G(c,Li,s)*c%s,f=G(a,zt,s)*e%s,p=G(f,Pu,s)*f%s,l=G(p,t,s)*p%s,u=G(l,r,s)*l%s,h=G(u,n,s)*u%s,d=G(h,o,s)*h%s,E=G(d,o,s)*h%s,S=G(E,t,s)*p%s;return{pow_p_5_8:G(S,Li,s)*e%s,b2:c}}function Ru(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var yo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function wo(e,t){let r=ke,n=J(t*t*t,r),o=J(n*n*t,r),s=Ku(e*o).pow_p_5_8,i=J(e*n*s,r),c=J(t*i*i,r),a=i,f=J(i*yo,r),p=c===e,l=c===J(-e,r),u=c===J(-e*yo,r);return p&&(i=a),(l||u)&&(i=f),Vt(i,r)&&(i=J(-i,r)),{isValid:p||l,value:i}}var ae=Et(ar.p,{isLE:!0}),Nu=Et(ar.n,{isLE:!0}),Uu={...ar,Fp:ae,hash:ii,adjustScalarBytes:Ru,uvRatio:wo},Gt=_i(Uu);var bo=yo,ku=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Ou=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Mu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),qu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ti=e=>wo(zt,e),Hu=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),go=e=>Gt.Point.Fp.create(Ht(e)&Hu);function Ci(e){let{d:t}=ar,r=ke,n=b=>ae.create(b),o=n(bo*e*e),s=n((o+zt)*Mu),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:f}=wo(s,c),p=n(f*e);Vt(p,r)||(p=n(-p)),a||(f=p),a||(i=o);let l=n(i*(o-zt)*qu-c),u=f*f,h=n((f+f)*c),d=n(l*ku),E=n(zt-u),S=n(zt+u);return new Gt.Point(n(h*S),n(E*d),n(d*S),n(h*E))}function Vu(e){wt(e,64);let t=go(e.subarray(0,32)),r=Ci(t),n=go(e.subarray(32,64)),o=Ci(n);return new Zt(r.add(o))}var Zt=class e extends Gr{constructor(t){super(t)}static fromAffine(t){return new e(Gt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Vu(H("ristrettoHash",t,64))}static fromBytes(t){wt(t,32);let{a:r,d:n}=ar,o=ke,s=L=>ae.create(L),i=go(t);if(!ci(ae.toBytes(i),t)||Vt(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(zt+r*c),f=s(zt-r*c),p=s(a*a),l=s(f*f),u=s(r*n*p-l),{isValid:h,value:d}=Ti(s(u*l)),E=s(d*f),S=s(d*E*u),b=s((i+i)*E);Vt(b,o)&&(b=s(-b));let A=s(a*S),w=s(b*A);if(!h||Vt(w,o)||A===Cu)throw new Error("invalid ristretto255 encoding 2");return new e(new Gt.Point(b,A,zt,w))}static fromHex(t){return e.fromBytes(H("ristrettoHex",t,32))}static msm(t,r){return Ue(e,Gt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=ke,i=S=>ae.create(S),c=i(i(n+r)*i(n-r)),a=i(t*r),f=i(a*a),{value:p}=Ti(i(c*f)),l=i(p*c),u=i(p*a),h=i(l*u*o),d;if(Vt(o*h,s)){let S=i(r*bo),b=i(t*bo);t=S,r=b,d=i(l*Ou)}else d=u;Vt(t*h,s)&&(r=i(-r));let E=i((n-r)*d);return Vt(E,s)&&(E=i(-E)),ae.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=f=>ae.create(f),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};Zt.BASE=new Zt(Gt.Point.BASE);Zt.ZERO=new Zt(Gt.Point.ZERO);Zt.Fp=ae;Zt.Fn=Nu;var cr=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 Pi={get(e=globalThis){let t=e.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 At=Pi;var jr=32;var xo,Fu=(async()=>{try{return await At.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function zu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await At.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await At.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Gu(e,t,r){return Gt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Di(e,t,r){return xo==null&&(xo=await Fu),xo?zu(e,t,r):Gu(e,t,r)}function Yr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Xr=class{type="Ed25519";raw;constructor(t){this.raw=Eo(t,jr)}toMultihash(){return It.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Di(this.raw,r,t);return Yr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function So(e){return e=Eo(e,jr),new Xr(e)}function Eo(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Z(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var ju=Math.pow(2,7),Yu=Math.pow(2,14),Xu=Math.pow(2,21),vo=Math.pow(2,28),Ao=Math.pow(2,35),Bo=Math.pow(2,42),Io=Math.pow(2,49),q=128,ut=127;function Lt(e){if(e<ju)return 1;if(e<Yu)return 2;if(e<Xu)return 3;if(e<vo)return 4;if(e<Ao)return 5;if(e<Bo)return 6;if(e<Io)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function _o(e,t,r=0){switch(Lt(e)){case 8:t[r++]=e&255|q,e/=128;case 7:t[r++]=e&255|q,e/=128;case 6:t[r++]=e&255|q,e/=128;case 5:t[r++]=e&255|q,e/=128;case 4:t[r++]=e&255|q,e>>>=7;case 3:t[r++]=e&255|q,e>>>=7;case 2:t[r++]=e&255|q,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function $u(e,t,r=0){switch(Lt(e)){case 8:t.set(r++,e&255|q),e/=128;case 7:t.set(r++,e&255|q),e/=128;case 6:t.set(r++,e&255|q),e/=128;case 5:t.set(r++,e&255|q),e/=128;case 4:t.set(r++,e&255|q),e>>>=7;case 3:t.set(r++,e&255|q),e>>>=7;case 2:t.set(r++,e&255|q),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Lo(e,t){let r=e[t],n=0;if(n+=r&ut,r<q||(r=e[t+1],n+=(r&ut)<<7,r<q)||(r=e[t+2],n+=(r&ut)<<14,r<q)||(r=e[t+3],n+=(r&ut)<<21,r<q)||(r=e[t+4],n+=(r&ut)*vo,r<q)||(r=e[t+5],n+=(r&ut)*Ao,r<q)||(r=e[t+6],n+=(r&ut)*Bo,r<q)||(r=e[t+7],n+=(r&ut)*Io,r<q))return n;throw new RangeError("Could not decode varint")}function Wu(e,t){let r=e.get(t),n=0;if(n+=r&ut,r<q||(r=e.get(t+1),n+=(r&ut)<<7,r<q)||(r=e.get(t+2),n+=(r&ut)<<14,r<q)||(r=e.get(t+3),n+=(r&ut)<<21,r<q)||(r=e.get(t+4),n+=(r&ut)*vo,r<q)||(r=e.get(t+5),n+=(r&ut)*Ao,r<q)||(r=e.get(t+6),n+=(r&ut)*Bo,r<q)||(r=e.get(t+7),n+=(r&ut)*Io,r<q))return n;throw new RangeError("Could not decode varint")}function Ri(e,t,r=0){return t==null&&(t=ct(Lt(e))),t instanceof Uint8Array?_o(e,t,r):$u(e,t,r)}function Ni(e,t=0){return e instanceof Uint8Array?Lo(e,t):Wu(e,t)}var To=new Float32Array([-0]),ce=new Uint8Array(To.buffer);function ki(e,t,r){To[0]=e,t[r]=ce[0],t[r+1]=ce[1],t[r+2]=ce[2],t[r+3]=ce[3]}function Oi(e,t){return ce[0]=e[t],ce[1]=e[t+1],ce[2]=e[t+2],ce[3]=e[t+3],To[0]}var Co=new Float64Array([-0]),ft=new Uint8Array(Co.buffer);function Mi(e,t,r){Co[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function qi(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],Co[0]}var Ju=BigInt(Number.MAX_SAFE_INTEGER),Qu=BigInt(Number.MIN_SAFE_INTEGER),St=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ge;if(t<Ju&&t>Qu)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Hi&&(o=0n,++n>Hi&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ge}},ge=new St(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var Hi=4294967296n;function Vi(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Fi(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[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 Po(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Tt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function $r(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Do=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,Tt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Tt(this,4);return $r(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return $r(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=Oi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=qi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Tt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Fi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new St(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Tt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Tt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Tt(this,8);let t=$r(this.buf,this.pos+=4),r=$r(this.buf,this.pos+=4);return new St(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Lo(this.buf,this.pos);return this.pos+=Lt(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 Ko(e){return new Do(e instanceof Uint8Array?e:e.subarray())}function Wr(e,t,r){let n=Ko(e);return t.decode(n,void 0,r)}function Ro(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ct(i);o+i>t&&(n=ct(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var we=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function No(){}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}},tf=Ro();function ef(e){return globalThis.Buffer!=null?ct(e):tf(e)}var fr=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(No,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new we(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Oo((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,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=St.fromBigInt(t);return this._push(Jr,r.length(),r)}uint64Number(t){return this._push(_o,Lt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=St.fromBigInt(t).zzEncode();return this._push(Jr,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push(Jr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Uo,1,t?1:0)}fixed32(t){return this._push(ur,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(ur,4,r.lo)._push(ur,4,r.hi)}fixed64Number(t){let r=St.fromNumber(t);return this._push(ur,4,r.lo)._push(ur,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ki,4,t)}double(t){return this._push(Mi,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Uo,1,0):this.uint32(r)._push(nf,r,t)}string(t){let r=Vi(t);return r!==0?this.uint32(r)._push(Po,r,t):this._push(Uo,1,0)}fork(){return this.states=new ko(this),this.head=this.tail=new we(No,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 we(No,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=ef(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Uo(e,t,r){t[r]=e&255}function rf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Oo=class extends we{next;constructor(t,r){super(rf,t,r),this.next=void 0}};function Jr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function ur(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function nf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(fr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(of,t,e),this},fr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(sf,t,e),this});function of(e,t,r){t.set(e,r)}function sf(e,t,r){e.length<40?Po(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(F(e),r)}function Mo(){return new fr}function Qr(e,t){let r=Mo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Oe;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Oe||(Oe={}));function tn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function qo(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return tn("enum",Oe.VARINT,r,n)}function en(e,t){return tn("message",Oe.LENGTH_DELIMITED,e,t)}var tt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(tt||(tt={}));var Ho;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ho||(Ho={}));(function(e){e.codec=()=>qo(Ho)})(tt||(tt={}));var Pt;(function(e){let t;e.codec=()=>(t==null&&(t=en((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),tt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Qr(r,e.codec()),e.decode=(r,n)=>Wr(r,e.codec(),n)})(Pt||(Pt={}));var Vo;(function(e){let t;e.codec=()=>(t==null&&(t=en((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),tt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Qr(r,e.codec()),e.decode=(r,n)=>Wr(r,e.codec(),n)})(Vo||(Vo={}));function rn(e){if(isNaN(e)||e<=0)throw new Z("random bytes length must be a Number bigger than 0");return te(e)}var hr={};yt(hr,{MAX_RSA_KEY_SIZE:()=>Fo,generateRSAKeyPair:()=>Xi,jwkToJWKKeyPair:()=>$i,jwkToPkcs1:()=>ff,jwkToPkix:()=>jo,jwkToRSAPrivateKey:()=>Wo,pkcs1MessageToJwk:()=>Go,pkcs1MessageToRSAPrivateKey:()=>Yo,pkcs1ToJwk:()=>uf,pkcs1ToRSAPrivateKey:()=>Yi,pkixMessageToJwk:()=>Zo,pkixMessageToRSAPublicKey:()=>$o,pkixToJwk:()=>lf,pkixToRSAPublicKey:()=>Xo});var nn=qr;var Me=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=hr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){return ji(this.jwk,r,t,n)}},lr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=hr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}sign(t,r){return Zi(this.jwk,t,r)}};var Fo=8192,zo=18,af=1062,cf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function uf(e){let t=Rt(e);return Go(t)}function Go(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function ff(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new Z("JWK was missing components");return Qt([gt(Uint8Array.from([0])),gt(F(e.n,"base64url")),gt(F(e.e,"base64url")),gt(F(e.d,"base64url")),gt(F(e.p,"base64url")),gt(F(e.q,"base64url")),gt(F(e.dp,"base64url")),gt(F(e.dq,"base64url")),gt(F(e.qi,"base64url"))]).subarray()}function lf(e){let t=Rt(e,{offset:0});return Zo(t)}function Zo(e){let t=Rt(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function jo(e){if(e.n==null||e.e==null)throw new Z("JWK was missing components");return Qt([cf,Nr(Qt([gt(F(e.n,"base64url")),gt(F(e.e,"base64url"))]))]).subarray()}function Yi(e){let t=Rt(e);return Yo(t)}function Yo(e){let t=Go(e);return Wo(t)}function Xo(e,t){if(e.byteLength>=af)throw new Se("Key size is too large");let r=Rt(e,{offset:0});return $o(r,e,t)}function $o(e,t,r){let n=Zo(e);if(r==null){let o=nn(Pt.encode({Type:tt.RSA,Data:t}));r=Bt(zo,o)}return new Me(n,r)}function Wo(e){if(Ji(e)>Fo)throw new Z("Key size is too large");let t=$i(e),r=nn(Pt.encode({Type:tt.RSA,Data:jo(t.publicKey)})),n=Bt(zo,r);return new lr(t.privateKey,new Me(t.publicKey,n))}async function Xi(e){if(e>Fo)throw new Z("Key size is too large");let t=await Wi(e),r=nn(Pt.encode({Type:tt.RSA,Data:jo(t.publicKey)})),n=Bt(zo,r);return new lr(t.privateKey,new Me(t.publicKey,n))}function $i(e){if(e==null)throw new Z("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Wi(e,t){let r=await At.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await hf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Zi(e,t,r){let n=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function ji(e,t,r,n){let o=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function hf(e,t){if(e.privateKey==null||e.publicKey==null)throw new Z("Private and public key are required");let r=await Promise.all([At.get().subtle.exportKey("jwk",e.privateKey),At.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Ji(e){if(e.kty!=="RSA")throw new Z("invalid key type");if(e.n==null)throw new Z("invalid key modulus");return F(e.n,"base64url").length*8}var on=class extends Ce{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Ur(t);let n=Qe(r);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),Ot(s)}update(t){return Pe(this),this.iHash.update(t),this}digestInto(t){Pe(this),wt(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:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Jo=(e,t,r)=>new on(e,t).update(r).digest();Jo.create=(e,t)=>new on(e,t);var Qi=(e,t)=>(e+(e>=0?t:-t)/ta)/t;function df(e,t,r){let[[n,o],[s,i]]=t,c=Qi(i*e,r),a=Qi(-o*e,r),f=e-c*n-a*s,p=-c*o-a*i,l=f<Yt,u=p<Yt;l&&(f=-f),u&&(p=-p);let h=oe(Math.ceil(Vr(r)/2))+He;if(f<Yt||f>=h||p<Yt||p>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:u,k2:p}}function ts(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Qo(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return qt(r.lowS,"lowS"),qt(r.prehash,"prehash"),r.format!==void 0&&ts(r.format),r}var es=class extends Error{constructor(t=""){super(t)}},jt={Err:es,_tlv:{encode:(e,t)=>{let{Err:r}=jt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=nr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?nr(o.length/2|128):"";return nr(e)+s+o+t},decode(e,t){let{Err:r}=jt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+a);if(f.length!==a)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let p of f)i=i<<8|p;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=jt;if(e<Yt)throw new t("integer: negative integers are not allowed");let r=nr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=jt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return De(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=jt,o=H("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:f,l:p}=n.decode(2,a);if(p.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=jt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Yt=BigInt(0),He=BigInt(1),ta=BigInt(2),sn=BigInt(3),pf=BigInt(4);function qe(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=H("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function mf(e,t={}){let r=zr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;se(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=ra(n,o);function p(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(C,g,m){let{x:y,y:v}=g.toAffine(),B=n.toBytes(y);if(qt(m,"isCompressed"),m){p();let P=!n.isOdd(v);return ht(ea(P),B)}else return ht(Uint8Array.of(4),B,n.toBytes(v))}function u(C){xt(C,void 0,"Point");let{publicKey:g,publicKeyUncompressed:m}=f,y=C.length,v=C[0],B=C.subarray(1);if(y===g&&(v===2||v===3)){let P=n.fromBytes(B);if(!n.isValid(P))throw new Error("bad point: is not on curve, wrong x");let I=E(P),_;try{_=n.sqrt(I)}catch(Y){let V=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}p();let K=n.isOdd(_);return(v&1)===1!==K&&(_=n.neg(_)),{x:P,y:_}}else if(y===m&&v===4){let P=n.BYTES,I=n.fromBytes(B.subarray(0,P)),_=n.fromBytes(B.subarray(P,P*2));if(!S(I,_))throw new Error("bad point: is not on curve");return{x:I,y:_}}else throw new Error(`bad point: got length ${y}, expected compressed=${g} or uncompressed=${m}`)}let h=t.toBytes||l,d=t.fromBytes||u;function E(C){let g=n.sqr(C),m=n.mul(g,C);return n.add(n.add(m,n.mul(C,s.a)),s.b)}function S(C,g){let m=n.sqr(g),y=E(C);return n.eql(m,y)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,sn),pf),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,A)))throw new Error("bad curve params: a or b");function w(C,g,m=!1){if(!n.isValid(g)||m&&n.is0(g))throw new Error(`bad point coordinate ${C}`);return g}function L(C){if(!(C instanceof x))throw new Error("ProjectivePoint expected")}function D(C){if(!a||!a.basises)throw new Error("no endo");return df(C,a.basises,o.ORDER)}let O=Ke((C,g)=>{let{X:m,Y:y,Z:v}=C;if(n.eql(v,n.ONE))return{x:m,y};let B=C.is0();g==null&&(g=B?n.ONE:n.inv(v));let P=n.mul(m,g),I=n.mul(y,g),_=n.mul(v,g);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:P,y:I}}),k=Ke(C=>{if(C.is0()){if(t.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:m}=C.toAffine();if(!n.isValid(g)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!S(g,m))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(C,g,m,y,v){return m=new x(n.mul(m.X,C),m.Y,m.Z),g=ir(y,g),m=ir(v,m),g.add(m)}class x{constructor(g,m,y){this.X=w("x",g),this.Y=w("y",m,!0),this.Z=w("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:m,y}=g||{};if(!g||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(g instanceof x)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?x.ZERO:new x(m,y,n.ONE)}static fromBytes(g){let m=x.fromAffine(d(xt(g,void 0,"point")));return m.assertValidity(),m}static fromHex(g){return x.fromBytes(H("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,m=!0){return N.createCache(this,g),m||this.multiply(sn),this}assertValidity(){k(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){L(g);let{X:m,Y:y,Z:v}=this,{X:B,Y:P,Z:I}=g,_=n.eql(n.mul(m,I),n.mul(B,v)),K=n.eql(n.mul(y,I),n.mul(P,v));return _&&K}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:m}=s,y=n.mul(m,sn),{X:v,Y:B,Z:P}=this,I=n.ZERO,_=n.ZERO,K=n.ZERO,U=n.mul(v,v),Y=n.mul(B,B),V=n.mul(P,P),M=n.mul(v,B);return M=n.add(M,M),K=n.mul(v,P),K=n.add(K,K),I=n.mul(g,K),_=n.mul(y,V),_=n.add(I,_),I=n.sub(Y,_),_=n.add(Y,_),_=n.mul(I,_),I=n.mul(M,I),K=n.mul(y,K),V=n.mul(g,V),M=n.sub(U,V),M=n.mul(g,M),M=n.add(M,K),K=n.add(U,U),U=n.add(K,U),U=n.add(U,V),U=n.mul(U,M),_=n.add(_,U),V=n.mul(B,P),V=n.add(V,V),U=n.mul(V,M),I=n.sub(I,U),K=n.mul(V,Y),K=n.add(K,K),K=n.add(K,K),new x(I,_,K)}add(g){L(g);let{X:m,Y:y,Z:v}=this,{X:B,Y:P,Z:I}=g,_=n.ZERO,K=n.ZERO,U=n.ZERO,Y=s.a,V=n.mul(s.b,sn),M=n.mul(m,B),X=n.mul(y,P),et=n.mul(v,I),mt=n.add(m,y),$=n.add(B,P);mt=n.mul(mt,$),$=n.add(M,X),mt=n.sub(mt,$),$=n.add(m,v);let it=n.add(B,I);return $=n.mul($,it),it=n.add(M,et),$=n.sub($,it),it=n.add(y,v),_=n.add(P,I),it=n.mul(it,_),_=n.add(X,et),it=n.sub(it,_),U=n.mul(Y,$),_=n.mul(V,et),U=n.add(_,U),_=n.sub(X,U),U=n.add(X,U),K=n.mul(_,U),X=n.add(M,M),X=n.add(X,M),et=n.mul(Y,et),$=n.mul(V,$),X=n.add(X,et),et=n.sub(M,et),et=n.mul(Y,et),$=n.add($,et),M=n.mul(X,$),K=n.add(K,M),M=n.mul(it,$),_=n.mul(mt,_),_=n.sub(_,M),M=n.mul(mt,X),U=n.mul(it,U),U=n.add(U,M),new x(_,K,U)}subtract(g){return this.add(g.negate())}is0(){return this.equals(x.ZERO)}multiply(g){let{endo:m}=t;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let y,v,B=P=>N.cached(this,P,I=>Ft(x,I));if(m){let{k1neg:P,k1:I,k2neg:_,k2:K}=D(g),{p:U,f:Y}=B(I),{p:V,f:M}=B(K);v=Y.add(M),y=R(m.beta,U,V,P,_)}else{let{p:P,f:I}=B(g);y=P,v=I}return Ft(x,[y,v])[0]}multiplyUnsafe(g){let{endo:m}=t,y=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===Yt||y.is0())return x.ZERO;if(g===He)return y;if(N.hasCache(this))return this.multiply(g);if(m){let{k1neg:v,k1:B,k2neg:P,k2:I}=D(g),{p1:_,p2:K}=Ii(x,y,B,I);return R(m.beta,_,K,v,P)}else return N.unsafe(y,g)}multiplyAndAddUnsafe(g,m,y){let v=this.multiplyUnsafe(m).add(g.multiplyUnsafe(y));return v.is0()?void 0:v}toAffine(g){return O(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return i===He?!0:g?g(x,this):N.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===He?this:g?g(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return qt(g,"isCompressed"),this.assertValidity(),h(x,this,g)}toHex(g=!0){return vt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return Ft(x,g)}static msm(g,m){return Ue(x,o,g,m)}static fromPrivateKey(g){return x.BASE.multiply(qe(o,g))}}x.BASE=new x(s.Gx,s.Gy,n.ONE),x.ZERO=new x(n.ZERO,n.ONE,n.ZERO),x.Fp=n,x.Fn=o;let T=o.BITS,N=new Ne(x,t.endo?Math.ceil(T/2):T);return x.BASE.precompute(8),x}function ea(e){return Uint8Array.of(e?2:3)}function ra(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function yf(e,t={}){let{Fn:r}=e,n=t.randomBytes||te,o=Object.assign(ra(e.Fp,r),{seed:uo(r.ORDER)});function s(h){try{return!!qe(r,h)}catch{return!1}}function i(h,d){let{publicKey:E,publicKeyUncompressed:S}=o;try{let b=h.length;return d===!0&&b!==E||d===!1&&b!==S?!1:!!e.fromBytes(h)}catch{return!1}}function c(h=n(o.seed)){return fo(xt(h,o.seed,"seed"),r.ORDER)}function a(h,d=!0){return e.BASE.multiply(qe(r,h)).toBytes(d)}function f(h){let d=c(h);return{secretKey:d,publicKey:a(d)}}function p(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let{secretKey:d,publicKey:E,publicKeyUncompressed:S}=o;if(r.allowedLengths||d===E)return;let b=H("key",h).length;return b===E||b===S}function l(h,d,E=!0){if(p(h)===!0)throw new Error("first arg must be private key");if(p(d)===!1)throw new Error("second arg must be public key");let S=qe(r,h);return e.fromHex(d).multiply(S).toBytes(E)}return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:f,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:h=>qe(r,h),precompute(h=8,d=e.BASE){return d.precompute(h,!1)}},lengths:o})}function bf(e,t,r={}){Ur(t),se(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||te,o=r.hmac||((m,...y)=>Jo(t,m,ht(...y))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:f,getPublicKey:p,getSharedSecret:l,utils:u,lengths:h}=yf(e,r),d={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function S(m){let y=c>>He;return m>y}function b(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function A(m,y){ts(y);let v=h.signature,B=y==="compact"?v:y==="recovered"?v+1:void 0;return xt(m,B,`${y} signature`)}class w{constructor(y,v,B){this.r=b("r",y),this.s=b("s",v),B!=null&&(this.recovery=B),Object.freeze(this)}static fromBytes(y,v=E){A(y,v);let B;if(v==="der"){let{r:K,s:U}=jt.toSig(xt(y));return new w(K,U)}v==="recovered"&&(B=y[0],v="compact",y=y.subarray(1));let P=i.BYTES,I=y.subarray(0,P),_=y.subarray(P,P*2);return new w(i.fromBytes(I),i.fromBytes(_),B)}static fromHex(y,v){return this.fromBytes(de(y),v)}addRecoveryBit(y){return new w(this.r,this.s,y)}recoverPublicKey(y){let v=s.ORDER,{r:B,s:P,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(c*ta<v&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");let K=I===2||I===3?B+c:B;if(!s.isValid(K))throw new Error("recovery id 2 or 3 invalid");let U=s.toBytes(K),Y=e.fromBytes(ht(ea((I&1)===0),U)),V=i.inv(K),M=D(H("msgHash",y)),X=i.create(-M*V),et=i.create(P*V),mt=e.BASE.multiplyUnsafe(X).add(Y.multiplyUnsafe(et));if(mt.is0())throw new Error("point at infinify");return mt.assertValidity(),mt}hasHighS(){return S(this.s)}toBytes(y=E){if(ts(y),y==="der")return de(jt.hexFromSig(this));let v=i.toBytes(this.r),B=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ht(Uint8Array.of(this.recovery),v,B)}return ht(v,B)}toHex(y){return vt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return w.fromBytes(H("sig",y),"compact")}static fromDER(y){return w.fromBytes(H("sig",y),"der")}normalizeS(){return this.hasHighS()?new w(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return vt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return vt(this.toBytes("compact"))}}let L=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let v=De(y),B=y.length*8-a;return B>0?v>>BigInt(B):v},D=r.bits2int_modN||function(y){return i.create(L(y))},O=oe(a);function k(m){return or("num < 2^"+a,m,Yt,O),i.toBytes(m)}function R(m,y){return xt(m,void 0,"message"),y?xt(t(m),void 0,"prehashed message"):m}function x(m,y,v){if(["recovered","canonical"].some(X=>X in v))throw new Error("sign() legacy options not supported");let{lowS:B,prehash:P,extraEntropy:I}=Qo(v,d);m=R(m,P);let _=D(m),K=qe(i,y),U=[k(K),k(_)];if(I!=null&&I!==!1){let X=I===!0?n(h.secretKey):I;U.push(H("extraEntropy",X))}let Y=ht(...U),V=_;function M(X){let et=L(X);if(!i.isValidNot0(et))return;let mt=i.inv(et),$=e.BASE.multiply(et).toAffine(),it=i.create($.x);if(it===Yt)return;let Lr=i.create(mt*i.create(V+it*K));if(Lr===Yt)return;let bs=($.x===it?0:2)|Number($.y&He),gs=Lr;return B&&S(Lr)&&(gs=i.neg(Lr),bs^=1),new w(it,gs,bs)}return{seed:Y,k2sig:M}}function T(m,y,v={}){m=H("message",m);let{seed:B,k2sig:P}=x(m,y,v);return fi(t.outputLen,i.BYTES,o)(B,P)}function N(m){let y,v=typeof m=="string"||kt(m),B=!v&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!v&&!B)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(B)y=new w(m.r,m.s);else if(v){try{y=w.fromBytes(H("sig",m),"der")}catch(P){if(!(P instanceof jt.Err))throw P}if(!y)try{y=w.fromBytes(H("sig",m),"compact")}catch{return!1}}return y||!1}function C(m,y,v,B={}){let{lowS:P,prehash:I,format:_}=Qo(B,d);if(v=H("publicKey",v),y=R(H("message",y),I),"strict"in B)throw new Error("options.strict was renamed to lowS");let K=_===void 0?N(m):w.fromBytes(H("sig",m),_);if(K===!1)return!1;try{let U=e.fromBytes(v);if(P&&K.hasHighS())return!1;let{r:Y,s:V}=K,M=D(y),X=i.inv(V),et=i.create(M*X),mt=i.create(Y*X),$=e.BASE.multiplyUnsafe(et).add(U.multiplyUnsafe(mt));return $.is0()?!1:i.create($.x)===Y}catch{return!1}}function g(m,y,v={}){let{prehash:B}=Qo(v,d);return y=R(y,B),w.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:f,getPublicKey:p,getSharedSecret:l,utils:u,lengths:h,Point:e,sign:T,verify:C,recoverPublicKey:g,Signature:w,hash:t})}function gf(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=Et(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function wf(e){let{CURVE:t,curveOpts:r}=gf(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function xf(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Fr(r.Fn.ORDER,r.Fn.BITS))})}function na(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=wf(e),s=mf(t,r),i=bf(s,n,o);return xf(e,i)}function oa(e,t){let r=n=>na({...e,hash:n});return{...r(t),create:r}}var ns={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ef={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var sa=BigInt(2);function Sf(e){let t=ns.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),f=e*e*e%t,p=f*f*e%t,l=G(p,r,t)*p%t,u=G(l,r,t)*p%t,h=G(u,sa,t)*f%t,d=G(h,o,t)*h%t,E=G(d,s,t)*d%t,S=G(E,c,t)*E%t,b=G(S,a,t)*S%t,A=G(b,c,t)*E%t,w=G(A,r,t)*p%t,L=G(w,i,t)*d%t,D=G(L,n,t)*f%t,O=G(D,sa,t);if(!rs.eql(rs.sqr(O),e))throw new Error("Cannot find square root");return O}var rs=Et(ns.p,{sqrt:Sf}),Ve=oa({...ns,Fp:rs,lowS:!0,endo:Ef},qr);function ia(e,t,r,n){let o=le.digest(r instanceof Uint8Array?r:r.subarray());if(Yr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ve.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new cr(String(s))});try{return n?.signal?.throwIfAborted(),Ve.verify(t,o.digest,e)}catch(s){throw new cr(String(s))}}var an=class{type="secp256k1";raw;_key;constructor(t){this._key=ca(t),this.raw=aa(this._key)}toMultihash(){return It.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){return ia(this._key,r,t,n)}};function os(e){return new an(e)}function aa(e){return Ve.ProjectivePoint.fromHex(e).toRawBytes(!0)}function ca(e){try{return Ve.ProjectivePoint.fromHex(e),e}catch(t){throw new Se(String(t))}}function ss(e,t){let{Type:r,Data:n}=Pt.decode(e),o=n??new Uint8Array;switch(r){case tt.RSA:return Xo(o,t);case tt.Ed25519:return So(o);case tt.secp256k1:return os(o);case tt.ECDSA:return Xn(o);default:throw new ue}}function ua(e){let{Type:t,Data:r}=Pt.decode(e.digest),n=r??new Uint8Array;switch(t){case tt.Ed25519:return So(n);case tt.secp256k1:return os(n);case tt.ECDSA:return Xn(n);default:throw new ue}}function Nt(e){return Pt.encode({Type:tt[e.type],Data:e.raw})}var fa=Symbol.for("nodejs.util.inspect.custom"),vf=114,dr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[En]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(vf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[fa](){return`PeerId(${this.toString()})`}},pr=class extends dr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},mr=class extends dr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},yr=class extends dr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Af=2336,cn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=It.digest(F(this.url))}[fa](){return`PeerId(${this.url})`}[En]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Af,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function is(e){if(e.type==="Ed25519")return new mr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new yr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new pr({multihash:e.toCID().multihash,publicKey:e});throw new ue}function la(e){return is(e.publicKey)}function br(e){if(If(e))return new pr({multihash:e});if(Bf(e))try{let t=ua(e);if(t.type==="Ed25519")return new mr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new yr({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new cn(new URL(r))}throw new Cr("Supplied PeerID Multihash is invalid")}function Bf(e){return e.code===It.code}function If(e){return e.code===le.code}function xe(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function un(e){let t=Wt(j.decode(`z${e}`));return br(t)}var gr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return xe(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return xe(this.map.values(),t=>t.key)}values(){return xe(this.map.values(),t=>t.value)}get size(){return this.map.size}};var wr=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return xe(this.set.entries(),t=>{let r=un(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=un(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return xe(this.set.values(),t=>un(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function Xt(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}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}},Fe=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 r=this.head;this.head=r.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 r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var as=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ln(e={}){return _f(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function _f(e,t){t=t??{};let r=t.onEnd,n=new Fe,o,s,i,c=Xt(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((S,b)=>{s=A=>{s=null,n.push(A);try{S(e(n))}catch(w){b(w)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Xt()})}},f=S=>s!=null?s(S):(n.push(S),o),p=S=>(n=new Fe,s!=null?s({error:S}):(n.push({error:S}),o)),l=S=>{if(i)return o;if(t?.objectMode!==!0&&S?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:S})},u=S=>i?o:(i=!0,S!=null?p(S):f({done:!0})),h=()=>(n=new Fe,u(),{done:!0}),d=S=>(u(S),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:h,throw:d,push:l,end:u,get readableLength(){return n.size},onEmpty:async S=>{let b=S?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let A,w;b!=null&&(A=new Promise((L,D)=>{w=()=>{D(new as)},b.addEventListener("abort",w)}));try{await Promise.race([c.promise,A])}finally{w!=null&&b!=null&&b?.removeEventListener("abort",w)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(S){return E.throw(S),r!=null&&(r(S),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(S){return E.end(S),r!=null&&(r(S),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:S=>E.onEmpty(S)},o}var hn=class extends Error{type;code;constructor(t,r,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function ha(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new hn(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new hn(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([e,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var cs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Xt(),this.haveNext=Xt()}[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=Xt(),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,r){await this._push(t,r)}async end(t,r){t!=null?await this.throw(t):await this._push(void 0,r)}async _push(t,r){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=Xt(),await ha(this.readNext.promise,r?.signal,r)}};function da(){return new cs}function Lf(e){return e[Symbol.asyncIterator]!=null}async function Tf(e,t,r){try{await Promise.all(e.map(async n=>{for await(let o of n)await t.push(o,{signal:r}),r.throwIfAborted()})),await t.end(void 0,{signal:r})}catch(n){await t.end(n,{signal:r}).catch(()=>{})}}async function*Cf(e){let t=new AbortController,r=da();Tf(e,r,t.signal).catch(()=>{});try{yield*r}finally{t.abort()}}function*Pf(e){for(let t of e)yield*t}function Df(...e){let t=[];for(let r of e)Lf(r)||t.push(r);return t.length===e.length?Pf(t):Cf(e)}var pa=Df;function xr(e,...t){if(e==null)throw new Error("Empty pipeline");if(us(e)){let n=e;e=()=>n.source}else if(ya(e)||ma(e)){let n=e;e=()=>n}let r=[e,...t];if(r.length>1&&us(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)us(r[n])&&(r[n]=Rf(r[n]));return Kf(...r)}var Kf=(...e)=>{let t;for(;e.length>0;)t=e.shift()(t);return t},ma=e=>e?.[Symbol.asyncIterator]!=null,ya=e=>e?.[Symbol.iterator]!=null,us=e=>e==null?!1:e.sink!=null&&e.source!=null,Rf=e=>t=>{let r=e.sink(t);if(r?.then!=null){let n=ln({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=e.source;if(ma(s))o=async function*(){yield*s,n.end()};else if(ya(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return pa(n,o())}return e.source};var ls=Ma(ga(),1);var Sr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},hs=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},wa=e=>globalThis.DOMException===void 0?new hs(e):new DOMException(e),xa=e=>{let t=e.reason===void 0?wa("This operation was aborted."):e.reason;return t instanceof Error?t:wa(t)};function ds(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,f=new Promise((p,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:h}=t;h.aborted&&l(xa(h)),c=()=>{l(xa(h))},h.addEventListener("abort",c,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(p,l);return}let u=new Sr;i=s.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(h){l(h)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?p():o instanceof Error?l(o):(u.message=o??`Promise timed out after ${r} milliseconds`,l(u))},r),(async()=>{try{p(await e)}catch(h){l(h)}})()}).finally(()=>{f.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}function ps(e,t,r){let n=0,o=e.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;r(e[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var vr=class{#t=[];enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,id:r.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=r.priority){this.#t.push(n);return}let o=ps(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,r){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#t.length}};var Ar=class extends ls.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:vr,...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 r=this.#p-t;if(r<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},r)),!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 r=this.#e.dequeue();return r?(this.emit("active"),r(),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#B(t){return new Promise((r,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,r){this.#e.setPriority(t,r)}async add(t,r={}){return r.id??=(this.#w++).toString(),r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{r.signal?.throwIfAborted();let s=t({signal:r.signal});r.timeout&&(s=ds(Promise.resolve(s),{milliseconds:r.timeout})),r.signal&&(s=Promise.race([s,this.#B(r.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof Sr&&!r.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},r),this.emit("add"),this.#f()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}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,r){return new Promise(n=>{let o=()=>{r&&!r()||(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 Ea(e){if(e!=null){if(typeof e[Symbol.iterator]=="function")return e[Symbol.iterator]();if(typeof e[Symbol.asyncIterator]=="function")return e[Symbol.asyncIterator]();if(typeof e.next=="function")return e}throw new Error("argument is not an iterator or iterable")}function Sa(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}function va(e,t){let r=Ea(e).return?.();Sa(r)&&r.catch(n=>{t.error("could not cause iterator to return",n)})}var pn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ze=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},mn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Br=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function yn(e){return e[Symbol.asyncIterator]!=null}function Aa(e,t){if(e.byteLength>t)throw new ze("Message length too long")}var gn=e=>{let t=Lt(e),r=ct(t);return Ri(e,r),gn.bytes=t,r};gn.bytes=0;function wn(e,t){t=t??{};let r=t.lengthEncoder??gn,n=t?.maxDataLength??4194304;function*o(s){Aa(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return yn(e)?async function*(){for await(let s of e)yield*o(s)}():function*(){for(let s of e)yield*o(s)}()}wn.single=(e,t)=>{t=t??{};let r=t.lengthEncoder??gn,n=t?.maxDataLength??4194304;return Aa(e,n),new rt(r(e.byteLength),e)};var Ee;(function(e){e[e.LENGTH=0]="LENGTH",e[e.DATA=1]="DATA"})(Ee||(Ee={}));var ms=e=>{let t=Ni(e);return ms.bytes=Lt(t),t};ms.bytes=0;function Ir(e,t){let r=new rt,n=Ee.LENGTH,o=-1,s=t?.lengthDecoder??ms,i=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;r.byteLength>0;){if(n===Ee.LENGTH)try{if(o=s(r),o<0)throw new pn("Invalid message length");if(o>c)throw new ze("Message length too long");let f=s.bytes;r.consume(f),t?.onLength!=null&&t.onLength(o),n=Ee.DATA}catch(f){if(f instanceof RangeError){if(r.byteLength>i)throw new mn("Message length length too long");break}throw f}if(n===Ee.DATA){if(r.byteLength<o)break;let f=r.sublist(0,o);r.consume(o),t?.onData!=null&&t.onData(f),yield f,n=Ee.LENGTH}}}return yn(e)?async function*(){for await(let f of e)r.append(f),yield*a();if(r.byteLength>0)throw new Br("Unexpected end of input")}():function*(){for(let f of e)r.append(f),yield*a();if(r.byteLength>0)throw new Br("Unexpected end of input")}()}Ir.fromReader=(e,t)=>{let r=1,n=async function*(){for(;;)try{let{done:s,value:i}=await e.next(r);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{r=1}}();return Ir(n,{...t??{},onLength:s=>{r=s}})};var xn=class extends ve{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,r){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=r.id,this.protocol=r.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 r=this.id.toString();throw new Error("No writable connection to "+r)}this.outboundStream.push(t instanceof Uint8Array?new rt(t):t)}attachInboundStream(t,r){let n=()=>{va(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=xr(this._rawInboundStream,o=>Ir(o,r)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let r=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"))}}),xr(this.outboundStream,n=>wn(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),r==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 Ba(){return BigInt(`0x${z(rn(8),"base16")}`)}var Ia=(e,t)=>{let r=F(t.toString(16).padStart(16,"0"),"base16"),n=Nt(e),o=new Uint8Array(n.byteLength+r.length);return o.set(n,0),o.set(r,n.byteLength),o},_a=e=>le.encode(e);var La=function(e){return Array.isArray(e)?e:[e]},Mf=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=br(Wt(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return is(ss(r)).equals(t)}return!1},Ta=async e=>{if(e.from==null)throw new Q("RPC message was missing from");if(!await Mf(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=br(Wt(e.from)),r=e.key??t.publicKey;if(r==null)throw new Q("RPC message was missing public key");return{type:"signed",from:t,topic:e.topic??"",sequenceNumber:Hf(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?ss(r):r}},_r=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:qf(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Nt(e.key):void 0}:{data:e.data,topic:e.topic},qf=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},Hf=e=>BigInt(`0x${z(e,"base16")}`);var Ca=F("libp2p-pubsub:");async function Pa(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:la(e)},o=fe([Ca,r(_r(n)).subarray()]);return n.signature=await e.sign(o),n.key=e.publicKey,n}async function Da(e,t){if(e.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(e.signature==null)throw new Error("Message must contain a signature to be verified");if(e.from==null)throw new Error("Message must contain a from property to be verified");let r=fe([Ca,t({..._r(e),signature:void 0,key:void 0}).subarray()]);return Vf(e).verify(r,e.signature)}function Vf(e){if(e.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(e.from==null)throw new Error("Could not get the public key from the originator id");if(e.key!=null)return e.key;if(e.from.publicKey!=null)return e.from.publicKey;throw new Error("Could not get the public key from the originator id")}var ys=class extends ve{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,r){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:c=10,maxInboundStreams:a=1,maxOutboundStreams:f=1}=r;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=La(n),this.enabled=r.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new gr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new Ar({concurrency:c}),this.maxInboundStreams=a,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 r={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,r))),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(r=>{t.unregister(r)}),await Promise.all(this.multicodecs.map(async r=>{await t.unhandle(r)})),this.log("stopping");for(let r of this.peers.values())r.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:r,connection:n}=t,o=n.remotePeer;if(r.protocol==null){r.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,r.protocol),i=s.attachInboundStream(r);this.processMessages(o,i,s).catch(c=>{this.log(c)})}_onPeerConnected(t,r){if(this.log("connected %p",t),r.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 r.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,r){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,r){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new xn(this.components,{id:t,protocol:r});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let r=this.peers.get(t);if(r!=null){r.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return r}}async processMessages(t,r,n){try{await xr(r,async o=>{for await(let s of o){let i=this.decodeRpc(s),c=[];for(let a of i.messages??[]){if(a.from==null||a.data==null||a.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}c.push({from:a.from,data:a.data,topic:a.topic,sequenceNumber:a.sequenceNumber??void 0,signature:a.signature??void 0,key:a.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(a=>({subscribe:!!a.subscribe,topic:a.topic??""})),messages:c}).catch(a=>{this.log(a)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,r,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:r.id,subscriptions:o.map(({topic:i,subscribe:c})=>({topic:`${i??""}`,subscribe:!!c}))}}))),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 c=await Ta(i);await this.processMessage(t,c)}catch(c){this.log.error(c)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,r){let n=r.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new wr,this.topics.set(n,o)),r.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,r){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,r)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(r.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:r})),await this.publishMessage(t,r)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new Q("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new Q("Need key when signature policy is StrictSign but it was missing");return Ia(t.key,t.sequenceNumber);case"StrictNoSign":return _a(t.data);default:throw new Q("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,r){let{messages:n,subscriptions:o,subscribe:s}=r;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(_r)})}sendRpc(t,r){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}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(r))}async validate(t,r){switch(this.globalSignaturePolicy){case"StrictNoSign":if(r.type!=="unsigned")throw new Q('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new Q("StrictNoSigning: signature should not be present");if(r.key!=null)throw new Q("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new Q("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new Q("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new Q("StrictSigning: Signing required and no sequenceNumber was present");if(!await Da(r,this.encodeMessage.bind(this)))throw new Q("StrictSigning: Invalid message signature");break;default:throw new Q("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(r.topic);if(o!=null){let s=await o(t,r);if(s===Ge.Reject||s===Ge.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Pa(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new Q("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Pr("not started yet");if(t==null)throw new Z("Topic is required");let r=this.topics.get(t.toString());return r==null?[]:Array.from(r.values())}async publish(t,r){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:r??new Uint8Array(0),sequenceNumber:Ba()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let 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 r of this.peers.keys())this.send(r,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let r=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,r),r){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 qa(Ff);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: