@libp2p/floodsub 10.1.45-cf9aab5c8 → 10.1.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PFloodsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PFloodsub=(()=>{var Ya=Object.create;var kr=Object.defineProperty;var $a=Object.getOwnPropertyDescriptor;var Xa=Object.getOwnPropertyNames;var ja=Object.getPrototypeOf,Wa=Object.prototype.hasOwnProperty;var Ja=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yt=(e,t)=>{for(var r in t)kr(e,r,{get:t[r],enumerable:!0})},Ds=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xa(t))!Wa.call(e,o)&&o!==r&&kr(e,o,{get:()=>t[o],enumerable:!(n=$a(t,o))||n.enumerable});return e};var Qa=(e,t,r)=>(r=e!=null?Ya(ja(e)):{},Ds(t||!e||!e.__esModule?kr(r,"default",{value:e,enumerable:!0}):r,e)),tc=e=>Ds(kr({},"__esModule",{value:!0}),e);var Pa=Ja((ey,xs)=>{"use strict";var Xf=Object.prototype.hasOwnProperty,pt="~";function Br(){}Object.create&&(Br.prototype=Object.create(null),new Br().__proto__||(pt=!1));function jf(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function Ca(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new jf(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 mn(e,t){--e._eventsCount===0?e._events=new Br:delete e._events[t]}function lt(){this._events=new Br,this._eventsCount=0}lt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)Xf.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 a=pt?pt+t:t;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,d,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,o),!0;case 5:return c.fn.call(c.context,r,n,o,s),!0;case 6:return c.fn.call(c.context,r,n,o,s,i),!0}for(l=1,d=new Array(u-1);l<u;l++)d[l-1]=arguments[l];c.fn.apply(c.context,d)}else{var f=c.length,h;for(l=0;l<f;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),u){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,r);break;case 3:c[l].fn.call(c[l].context,r,n);break;case 4:c[l].fn.call(c[l].context,r,n,o);break;default:if(!d)for(h=1,d=new Array(u-1);h<u;h++)d[h-1]=arguments[h];c[l].fn.apply(c[l].context,d)}}return!0};lt.prototype.on=function(t,r,n){return Ca(this,t,r,n,!1)};lt.prototype.once=function(t,r,n){return Ca(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 mn(this,s),this;var i=this._events[s];if(i.fn)i.fn===r&&(!o||i.once)&&(!n||i.context===n)&&mn(this,s);else{for(var a=0,c=[],u=i.length;a<u;a++)(i[a].fn!==r||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:mn(this,s)}return this};lt.prototype.removeAllListeners=function(t){var r;return t?(r=pt?pt+t:t,this._events[r]&&mn(this,r)):(this._events=new Br,this._eventsCount=0),this};lt.prototype.off=lt.prototype.removeListener;lt.prototype.addListener=lt.prototype.on;lt.prefixed=pt;lt.EventEmitter=lt;typeof xs<"u"&&(xs.exports=lt)});var ol={};yt(ol,{floodsub:()=>nl,multicodec:()=>Bs});var Cn=Symbol.for("@libp2p/peer-id");var je;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(je||(je={}));var Cs=Symbol.for("@libp2p/pubsub");var Z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},_e=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Rr=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 Nr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var de=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Le=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){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 Ps=Symbol.for("@libp2p/service-capabilities"),Ks=Symbol.for("@libp2p/service-dependencies");var Nn={};yt(Nn,{base58btc:()=>Y,base58flickr:()=>ac});var Cl=new Uint8Array(0);function ks(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Nt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Rs(e){return new TextEncoder().encode(e)}function Ns(e){return new TextDecoder().decode(e)}function ec(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 a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var E=0,S=0,b=0,A=p.length;b!==A&&p[b]===0;)b++,E++;for(var w=(A-b)*d+1>>>0,L=new Uint8Array(w);b!==A;){for(var P=p[b],M=0,U=w-1;(P!==0||M<S)&&U!==-1;U--,M++)P+=256*L[U]>>>0,L[U]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");S=M,b++}for(var k=w-S;k!==w&&L[k]===0;)k++;for(var x=c.repeat(E);k<w;++k)x+=e.charAt(L[k]);return x}function f(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var E=0;if(p[E]!==" "){for(var S=0,b=0;p[E]===c;)S++,E++;for(var A=(p.length-E)*u+1>>>0,w=new Uint8Array(A);p[E];){var L=r[p.charCodeAt(E)];if(L===255)return;for(var P=0,M=A-1;(L!==0||P<b)&&M!==-1;M--,P++)L+=a*w[M]>>>0,w[M]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");b=P,E++}if(p[E]!==" "){for(var U=A-b;U!==A&&w[U]===0;)U++;for(var k=new Uint8Array(S+(A-U)),x=S;U!==A;)k[x++]=w[U++];return k}}}function h(p){var E=f(p);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:f,decode:h}}var rc=ec,nc=rc,Ms=nc;var Pn=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")}},Kn=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 Os(this,t)}},kn=class{decoders;constructor(t){this.decoders=t}or(t){return Os(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 Os(e,t){return new kn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Rn=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 Pn(t,r,n),this.decoder=new Kn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Te({name:e,prefix:t,encode:r,decode:n}){return new Rn(e,t,r,n)}function te({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ms(r,e);return Te({prefix:t,name:e,encode:n,decode:s=>Nt(o(s))})}function oc(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let d=t[e[u]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|d,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function sc(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function ic(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=ic(n);return Te({prefix:t,name:e,encode(s){return sc(s,n,r)},decode(s){return oc(s,o,r,e)}})}var Y=te({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ac=te({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Un={};yt(Un,{base32:()=>De,base32hex:()=>lc,base32hexpad:()=>dc,base32hexpadupper:()=>pc,base32hexupper:()=>hc,base32pad:()=>uc,base32padupper:()=>fc,base32upper:()=>cc,base32z:()=>mc});var De=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),cc=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),uc=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),fc=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),lc=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),hc=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),dc=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),pc=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),mc=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Mn={};yt(Mn,{base36:()=>We,base36upper:()=>yc});var We=te({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),yc=te({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var bc=Vs,qs=128,gc=127,wc=~gc,xc=Math.pow(2,31);function Vs(e,t,r){t=t||[],r=r||0;for(var n=r;e>=xc;)t[r++]=e&255|qs,e/=128;for(;e&wc;)t[r++]=e&255|qs,e>>>=7;return t[r]=e|0,Vs.bytes=r-n+1,t}var Ec=On,Sc=128,Hs=127;function On(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw On.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Hs)<<o:(i&Hs)*Math.pow(2,o),o+=7}while(i>=Sc);return On.bytes=s-n,r}var vc=Math.pow(2,7),Ac=Math.pow(2,14),Ic=Math.pow(2,21),Bc=Math.pow(2,28),_c=Math.pow(2,35),Lc=Math.pow(2,42),Tc=Math.pow(2,49),Dc=Math.pow(2,56),Cc=Math.pow(2,63),Pc=function(e){return e<vc?1:e<Ac?2:e<Ic?3:e<Bc?4:e<_c?5:e<Lc?6:e<Tc?7:e<Dc?8:e<Cc?9:10},Kc={encode:bc,decode:Ec,encodingLength:Pc},kc=Kc,Je=kc;function Qe(e,t=0){return[Je.decode(e,t),Je.decode.bytes]}function Ce(e,t,r=0){return Je.encode(e,t,r),t}function Pe(e){return Je.encodingLength(e)}function Tt(e,t){let r=t.byteLength,n=Pe(e),o=n+Pe(r),s=new Uint8Array(o+r);return Ce(e,s,0),Ce(r,s,n),s.set(t,o),new Ke(e,r,t,s)}function ee(e){let t=Nt(e),[r,n]=Qe(t),[o,s]=Qe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ke(r,o,i,t)}function Fs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ks(e.bytes,r.bytes)}}var Ke=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function zs(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Nc(r,qn(e),t??Y.encoder);default:return Uc(r,qn(e),t??De.encoder)}}var Gs=new WeakMap;function qn(e){let t=Gs.get(e);if(t==null){let r=new Map;return Gs.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!==tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Mc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Tt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Fs(t.multihash,n.multihash)}toString(t){return zs(this,t)}toJSON(){return{"/":zs(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??Zs(n,o,s.bytes))}else if(r[Oc]===!0){let{version:n,multihash:o,code:s}=r,i=ee(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!==tr)throw new Error(`Version 0 CID must use dag-pb (code: ${tr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Zs(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,tr,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=Nt(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 Ke(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,f]=Qe(t.subarray(r));return r+=f,l},o=n(),s=tr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,d=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:u}}static parse(t,r){let[n,o]=Rc(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 qn(s).set(n,t),s}};function Rc(e,t){switch(e[0]){case"Q":{let r=t??Y;return[Y.prefix,r.decode(`${Y.prefix}${e}`)]}case Y.prefix:{let r=t??Y;return[Y.prefix,r.decode(e)]}case De.prefix:{let r=t??De;return[De.prefix,r.decode(e)]}case We.prefix:{let r=t??We;return[We.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 Nc(e,t,r){let{prefix:n}=r;if(n!==Y.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 Uc(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 tr=112,Mc=18;function Zs(e,t,r){let n=Pe(e),o=n+Pe(t),s=new Uint8Array(o+r.byteLength);return Ce(e,s,0),Ce(t,s,n),s.set(r,o),s}var Oc=Symbol.for("@ipld/js-cid/CID");var Hn={};yt(Hn,{identity:()=>Dt});var Ys=0,qc="identity",$s=Nt;function Hc(e){return Tt(Ys,$s(e))}var Dt={code:Ys,name:qc,encode:$s,digest:Hc};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 Ut(e=0){return new Uint8Array(e)}function ct(e=0){return new Uint8Array(e)}function pe(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 js=Symbol.for("@achingbrain/uint8arraylist");function Xs(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 Mr(e){return!!e?.[js]}var rt=class e{bufs;length;[js]=!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(Mr(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(Mr(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=Xs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Xs(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(Mr(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 pe(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:pe(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],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,d=r>a&&r<=c;if(u&&d){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Mr(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 a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,d;for(let l=r;l<=c;l+=d){d=0;for(let f=u;f>=0;f--){let h=this.get(l+f);if(n[f]!==h){d=Math.max(1,f-a[h]);break}}if(d===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=Ut(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=Ut(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=Ut(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=Ut(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=Ut(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=Ut(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=Ut(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=Ut(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 Vn={};yt(Vn,{base10:()=>Vc});var Vc=te({prefix:"9",name:"base10",alphabet:"0123456789"});var Fn={};yt(Fn,{base16:()=>Fc,base16upper:()=>zc});var Fc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),zc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var zn={};yt(zn,{base2:()=>Gc});var Gc=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Gn={};yt(Gn,{base256emoji:()=>jc});var Ws=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Zc=Ws.reduce((e,t,r)=>(e[r]=t,e),[]),Yc=Ws.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function $c(e){return e.reduce((t,r)=>(t+=Zc[r],t),"")}function Xc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Yc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var jc=Te({prefix:"\u{1F680}",name:"base256emoji",encode:$c,decode:Xc});var Zn={};yt(Zn,{base64:()=>Wc,base64pad:()=>Jc,base64url:()=>Qc,base64urlpad:()=>tu});var Wc=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Jc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Qc=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),tu=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Yn={};yt(Yn,{base8:()=>eu});var eu=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $n={};yt($n,{identity:()=>ru});var ru=Te({prefix:"\0",name:"identity",encode:e=>Ns(e),decode:e=>Rs(e)});var ph=new TextEncoder,mh=new TextDecoder;var Wn={};yt(Wn,{sha256:()=>me,sha512:()=>su});function jn({name:e,code:t,encode:r}){return new Xn(e,t,r)}var Xn=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?Tt(this.code,r):r.then(n=>Tt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Qs(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var me=jn({name:"sha2-256",code:18,encode:Qs("SHA-256")}),su=jn({name:"sha2-512",code:19,encode:Qs("SHA-512")});var Jn={...$n,...zn,...Yn,...Vn,...Fn,...Un,...Mn,...Nn,...Zn,...Gn},_h={...Wn,...Hn};function ei(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ti=ei("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Qn=ei("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}),iu={utf8:ti,"utf-8":ti,hex:Jn.base16,latin1:Qn,ascii:Qn,binary:Qn,...Jn},Or=iu;function z(e,t="utf8"){let r=Or[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function H(e,t="utf8"){let r=Or[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var au=parseInt("11111",2),to=parseInt("10000000",2),cu=parseInt("01111111",2),ri={0:er,1:er,2:uu,3:hu,4:du,5:lu,6:fu,16:er,22:er,48:er};function Mt(e,t={offset:0}){let r=e[t.offset]&au;if(t.offset++,ri[r]!=null)return ri[r](e,t);throw new Error("No decoder for tag "+r)}function rr(e,t){let r=0;if((e[t.offset]&to)===to){let n=e[t.offset]&cu,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 er(e,t){rr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Mt(e,t);if(n===null)break;r.push(n)}return r}function uu(e,t){let r=rr(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 fu(e,t){let r=rr(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 a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let d=0;for(let l=0;l<c.length;l++)d+=c[l]<<l*7;a+=`.${d}`,c=[]}}return a}function lu(e,t){return t.offset++,null}function hu(e,t){let r=rr(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 du(e,t){let r=rr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function pu(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 eo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=pu(e.byteLength);return new rt(Uint8Array.from([t.byteLength|to]),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]),eo(t),t)}function qr(e){let t=Uint8Array.from([0]),r=new rt(t,e);return new rt(Uint8Array.from([3]),eo(r),r)}function ne(e,t=48){let r=new rt;for(let n of e)r.append(n);return new rt(Uint8Array.from([t]),eo(r),r)}async function ni(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 mu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),yu=Uint8Array.from([6,5,43,129,4,0,34]),bu=Uint8Array.from([6,5,43,129,4,0,35]),gu={ext:!0,kty:"EC",crv:"P-256"},wu={ext:!0,kty:"EC",crv:"P-384"},xu={ext:!0,kty:"EC",crv:"P-521"},ro=32,no=48,oo=66;function so(e){let t=Mt(e);return oi(t)}function oi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===ro*2+1)return n=H(t.subarray(r,r+ro),"base64url"),o=H(t.subarray(r+ro),"base64url"),new ke({...gu,key_ops:["verify"],x:n,y:o});if(t.byteLength===no*2+1)return n=H(t.subarray(r,r+no),"base64url"),o=H(t.subarray(r+no),"base64url"),new ke({...wu,key_ops:["verify"],x:n,y:o});if(t.byteLength===oo*2+1)return n=H(t.subarray(r,r+oo),"base64url"),o=H(t.subarray(r+oo),"base64url"),new ke({...xu,key_ops:["verify"],x:n,y:o});throw new Z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function si(e){return ne([gt(Uint8Array.from([1])),ne([Eu(e.crv)],160),ne([qr(new rt(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function Eu(e){if(e==="P-256")return mu;if(e==="P-384")return yu;if(e==="P-521")return bu;throw new Z(`Invalid curve ${e}`)}var ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=si(this.jwk)),this._raw}toMultihash(){return Dt.digest(Ot(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Y.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 ni(this.jwk,r,t,n)}};var ye=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ht(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function nr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function wt(e,...t){if(!Ht(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 Hr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");nr(e.outputLen),nr(e.blockLen)}function Ne(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 ai(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 Vt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Vr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ct(e,t){return e<<32-t|e>>>t}var ci=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Su=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Bt(e){if(wt(e),ci)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Su[e[r]];return t}var qt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ii(e){if(e>=qt._0&&e<=qt._9)return e-qt._0;if(e>=qt.A&&e<=qt.F)return e-(qt.A-10);if(e>=qt.a&&e<=qt.f)return e-(qt.a-10)}function be(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ci)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=ii(e.charCodeAt(s)),a=ii(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function io(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function or(e){return typeof e=="string"&&(e=io(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 Re=class{};function ao(e){let t=n=>e().update(or(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function oe(e=32){if(ye&&typeof ye.getRandomValues=="function")return ye.getRandomValues(new Uint8Array(e));if(ye&&typeof ye.randomBytes=="function")return Uint8Array.from(ye.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function vu(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),a=Number(r&s),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function ui(e,t,r){return e&t^~e&r}function fi(e,t,r){return e&t^e&r^t&r}var sr=class extends Re{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=Vr(this.buffer)}update(t){Ne(this),t=or(t),wt(t);let{view:r,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=Vr(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(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ne(this),ai(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Vt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;vu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Vr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,d[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:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ft=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 Fr=BigInt(4294967295),li=BigInt(32);function Au(e,t=!1){return t?{h:Number(e&Fr),l:Number(e>>li&Fr)}:{h:Number(e>>li&Fr)|0,l:Number(e&Fr)|0}}function hi(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:a}=Au(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var co=(e,t,r)=>e>>>r,uo=(e,t,r)=>e<<32-r|t>>>r,ge=(e,t,r)=>e>>>r|t<<32-r,we=(e,t,r)=>e<<32-r|t>>>r,ir=(e,t,r)=>e<<64-r|t>>>r-32,ar=(e,t,r)=>e>>>r-32|t<<64-r;function kt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var di=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),pi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,mi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),yi=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,bi=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),gi=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Bu=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]),se=new Uint32Array(64),zr=class extends sr{constructor(t=32){super(64,t,8,!1),this.A=Ft[0]|0,this.B=Ft[1]|0,this.C=Ft[2]|0,this.D=Ft[3]|0,this.E=Ft[4]|0,this.F=Ft[5]|0,this.G=Ft[6]|0,this.H=Ft[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){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=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)se[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let f=se[l-15],h=se[l-2],p=Ct(f,7)^Ct(f,18)^f>>>3,E=Ct(h,17)^Ct(h,19)^h>>>10;se[l]=E+se[l-7]+p+se[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:d}=this;for(let l=0;l<64;l++){let f=Ct(a,6)^Ct(a,11)^Ct(a,25),h=d+f+ui(a,c,u)+Bu[l]+se[l]|0,E=(Ct(n,2)^Ct(n,13)^Ct(n,22))+fi(n,o,s)|0;d=u,u=c,c=a,a=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,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,u,d)}roundClean(){Vt(se)}destroy(){this.set(0,0,0,0,0,0,0,0),Vt(this.buffer)}};var wi=hi(["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))),_u=wi[0],Lu=wi[1],ie=new Uint32Array(80),ae=new Uint32Array(80),fo=class extends sr{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:a,Dl:c,Eh:u,El:d,Fh:l,Fl:f,Gh:h,Gl:p,Hh:E,Hl:S}=this;return[t,r,n,o,s,i,a,c,u,d,l,f,h,p,E,S]}set(t,r,n,o,s,i,a,c,u,d,l,f,h,p,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=a|0,this.Dl=c|0,this.Eh=u|0,this.El=d|0,this.Fh=l|0,this.Fl=f|0,this.Gh=h|0,this.Gl=p|0,this.Hh=E|0,this.Hl=S|0}process(t,r){for(let w=0;w<16;w++,r+=4)ie[w]=t.getUint32(r),ae[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let L=ie[w-15]|0,P=ae[w-15]|0,M=ge(L,P,1)^ge(L,P,8)^co(L,P,7),U=we(L,P,1)^we(L,P,8)^uo(L,P,7),k=ie[w-2]|0,x=ae[w-2]|0,T=ge(k,x,19)^ir(k,x,61)^co(k,x,6),R=we(k,x,19)^ar(k,x,61)^uo(k,x,6),D=mi(U,R,ae[w-7],ae[w-16]),g=yi(D,M,T,ie[w-7],ie[w-16]);ie[w]=g|0,ae[w]=D|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:d,Eh:l,El:f,Fh:h,Fl:p,Gh:E,Gl:S,Hh:b,Hl:A}=this;for(let w=0;w<80;w++){let L=ge(l,f,14)^ge(l,f,18)^ir(l,f,41),P=we(l,f,14)^we(l,f,18)^ar(l,f,41),M=l&h^~l&E,U=f&p^~f&S,k=bi(A,P,U,Lu[w],ae[w]),x=gi(k,b,L,M,_u[w],ie[w]),T=k|0,R=ge(n,o,28)^ir(n,o,34)^ir(n,o,39),D=we(n,o,28)^ar(n,o,34)^ar(n,o,39),g=n&s^n&a^s&a,m=o&i^o&c^i&c;b=E|0,A=S|0,E=h|0,S=p|0,h=l|0,p=f|0,{h:l,l:f}=kt(u|0,d|0,x|0,T|0),u=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let y=di(T,D,m);n=pi(y,x,R,g),o=y|0}({h:n,l:o}=kt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=kt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=kt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:d}=kt(this.Dh|0,this.Dl|0,u|0,d|0),{h:l,l:f}=kt(this.Eh|0,this.El|0,l|0,f|0),{h,l:p}=kt(this.Fh|0,this.Fl|0,h|0,p|0),{h:E,l:S}=kt(this.Gh|0,this.Gl|0,E|0,S|0),{h:b,l:A}=kt(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,a,c,u,d,l,f,h,p,E,S,b,A)}roundClean(){Vt(ie,ae)}destroy(){Vt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Gr=ao(()=>new zr);var xi=ao(()=>new fo);var po=BigInt(0),ho=BigInt(1);function zt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function vt(e,t,r=""){let n=Ht(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function cr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Ei(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?po:BigInt("0x"+e)}function Ue(e){return Ei(Bt(e))}function Gt(e){return wt(e),Ei(Bt(Uint8Array.from(e).reverse()))}function Zr(e,t){return be(e.toString(16).padStart(t*2,"0"))}function mo(e,t){return Zr(e,t).reverse()}function V(e,t,r){let n;if(typeof t=="string")try{n=be(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ht(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 Si(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 yo(e){return Uint8Array.from(e)}var lo=e=>typeof e=="bigint"&&po<=e;function vi(e,t,r){return lo(e)&&lo(t)&&lo(r)&&t<=e&&e<r}function ur(e,t,r,n){if(!vi(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Yr(e){let t;for(t=0;e>po;e>>=ho,t+=1);return t}var ce=e=>(ho<<BigInt(e))-ho;function Ai(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),a=0,c=()=>{s.fill(1),i.fill(0),a=0},u=(...h)=>r(i,s,...h),d=(h=n(0))=>{i=u(o(0),h),s=u(),h.length!==0&&(i=u(o(1),h),s=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,p=[];for(;h<t;){s=u();let E=s.slice();p.push(E),h+=s.length}return ht(...p)};return(h,p)=>{c(),d(h);let E;for(;!(E=p(l()));)d();return c(),E}}function ue(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[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(r).forEach(([o,s])=>n(o,s,!0))}var bo=()=>{throw new Error("not implemented")};function Me(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),xe=BigInt(2),_i=BigInt(3),Li=BigInt(4),Ti=BigInt(5),Tu=BigInt(7),Di=BigInt(8),Du=BigInt(9),Ci=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 Ii(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,a=dt;for(;r!==dt;){let u=n/r,d=n%r,l=o-i*u,f=s-a*u;n=r,r=d,o=i,s=a,i=l,a=f}if(n!==nt)throw new Error("invert: does not exist");return J(o,t)}function go(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Pi(e,t){let r=(e.ORDER+nt)/Li,n=e.pow(t,r);return go(e,n,t),n}function Cu(e,t){let r=(e.ORDER-Ti)/Di,n=e.mul(t,xe),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,xe),o),a=e.mul(s,e.sub(i,e.ONE));return go(e,a,t),a}function Pu(e){let t=At(e),r=Ki(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Tu)/Ci;return(a,c)=>{let u=a.pow(c,i),d=a.mul(u,n),l=a.mul(u,o),f=a.mul(u,s),h=a.eql(a.sqr(d),c),p=a.eql(a.sqr(l),c);u=a.cmov(u,d,h),d=a.cmov(f,l,p);let E=a.eql(a.sqr(d),c),S=a.cmov(u,d,E);return go(a,S,c),S}}function Ki(e){if(e<_i)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%xe===dt;)t/=xe,r++;let n=xe,o=At(e);for(;Bi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Pi;let s=o.pow(n,t),i=(t+nt)/xe;return function(c,u){if(c.is0(u))return u;if(Bi(c,u)!==1)throw new Error("Cannot find square root");let d=r,l=c.mul(c.ONE,s),f=c.pow(u,t),h=c.pow(u,i);for(;!c.eql(f,c.ONE);){if(c.is0(f))return c.ZERO;let p=1,E=c.sqr(f);for(;!c.eql(E,c.ONE);)if(p++,E=c.sqr(E),p===d)throw new Error("Cannot find square root");let S=nt<<BigInt(d-p-1),b=c.pow(l,S);d=p,l=c.sqr(b),f=c.mul(f,l),h=c.mul(h,b)}return h}}function Ku(e){return e%Li===_i?Pi:e%Di===Ti?Cu:e%Ci===Du?Pu(e):Ki(e)}var Zt=(e,t)=>(J(e,t)&nt)===nt,ku=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function wo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=ku.reduce((n,o)=>(n[o]="function",n),t);return ue(e,r),e}function Ru(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 fr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function Bi(e,t){let r=(e.ORDER-nt)/xe,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 $r(e,t){t!==void 0&&nr(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function At(e,t,r=!1,n={}){if(e<=dt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),a=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:u}=$r(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,l=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:u,MASK:ce(c),ZERO:dt,ONE:nt,allowedLengths:a,create:f=>J(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return dt<=f&&f<e},is0:f=>f===dt,isValidNot0:f=>!l.is0(f)&&l.isValid(f),isOdd:f=>(f&nt)===nt,neg:f=>J(-f,e),eql:(f,h)=>f===h,sqr:f=>J(f*f,e),add:(f,h)=>J(f+h,e),sub:(f,h)=>J(f-h,e),mul:(f,h)=>J(f*h,e),pow:(f,h)=>Ru(l,f,h),div:(f,h)=>J(f*Ii(h,e),e),sqrN:f=>f*f,addN:(f,h)=>f+h,subN:(f,h)=>f-h,mulN:(f,h)=>f*h,inv:f=>Ii(f,e),sqrt:s||(f=>(d||(d=Ku(e)),d(l,f))),toBytes:f=>r?mo(f,u):Zr(f,u),fromBytes:(f,h=!0)=>{if(a){if(!a.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);let E=new Uint8Array(u);E.set(f,r?0:E.length-f.length),f=E}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let p=r?Gt(f):Ue(f);if(i&&(p=J(p,e)),!h&&!l.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:f=>fr(l,f),cmov:(f,h,p)=>p?h:f});return Object.freeze(l)}function ki(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 xo(e){let t=ki(e);return t+Math.ceil(t/2)}function Eo(e,t,r=!1){let n=e.length,o=ki(t),s=xo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Gt(e):Ue(e),a=J(i,t-nt)+nt;return r?mo(a,o):Zr(a,o)}var Oe=BigInt(0),Ee=BigInt(1);function lr(e,t){let r=t.negate();return e?r:t}function Yt(e,t){let r=fr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Mi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function So(e,t){Mi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=ce(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ri(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=Ee);let u=t*n,d=u+Math.abs(a)-1,l=a===0,f=a<0,h=t%2!==0;return{nextN:c,offset:d,isZero:l,isNeg:f,isNegF:h,offsetF:u}}function Nu(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 Uu(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 vo=new WeakMap,Oi=new WeakMap;function Ao(e){return Oi.get(e)||1}function Ni(e){if(e!==Oe)throw new Error("invalid wNAF")}var qe=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>Oe;)r&Ee&&(n=n.add(o)),o=o.double(),r>>=Ee;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=So(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.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=So(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:d,isNeg:l,isNegF:f,offsetF:h}=Ri(n,a,i);n=c,d?s=s.add(lr(f,r[h])):o=o.add(lr(l,r[u]))}return Ni(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=So(t,this.bits);for(let i=0;i<s.windows&&n!==Oe;i++){let{nextN:a,offset:c,isZero:u,isNeg:d}=Ri(n,i,s);if(n=a,!u){let l=r[c];o=o.add(d?l.negate():l)}}return Ni(n),o}getPrecomputes(t,r,n){let o=vo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),vo.set(r,o))),o}cached(t,r,n){let o=Ao(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Ao(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Mi(r,this.bits),Oi.set(t,r),vo.delete(t)}hasCache(t){return Ao(t)!==1}};function qi(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Oe||n>Oe;)r&Ee&&(s=s.add(o)),n&Ee&&(i=i.add(o)),o=o.double(),r>>=Ee,n>>=Ee;return{p1:s,p2:i}}function He(e,t,r,n){Nu(r,e),Uu(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,a=Yr(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=ce(c),d=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,f=i;for(let h=l;h>=0;h-=c){d.fill(i);for(let E=0;E<s;E++){let S=n[E],b=Number(S>>BigInt(h)&u);d[b]=d[b].add(r[E])}let p=i;for(let E=d.length-1,S=i;E>0;E--)S=S.add(d[E]),p=p.add(S);if(f=f.add(p),h!==0)for(let E=0;E<c;E++)f=f.double()}return f}function Ui(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return wo(t),t}else return At(e,{isLE:r})}function Xr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Oe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ui(t.p,r.Fp,n),s=Ui(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var fe=BigInt(0),ot=BigInt(1),Io=BigInt(2),Mu=BigInt(8);function Ou(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function qu(e,t={}){let r=Xr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;ue(t,{},{uvRatio:"function"});let a=Io<<BigInt(o.BYTES*8)-ot,c=S=>n.create(S),u=t.uvRatio||((S,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,b))}}catch{return{isValid:!1,value:fe}}});if(!Ou(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function d(S,b,A=!1){let w=A?ot:fe;return ur("coordinate "+S,b,w,a),b}function l(S){if(!(S instanceof p))throw new Error("ExtendedPoint expected")}let f=Me((S,b)=>{let{X:A,Y:w,Z:L}=S,P=S.is0();b==null&&(b=P?Mu:n.inv(L));let M=c(A*b),U=c(w*b),k=n.mul(L,b);if(P)return{x:fe,y:ot};if(k!==ot)throw new Error("invZ was invalid");return{x:M,y:U}}),h=Me(S=>{let{a:b,d:A}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:w,Y:L,Z:P,T:M}=S,U=c(w*w),k=c(L*L),x=c(P*P),T=c(x*x),R=c(U*b),D=c(x*c(R+k)),g=c(T+c(A*c(U*k)));if(D!==g)throw new Error("bad point: equation left != right (1)");let m=c(w*L),y=c(P*M);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(b,A,w,L){this.X=d("x",b),this.Y=d("y",A),this.Z=d("z",w,!0),this.T=d("t",L),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof p)throw new Error("extended point not allowed");let{x:A,y:w}=b||{};return d("x",A),d("y",w),new p(A,w,ot,c(A*w))}static fromBytes(b,A=!1){let w=n.BYTES,{a:L,d:P}=s;b=yo(vt(b,w,"point")),zt(A,"zip215");let M=yo(b),U=b[w-1];M[w-1]=U&-129;let k=Gt(M),x=A?a:n.ORDER;ur("point.y",k,fe,x);let T=c(k*k),R=c(T-ot),D=c(P*T-L),{isValid:g,value:m}=u(R,D);if(!g)throw new Error("bad point: invalid y coordinate");let y=(m&ot)===ot,v=(U&128)!==0;if(!A&&m===fe&&v)throw new Error("bad point: x=0 and x_0=1");return v!==y&&(m=c(-m)),p.fromAffine({x:m,y:k})}static fromHex(b,A=!1){return p.fromBytes(V("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(Io),this}assertValidity(){h(this)}equals(b){l(b);let{X:A,Y:w,Z:L}=this,{X:P,Y:M,Z:U}=b,k=c(A*U),x=c(P*L),T=c(w*U),R=c(M*L);return k===x&&T===R}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=s,{X:A,Y:w,Z:L}=this,P=c(A*A),M=c(w*w),U=c(Io*c(L*L)),k=c(b*P),x=A+w,T=c(c(x*x)-P-M),R=k+M,D=R-U,g=k-M,m=c(T*D),y=c(R*g),v=c(T*g),I=c(D*R);return new p(m,y,I,v)}add(b){l(b);let{a:A,d:w}=s,{X:L,Y:P,Z:M,T:U}=this,{X:k,Y:x,Z:T,T:R}=b,D=c(L*k),g=c(P*x),m=c(U*w*R),y=c(M*T),v=c((L+P)*(k+x)-D-g),I=y-m,C=y+m,B=c(g-A*D),_=c(v*I),K=c(C*B),N=c(v*B),$=c(I*C);return new p(_,K,$,N)}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=>Yt(p,L));return Yt(p,[A,w])[0]}multiplyUnsafe(b,A=p.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===fe?p.ZERO:this.is0()||b===ot?this:E.unsafe(this,b,w=>Yt(p,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(b){return f(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 Bt(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 Yt(p,b)}static msm(b,A){return He(p,o,b,A)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,ot,c(s.Gx*s.Gy)),p.ZERO=new p(fe,ot,ot,fe),p.Fp=n,p.Fn=o;let E=new qe(p,o.BITS);return p.BASE.precompute(8),p}var jr=class{constructor(t){this.ep=t}static fromBytes(t){bo()}static fromHex(t){bo()}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 Bt(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 Hu(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ue(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,a=r.randomBytes||oe,c=r.adjustScalarBytes||(x=>x),u=r.domain||((x,T,R)=>{if(zt(R,"phflag"),T.length||R)throw new Error("Contexts/pre-hash are not supported");return x});function d(x){return i.create(Gt(x))}function l(x){let T=w.secretKey;x=V("private key",x,T);let R=V("hashed private key",t(x),2*T),D=c(R.slice(0,T)),g=R.slice(T,2*T),m=d(D);return{head:D,prefix:g,scalar:m}}function f(x){let{head:T,prefix:R,scalar:D}=l(x),g=o.multiply(D),m=g.toBytes();return{head:T,prefix:R,scalar:D,point:g,pointBytes:m}}function h(x){return f(x).pointBytes}function p(x=Uint8Array.of(),...T){let R=ht(...T);return d(t(u(R,V("context",x),!!n)))}function E(x,T,R={}){x=V("message",x),n&&(x=n(x));let{prefix:D,scalar:g,pointBytes:m}=f(T),y=p(R.context,D,x),v=o.multiply(y).toBytes(),I=p(R.context,v,m,x),C=i.create(y+I*g);if(!i.isValid(C))throw new Error("sign failed: invalid s");let B=ht(v,i.toBytes(C));return vt(B,w.signature,"result")}let S={zip215:!0};function b(x,T,R,D=S){let{context:g,zip215:m}=D,y=w.signature;x=V("signature",x,y),T=V("message",T),R=V("publicKey",R,w.publicKey),m!==void 0&&zt(m,"zip215"),n&&(T=n(T));let v=y/2,I=x.subarray(0,v),C=Gt(x.subarray(v,y)),B,_,K;try{B=e.fromBytes(R,m),_=e.fromBytes(I,m),K=o.multiplyUnsafe(C)}catch{return!1}if(!m&&B.isSmallOrder())return!1;let N=p(g,_.toBytes(),B.toBytes(),T);return _.add(B.multiplyUnsafe(N)).subtract(K).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function L(x=a(w.seed)){return vt(x,w.seed,"seed")}function P(x){let T=k.randomSecretKey(x);return{secretKey:T,publicKey:h(T)}}function M(x){return Ht(x)&&x.length===i.BYTES}function U(x,T){try{return!!e.fromBytes(x,T)}catch{return!1}}let k={getExtendedPublicKey:f,randomSecretKey:L,isValidSecretKey:M,isValidPublicKey:U,toMontgomery(x){let{y:T}=e.fromBytes(x),R=w.publicKey,D=R===32;if(!D&&R!==57)throw new Error("only defined for 25519 and 448");let g=D?s.div(ot+T,ot-T):s.div(T-ot,T+ot);return s.toBytes(g)},toMontgomeryPriv(x){let T=w.secretKey;vt(x,T);let R=t(x.subarray(0,T));return c(R).subarray(0,T)},randomPrivateKey:L,precompute(x=8,T=e.BASE){return T.precompute(x,!1)}};return Object.freeze({keygen:P,getPublicKey:h,sign:E,verify:b,utils:k,Point:e,lengths:w})}function Vu(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=At(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 Fu(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Hi(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=Vu(e),s=qu(t,r),i=Hu(s,n,o);return Fu(e,i)}var zu=BigInt(0),$t=BigInt(1),Vi=BigInt(2),Rd=BigInt(3),Gu=BigInt(5),Zu=BigInt(8),Ve=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),hr={p:Ve,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Zu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Yu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ve,a=e*e%s*e%s,c=G(a,Vi,s)*a%s,u=G(c,$t,s)*e%s,d=G(u,Gu,s)*u%s,l=G(d,t,s)*d%s,f=G(l,r,s)*l%s,h=G(f,n,s)*f%s,p=G(h,o,s)*h%s,E=G(p,o,s)*h%s,S=G(E,t,s)*d%s;return{pow_p_5_8:G(S,Vi,s)*e%s,b2:a}}function $u(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Bo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function To(e,t){let r=Ve,n=J(t*t*t,r),o=J(n*n*t,r),s=Yu(e*o).pow_p_5_8,i=J(e*n*s,r),a=J(t*i*i,r),c=i,u=J(i*Bo,r),d=a===e,l=a===J(-e,r),f=a===J(-e*Bo,r);return d&&(i=c),(l||f)&&(i=u),Zt(i,r)&&(i=J(-i,r)),{isValid:d||l,value:i}}var le=At(hr.p,{isLE:!0}),Xu=At(hr.n,{isLE:!0}),ju={...hr,Fp:le,hash:xi,adjustScalarBytes:$u,uvRatio:To},Xt=Hi(ju);var _o=Bo,Wu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Ju=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Qu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),tf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Fi=e=>To($t,e),ef=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Lo=e=>Xt.Point.Fp.create(Gt(e)&ef);function zi(e){let{d:t}=hr,r=Ve,n=b=>le.create(b),o=n(_o*e*e),s=n((o+$t)*Qu),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=To(s,a),d=n(u*e);Zt(d,r)||(d=n(-d)),c||(u=d),c||(i=o);let l=n(i*(o-$t)*tf-a),f=u*u,h=n((u+u)*a),p=n(l*Wu),E=n($t-f),S=n($t+f);return new Xt.Point(n(h*S),n(E*p),n(p*S),n(h*E))}function rf(e){wt(e,64);let t=Lo(e.subarray(0,32)),r=zi(t),n=Lo(e.subarray(32,64)),o=zi(n);return new jt(r.add(o))}var jt=class e extends jr{constructor(t){super(t)}static fromAffine(t){return new e(Xt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return rf(V("ristrettoHash",t,64))}static fromBytes(t){wt(t,32);let{a:r,d:n}=hr,o=Ve,s=L=>le.create(L),i=Lo(t);if(!Si(le.toBytes(i),t)||Zt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s($t+r*a),u=s($t-r*a),d=s(c*c),l=s(u*u),f=s(r*n*d-l),{isValid:h,value:p}=Fi(s(f*l)),E=s(p*u),S=s(p*E*f),b=s((i+i)*E);Zt(b,o)&&(b=s(-b));let A=s(c*S),w=s(b*A);if(!h||Zt(w,o)||A===zu)throw new Error("invalid ristretto255 encoding 2");return new e(new Xt.Point(b,A,$t,w))}static fromHex(t){return e.fromBytes(V("ristrettoHex",t,32))}static msm(t,r){return He(e,Xt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ve,i=S=>le.create(S),a=i(i(n+r)*i(n-r)),c=i(t*r),u=i(c*c),{value:d}=Fi(i(a*u)),l=i(d*a),f=i(d*c),h=i(l*f*o),p;if(Zt(o*h,s)){let S=i(r*_o),b=i(t*_o);t=S,r=b,p=i(l*Ju)}else p=f;Zt(t*h,s)&&(r=i(-r));let E=i((n-r)*p);return Zt(E,s)&&(E=i(-E)),le.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>le.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(e.ZERO)}};jt.BASE=new jt(Xt.Point.BASE);jt.ZERO=new jt(Xt.Point.ZERO);jt.Fp=le;jt.Fn=Xu;var dr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Wr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Gi={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Wr("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 _t=Gi;var Jr=32;var Do,nf=(async()=>{try{return await _t.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function of(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await _t.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await _t.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 sf(e,t,r){return Xt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Zi(e,t,r){return Do==null&&(Do=await nf),Do?of(e,t,r):sf(e,t,r)}function Qr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var tn=class{type="Ed25519";raw;constructor(t){this.raw=Co(t,Jr)}toMultihash(){return Dt.digest(Ot(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Y.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=Zi(this.raw,r,t);return Qr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Po(e){return e=Co(e,Jr),new tn(e)}function Co(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 cf=Math.pow(2,7),uf=Math.pow(2,14),ff=Math.pow(2,21),Ko=Math.pow(2,28),ko=Math.pow(2,35),Ro=Math.pow(2,42),No=Math.pow(2,49),q=128,ut=127;function Pt(e){if(e<cf)return 1;if(e<uf)return 2;if(e<ff)return 3;if(e<Ko)return 4;if(e<ko)return 5;if(e<Ro)return 6;if(e<No)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Uo(e,t,r=0){switch(Pt(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 lf(e,t,r=0){switch(Pt(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 Mo(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)*Ko,r<q)||(r=e[t+5],n+=(r&ut)*ko,r<q)||(r=e[t+6],n+=(r&ut)*Ro,r<q)||(r=e[t+7],n+=(r&ut)*No,r<q))return n;throw new RangeError("Could not decode varint")}function hf(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)*Ko,r<q)||(r=e.get(t+5),n+=(r&ut)*ko,r<q)||(r=e.get(t+6),n+=(r&ut)*Ro,r<q)||(r=e.get(t+7),n+=(r&ut)*No,r<q))return n;throw new RangeError("Could not decode varint")}function $i(e,t,r=0){return t==null&&(t=ct(Pt(e))),t instanceof Uint8Array?Uo(e,t,r):lf(e,t,r)}function Xi(e,t=0){return e instanceof Uint8Array?Mo(e,t):hf(e,t)}var Oo=new Float32Array([-0]),he=new Uint8Array(Oo.buffer);function Wi(e,t,r){Oo[0]=e,t[r]=he[0],t[r+1]=he[1],t[r+2]=he[2],t[r+3]=he[3]}function Ji(e,t){return he[0]=e[t],he[1]=e[t+1],he[2]=e[t+2],he[3]=e[t+3],Oo[0]}var qo=new Float64Array([-0]),ft=new Uint8Array(qo.buffer);function Qi(e,t,r){qo[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 ta(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],qo[0]}var df=BigInt(Number.MAX_SAFE_INTEGER),pf=BigInt(Number.MIN_SAFE_INTEGER),It=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 Se;if(t<df&&t>pf)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>ea&&(o=0n,++n>ea&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Se;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):Se}},Se=new It(0,0);Se.toBigInt=function(){return 0n};Se.zzEncode=Se.zzDecode=function(){return this};Se.length=function(){return 1};var ea=4294967296n;function ra(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 na(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&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 Ho(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 Kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function en(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Vo=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,Kt(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 Kt(this,4);return en(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return en(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Ji(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=ta(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 Kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return na(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Kt(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 It(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 Kt(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 Kt(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 Kt(this,8);let t=en(this.buf,this.pos+=4),r=en(this.buf,this.pos+=4);return new It(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=Mo(this.buf,this.pos);return this.pos+=Pt(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 Fo(e){return new Vo(e instanceof Uint8Array?e:e.subarray())}function xt(e,t,r){let n=Fo(e);return t.decode(n,void 0,r)}function zo(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 a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ve=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Go(){}var Yo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},mf=zo();function yf(e){return globalThis.Buffer!=null?ct(e):mf(e)}var mr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ve(Go,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ve(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new $o((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(rn,10,It.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=It.fromBigInt(t);return this._push(rn,r.length(),r)}uint64Number(t){return this._push(Uo,Pt(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=It.fromBigInt(t).zzEncode();return this._push(rn,r.length(),r)}sint64Number(t){let r=It.fromNumber(t).zzEncode();return this._push(rn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Zo,1,t?1:0)}fixed32(t){return this._push(pr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=It.fromBigInt(t);return this._push(pr,4,r.lo)._push(pr,4,r.hi)}fixed64Number(t){let r=It.fromNumber(t);return this._push(pr,4,r.lo)._push(pr,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(Wi,4,t)}double(t){return this._push(Qi,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Zo,1,0):this.uint32(r)._push(gf,r,t)}string(t){let r=ra(t);return r!==0?this.uint32(r)._push(Ho,r,t):this._push(Zo,1,0)}fork(){return this.states=new Yo(this),this.head=this.tail=new ve(Go,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 ve(Go,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=yf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Zo(e,t,r){t[r]=e&255}function bf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var $o=class extends ve{next;constructor(t,r){super(bf,t,r),this.next=void 0}};function rn(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 pr(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 gf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(mr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(wf,t,e),this},mr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(xf,t,e),this});function wf(e,t,r){t.set(e,r)}function xf(e,t,r){e.length<40?Ho(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(z(e),r)}function Xo(){return new mr}function Et(e,t){let r=Xo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Fe;(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"})(Fe||(Fe={}));function nn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function jo(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return nn("enum",Fe.VARINT,r,n)}function St(e,t){return nn("message",Fe.LENGTH_DELIMITED,e,t)}var Lt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var tt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(tt||(tt={}));var Wo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Wo||(Wo={}));(function(e){e.codec=()=>jo(Wo)})(tt||(tt={}));var Rt;(function(e){let t;e.codec=()=>(t==null&&(t=St((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 a=r.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(Rt||(Rt={}));var Jo;(function(e){let t;e.codec=()=>(t==null&&(t=St((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 a=r.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(Jo||(Jo={}));function on(e){if(isNaN(e)||e<=0)throw new Z("random bytes length must be a Number bigger than 0");return oe(e)}var br={};yt(br,{MAX_RSA_KEY_SIZE:()=>Qo,generateRSAKeyPair:()=>ua,jwkToJWKKeyPair:()=>fa,jwkToPkcs1:()=>Af,jwkToPkix:()=>ns,jwkToRSAPrivateKey:()=>as,pkcs1MessageToJwk:()=>es,pkcs1MessageToRSAPrivateKey:()=>os,pkcs1ToJwk:()=>vf,pkcs1ToRSAPrivateKey:()=>ca,pkixMessageToJwk:()=>rs,pkixMessageToRSAPublicKey:()=>is,pkixToJwk:()=>If,pkixToRSAPublicKey:()=>ss});var sn=Gr;var ze=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=br.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return Y.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 aa(this.jwk,r,t,n)}},yr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=br.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}sign(t,r){return ia(this.jwk,t,r)}};var Qo=8192,ts=18,Ef=1062,Sf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function vf(e){let t=Mt(e);return es(t)}function es(e){return{n:H(e[1],"base64url"),e:H(e[2],"base64url"),d:H(e[3],"base64url"),p:H(e[4],"base64url"),q:H(e[5],"base64url"),dp:H(e[6],"base64url"),dq:H(e[7],"base64url"),qi:H(e[8],"base64url"),kty:"RSA"}}function Af(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 ne([gt(Uint8Array.from([0])),gt(z(e.n,"base64url")),gt(z(e.e,"base64url")),gt(z(e.d,"base64url")),gt(z(e.p,"base64url")),gt(z(e.q,"base64url")),gt(z(e.dp,"base64url")),gt(z(e.dq,"base64url")),gt(z(e.qi,"base64url"))]).subarray()}function If(e){let t=Mt(e,{offset:0});return rs(t)}function rs(e){let t=Mt(e[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function ns(e){if(e.n==null||e.e==null)throw new Z("JWK was missing components");return ne([Sf,qr(ne([gt(z(e.n,"base64url")),gt(z(e.e,"base64url"))]))]).subarray()}function ca(e){let t=Mt(e);return os(t)}function os(e){let t=es(e);return as(t)}function ss(e,t){if(e.byteLength>=Ef)throw new _e("Key size is too large");let r=Mt(e,{offset:0});return is(r,e,t)}function is(e,t,r){let n=rs(e);if(r==null){let o=sn(Rt.encode({Type:tt.RSA,Data:t}));r=Tt(ts,o)}return new ze(n,r)}function as(e){if(ha(e)>Qo)throw new Z("Key size is too large");let t=fa(e),r=sn(Rt.encode({Type:tt.RSA,Data:ns(t.publicKey)})),n=Tt(ts,r);return new yr(t.privateKey,new ze(t.publicKey,n))}async function ua(e){if(e>Qo)throw new Z("Key size is too large");let t=await la(e),r=sn(Rt.encode({Type:tt.RSA,Data:ns(t.publicKey)})),n=Tt(ts,r);return new yr(t.privateKey,new ze(t.publicKey,n))}function fa(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 la(e,t){let r=await _t.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 Bf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function ia(e,t,r){let n=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await _t.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 aa(e,t,r,n){let o=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await _t.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Bf(e,t){if(e.privateKey==null||e.publicKey==null)throw new Z("Private and public key are required");let r=await Promise.all([_t.get().subtle.exportKey("jwk",e.privateKey),_t.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function ha(e){if(e.kty!=="RSA")throw new Z("invalid key type");if(e.n==null)throw new Z("invalid key modulus");return z(e.n,"base64url").length*8}var an=class extends Re{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Hr(t);let n=or(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),Vt(s)}update(t){return Ne(this),this.iHash.update(t),this}digestInto(t){Ne(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:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},cs=(e,t,r)=>new an(e,t).update(r).digest();cs.create=(e,t)=>new an(e,t);var da=(e,t)=>(e+(e>=0?t:-t)/pa)/t;function _f(e,t,r){let[[n,o],[s,i]]=t,a=da(i*e,r),c=da(-o*e,r),u=e-a*n-c*s,d=-a*o-c*i,l=u<Jt,f=d<Jt;l&&(u=-u),f&&(d=-d);let h=ce(Math.ceil(Yr(r)/2))+Ze;if(u<Jt||u>=h||d<Jt||d>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:f,k2:d}}function fs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function us(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return zt(r.lowS,"lowS"),zt(r.prehash,"prehash"),r.format!==void 0&&fs(r.format),r}var ls=class extends Error{constructor(t=""){super(t)}},Wt={Err:ls,_tlv:{encode:(e,t)=>{let{Err:r}=Wt;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=cr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?cr(o.length/2|128):"";return cr(e)+s+o+t},decode(e,t){let{Err:r}=Wt,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 c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of u)i=i<<8|d;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Wt;if(e<Jt)throw new t("integer: negative integers are not allowed");let r=cr(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}=Wt;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 Ue(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Wt,o=V("signature",e),{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:u,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Wt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Jt=BigInt(0),Ze=BigInt(1),pa=BigInt(2),cn=BigInt(3),Lf=BigInt(4);function Ge(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=V("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 Tf(e,t={}){let r=Xr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;ue(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=ya(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(D,g,m){let{x:y,y:v}=g.toAffine(),I=n.toBytes(y);if(zt(m,"isCompressed"),m){d();let C=!n.isOdd(v);return ht(ma(C),I)}else return ht(Uint8Array.of(4),I,n.toBytes(v))}function f(D){vt(D,void 0,"Point");let{publicKey:g,publicKeyUncompressed:m}=u,y=D.length,v=D[0],I=D.subarray(1);if(y===g&&(v===2||v===3)){let C=n.fromBytes(I);if(!n.isValid(C))throw new Error("bad point: is not on curve, wrong x");let B=E(C),_;try{_=n.sqrt(B)}catch($){let F=$ instanceof Error?": "+$.message:"";throw new Error("bad point: is not on curve, sqrt error"+F)}d();let K=n.isOdd(_);return(v&1)===1!==K&&(_=n.neg(_)),{x:C,y:_}}else if(y===m&&v===4){let C=n.BYTES,B=n.fromBytes(I.subarray(0,C)),_=n.fromBytes(I.subarray(C,C*2));if(!S(B,_))throw new Error("bad point: is not on curve");return{x:B,y:_}}else throw new Error(`bad point: got length ${y}, expected compressed=${g} or uncompressed=${m}`)}let h=t.toBytes||l,p=t.fromBytes||f;function E(D){let g=n.sqr(D),m=n.mul(g,D);return n.add(n.add(m,n.mul(D,s.a)),s.b)}function S(D,g){let m=n.sqr(g),y=E(D);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,cn),Lf),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(D,g,m=!1){if(!n.isValid(g)||m&&n.is0(g))throw new Error(`bad point coordinate ${D}`);return g}function L(D){if(!(D instanceof x))throw new Error("ProjectivePoint expected")}function P(D){if(!c||!c.basises)throw new Error("no endo");return _f(D,c.basises,o.ORDER)}let M=Me((D,g)=>{let{X:m,Y:y,Z:v}=D;if(n.eql(v,n.ONE))return{x:m,y};let I=D.is0();g==null&&(g=I?n.ONE:n.inv(v));let C=n.mul(m,g),B=n.mul(y,g),_=n.mul(v,g);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:C,y:B}}),U=Me(D=>{if(D.is0()){if(t.allowInfinityPoint&&!n.is0(D.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:m}=D.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(!D.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function k(D,g,m,y,v){return m=new x(n.mul(m.X,D),m.Y,m.Z),g=lr(y,g),m=lr(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(p(vt(g,void 0,"point")));return m.assertValidity(),m}static fromHex(g){return x.fromBytes(V("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,m=!0){return R.createCache(this,g),m||this.multiply(cn),this}assertValidity(){U(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:I,Y:C,Z:B}=g,_=n.eql(n.mul(m,B),n.mul(I,v)),K=n.eql(n.mul(y,B),n.mul(C,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,cn),{X:v,Y:I,Z:C}=this,B=n.ZERO,_=n.ZERO,K=n.ZERO,N=n.mul(v,v),$=n.mul(I,I),F=n.mul(C,C),O=n.mul(v,I);return O=n.add(O,O),K=n.mul(v,C),K=n.add(K,K),B=n.mul(g,K),_=n.mul(y,F),_=n.add(B,_),B=n.sub($,_),_=n.add($,_),_=n.mul(B,_),B=n.mul(O,B),K=n.mul(y,K),F=n.mul(g,F),O=n.sub(N,F),O=n.mul(g,O),O=n.add(O,K),K=n.add(N,N),N=n.add(K,N),N=n.add(N,F),N=n.mul(N,O),_=n.add(_,N),F=n.mul(I,C),F=n.add(F,F),N=n.mul(F,O),B=n.sub(B,N),K=n.mul(F,$),K=n.add(K,K),K=n.add(K,K),new x(B,_,K)}add(g){L(g);let{X:m,Y:y,Z:v}=this,{X:I,Y:C,Z:B}=g,_=n.ZERO,K=n.ZERO,N=n.ZERO,$=s.a,F=n.mul(s.b,cn),O=n.mul(m,I),X=n.mul(y,C),et=n.mul(v,B),mt=n.add(m,y),j=n.add(I,C);mt=n.mul(mt,j),j=n.add(O,X),mt=n.sub(mt,j),j=n.add(m,v);let it=n.add(I,B);return j=n.mul(j,it),it=n.add(O,et),j=n.sub(j,it),it=n.add(y,v),_=n.add(C,B),it=n.mul(it,_),_=n.add(X,et),it=n.sub(it,_),N=n.mul($,j),_=n.mul(F,et),N=n.add(_,N),_=n.sub(X,N),N=n.add(X,N),K=n.mul(_,N),X=n.add(O,O),X=n.add(X,O),et=n.mul($,et),j=n.mul(F,j),X=n.add(X,et),et=n.sub(O,et),et=n.mul($,et),j=n.add(j,et),O=n.mul(X,j),K=n.add(K,O),O=n.mul(it,j),_=n.mul(mt,_),_=n.sub(_,O),O=n.mul(mt,X),N=n.mul(it,N),N=n.add(N,O),new x(_,K,N)}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,I=C=>R.cached(this,C,B=>Yt(x,B));if(m){let{k1neg:C,k1:B,k2neg:_,k2:K}=P(g),{p:N,f:$}=I(B),{p:F,f:O}=I(K);v=$.add(O),y=k(m.beta,N,F,C,_)}else{let{p:C,f:B}=I(g);y=C,v=B}return Yt(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===Jt||y.is0())return x.ZERO;if(g===Ze)return y;if(R.hasCache(this))return this.multiply(g);if(m){let{k1neg:v,k1:I,k2neg:C,k2:B}=P(g),{p1:_,p2:K}=qi(x,y,I,B);return k(m.beta,_,K,v,C)}else return R.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 M(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return i===Ze?!0:g?g(x,this):R.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===Ze?this:g?g(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return zt(g,"isCompressed"),this.assertValidity(),h(x,this,g)}toHex(g=!0){return Bt(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 Yt(x,g)}static msm(g,m){return He(x,o,g,m)}static fromPrivateKey(g){return x.BASE.multiply(Ge(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,R=new qe(x,t.endo?Math.ceil(T/2):T);return x.BASE.precompute(8),x}function ma(e){return Uint8Array.of(e?2:3)}function ya(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Df(e,t={}){let{Fn:r}=e,n=t.randomBytes||oe,o=Object.assign(ya(e.Fp,r),{seed:xo(r.ORDER)});function s(h){try{return!!Ge(r,h)}catch{return!1}}function i(h,p){let{publicKey:E,publicKeyUncompressed:S}=o;try{let b=h.length;return p===!0&&b!==E||p===!1&&b!==S?!1:!!e.fromBytes(h)}catch{return!1}}function a(h=n(o.seed)){return Eo(vt(h,o.seed,"seed"),r.ORDER)}function c(h,p=!0){return e.BASE.multiply(Ge(r,h)).toBytes(p)}function u(h){let p=a(h);return{secretKey:p,publicKey:c(p)}}function d(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let{secretKey:p,publicKey:E,publicKeyUncompressed:S}=o;if(r.allowedLengths||p===E)return;let b=V("key",h).length;return b===E||b===S}function l(h,p,E=!0){if(d(h)===!0)throw new Error("first arg must be private key");if(d(p)===!1)throw new Error("second arg must be public key");let S=Ge(r,h);return e.fromHex(p).multiply(S).toBytes(E)}return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:h=>Ge(r,h),precompute(h=8,p=e.BASE){return p.precompute(h,!1)}},lengths:o})}function Cf(e,t,r={}){Hr(t),ue(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||oe,o=r.hmac||((m,...y)=>cs(t,m,ht(...y))),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:h}=Df(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function S(m){let y=a>>Ze;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){fs(y);let v=h.signature,I=y==="compact"?v:y==="recovered"?v+1:void 0;return vt(m,I,`${y} signature`)}class w{constructor(y,v,I){this.r=b("r",y),this.s=b("s",v),I!=null&&(this.recovery=I),Object.freeze(this)}static fromBytes(y,v=E){A(y,v);let I;if(v==="der"){let{r:K,s:N}=Wt.toSig(vt(y));return new w(K,N)}v==="recovered"&&(I=y[0],v="compact",y=y.subarray(1));let C=i.BYTES,B=y.subarray(0,C),_=y.subarray(C,C*2);return new w(i.fromBytes(B),i.fromBytes(_),I)}static fromHex(y,v){return this.fromBytes(be(y),v)}addRecoveryBit(y){return new w(this.r,this.s,y)}recoverPublicKey(y){let v=s.ORDER,{r:I,s:C,recovery:B}=this;if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");if(a*pa<v&&B>1)throw new Error("recovery id is ambiguous for h>1 curve");let K=B===2||B===3?I+a:I;if(!s.isValid(K))throw new Error("recovery id 2 or 3 invalid");let N=s.toBytes(K),$=e.fromBytes(ht(ma((B&1)===0),N)),F=i.inv(K),O=P(V("msgHash",y)),X=i.create(-O*F),et=i.create(C*F),mt=e.BASE.multiplyUnsafe(X).add($.multiplyUnsafe(et));if(mt.is0())throw new Error("point at infinify");return mt.assertValidity(),mt}hasHighS(){return S(this.s)}toBytes(y=E){if(fs(y),y==="der")return be(Wt.hexFromSig(this));let v=i.toBytes(this.r),I=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,I)}return ht(v,I)}toHex(y){return Bt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return w.fromBytes(V("sig",y),"compact")}static fromDER(y){return w.fromBytes(V("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 Bt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Bt(this.toBytes("compact"))}}let L=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let v=Ue(y),I=y.length*8-c;return I>0?v>>BigInt(I):v},P=r.bits2int_modN||function(y){return i.create(L(y))},M=ce(c);function U(m){return ur("num < 2^"+c,m,Jt,M),i.toBytes(m)}function k(m,y){return vt(m,void 0,"message"),y?vt(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:I,prehash:C,extraEntropy:B}=us(v,p);m=k(m,C);let _=P(m),K=Ge(i,y),N=[U(K),U(_)];if(B!=null&&B!==!1){let X=B===!0?n(h.secretKey):B;N.push(V("extraEntropy",X))}let $=ht(...N),F=_;function O(X){let et=L(X);if(!i.isValidNot0(et))return;let mt=i.inv(et),j=e.BASE.multiply(et).toAffine(),it=i.create(j.x);if(it===Jt)return;let Kr=i.create(mt*i.create(F+it*K));if(Kr===Jt)return;let Ls=(j.x===it?0:2)|Number(j.y&Ze),Ts=Kr;return I&&S(Kr)&&(Ts=i.neg(Kr),Ls^=1),new w(it,Ts,Ls)}return{seed:$,k2sig:O}}function T(m,y,v={}){m=V("message",m);let{seed:I,k2sig:C}=x(m,y,v);return Ai(t.outputLen,i.BYTES,o)(I,C)}function R(m){let y,v=typeof m=="string"||Ht(m),I=!v&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!v&&!I)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(I)y=new w(m.r,m.s);else if(v){try{y=w.fromBytes(V("sig",m),"der")}catch(C){if(!(C instanceof Wt.Err))throw C}if(!y)try{y=w.fromBytes(V("sig",m),"compact")}catch{return!1}}return y||!1}function D(m,y,v,I={}){let{lowS:C,prehash:B,format:_}=us(I,p);if(v=V("publicKey",v),y=k(V("message",y),B),"strict"in I)throw new Error("options.strict was renamed to lowS");let K=_===void 0?R(m):w.fromBytes(V("sig",m),_);if(K===!1)return!1;try{let N=e.fromBytes(v);if(C&&K.hasHighS())return!1;let{r:$,s:F}=K,O=P(y),X=i.inv(F),et=i.create(O*X),mt=i.create($*X),j=e.BASE.multiplyUnsafe(et).add(N.multiplyUnsafe(mt));return j.is0()?!1:i.create(j.x)===$}catch{return!1}}function g(m,y,v={}){let{prehash:I}=us(v,p);return y=k(y,I),w.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:h,Point:e,sign:T,verify:D,recoverPublicKey:g,Signature:w,hash:t})}function Pf(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=At(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 Kf(e){let{CURVE:t,curveOpts:r}=Pf(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 kf(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,$r(r.Fn.ORDER,r.Fn.BITS))})}function ba(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=Kf(e),s=Tf(t,r),i=Cf(s,n,o);return kf(e,i)}function ga(e,t){let r=n=>ba({...e,hash:n});return{...r(t),create:r}}var ds={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Rf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var wa=BigInt(2);function Nf(e){let t=ds.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,d=u*u*e%t,l=G(d,r,t)*d%t,f=G(l,r,t)*d%t,h=G(f,wa,t)*u%t,p=G(h,o,t)*h%t,E=G(p,s,t)*p%t,S=G(E,a,t)*E%t,b=G(S,c,t)*S%t,A=G(b,a,t)*E%t,w=G(A,r,t)*d%t,L=G(w,i,t)*p%t,P=G(L,n,t)*u%t,M=G(P,wa,t);if(!hs.eql(hs.sqr(M),e))throw new Error("Cannot find square root");return M}var hs=At(ds.p,{sqrt:Nf}),Ye=ga({...ds,Fp:hs,lowS:!0,endo:Rf},Gr);function xa(e,t,r,n){let o=me.digest(r instanceof Uint8Array?r:r.subarray());if(Qr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ye.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new dr(String(s))});try{return n?.signal?.throwIfAborted(),Ye.verify(t,o.digest,e)}catch(s){throw new dr(String(s))}}var un=class{type="secp256k1";raw;_key;constructor(t){this._key=Sa(t),this.raw=Ea(this._key)}toMultihash(){return Dt.digest(Ot(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Y.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 xa(this._key,r,t,n)}};function ps(e){return new un(e)}function Ea(e){return Ye.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Sa(e){try{return Ye.ProjectivePoint.fromHex(e),e}catch(t){throw new _e(String(t))}}function ms(e,t){let{Type:r,Data:n}=Rt.decode(e),o=n??new Uint8Array;switch(r){case tt.RSA:return ss(o,t);case tt.Ed25519:return Po(o);case tt.secp256k1:return ps(o);case tt.ECDSA:return so(o);default:throw new de}}function va(e){let{Type:t,Data:r}=Rt.decode(e.digest),n=r??new Uint8Array;switch(t){case tt.Ed25519:return Po(n);case tt.secp256k1:return ps(n);case tt.ECDSA:return so(n);default:throw new de}}function Ot(e){return Rt.encode({Type:tt[e.type],Data:e.raw})}var Aa=Symbol.for("nodejs.util.inspect.custom"),Uf=114,gr=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()})`}[Cn]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Uf,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")}[Aa](){return`PeerId(${this.toString()})`}},wr=class extends gr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},xr=class extends gr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Er=class extends gr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Mf=2336,fn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Dt.digest(z(this.url))}[Aa](){return`PeerId(${this.url})`}[Cn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Mf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};function ys(e){if(e.type==="Ed25519")return new xr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Er({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new wr({multihash:e.toCID().multihash,publicKey:e});throw new de}function Ia(e){return ys(e.publicKey)}function Sr(e){if(qf(e))return new wr({multihash:e});if(Of(e))try{let t=va(e);if(t.type==="Ed25519")return new xr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Er({multihash:e,publicKey:t})}catch{let r=H(e.digest);return new fn(new URL(r))}throw new Rr("Supplied PeerID Multihash is invalid")}function Of(e){return e.code===Dt.code}function qf(e){return e.code===me.code}function Ae(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 ln(e){let t=ee(Y.decode(`z${e}`));return Sr(t)}var vr=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 Ae(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 Ae(this.map.values(),t=>t.key)}values(){return Ae(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Ar=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 Ae(this.set.entries(),t=>{let r=ln(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=ln(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ae(this.set.values(),t=>ln(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 Qt(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var hn=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}},$e=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new hn(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 hn(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 bs=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function dn(e={}){return Hf(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 Hf(e,t){t=t??{};let r=t.onEnd,n=new $e,o,s,i,a=Qt(),c=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(()=>{a.resolve(),a=Qt()})}},u=S=>s!=null?s(S):(n.push(S),o),d=S=>(n=new $e,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 u({done:!1,value:S})},f=S=>i?o:(i=!0,S!=null?d(S):u({done:!0})),h=()=>(n=new $e,f(),{done:!0}),p=S=>(f(S),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:p,push:l,end:f,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,P)=>{w=()=>{P(new bs)},b.addEventListener("abort",w)}));try{await Promise.race([a.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 pn=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 Ba(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new pn(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new pn(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 gs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Qt(),this.haveNext=Qt()}[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=Qt(),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=Qt(),await Ba(this.readNext.promise,r?.signal,r)}};function _a(){return new gs}function Vf(e){return e[Symbol.asyncIterator]!=null}async function Ff(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*zf(e){let t=new AbortController,r=_a();Ff(e,r,t.signal).catch(()=>{});try{yield*r}finally{t.abort()}}function*Gf(e){for(let t of e)yield*t}function Zf(...e){let t=[];for(let r of e)Vf(r)||t.push(r);return t.length===e.length?Gf(t):zf(e)}var La=Zf;function Ir(e,...t){if(e==null)throw new Error("Empty pipeline");if(ws(e)){let n=e;e=()=>n.source}else if(Da(e)||Ta(e)){let n=e;e=()=>n}let r=[e,...t];if(r.length>1&&ws(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++)ws(r[n])&&(r[n]=$f(r[n]));return Yf(...r)}var Yf=(...e)=>{let t;for(;e.length>0;)t=e.shift()(t);return t},Ta=e=>e?.[Symbol.asyncIterator]!=null,Da=e=>e?.[Symbol.iterator]!=null,ws=e=>e==null?!1:e.sink!=null&&e.source!=null,$f=e=>t=>{let r=e.sink(t);if(r?.then!=null){let n=dn({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=e.source;if(Ta(s))o=async function*(){yield*s,n.end()};else if(Da(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return La(n,o())}return e.source};var Es=Qa(Pa(),1);var _r=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Ss=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Ka=e=>globalThis.DOMException===void 0?new Ss(e):new DOMException(e),ka=e=>{let t=e.reason===void 0?Ka("This operation was aborted."):e.reason;return t instanceof Error?t:Ka(t)};function vs(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,u=new Promise((d,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(ka(h)),a=()=>{l(ka(h))},h.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(d,l);return}let f=new _r;i=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(h){l(h)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?d():o instanceof Error?l(o):(f.message=o??`Promise timed out after ${r} milliseconds`,l(f))},r),(async()=>{try{d(await e)}catch(h){l(h)}})()}).finally(()=>{u.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}function As(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 Lr=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=As(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 Tr=class extends Es.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:Lr,...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#I(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=vs(Promise.resolve(s),{milliseconds:r.timeout})),r.signal&&(s=Promise.race([s,this.#I(r.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof _r&&!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 Ra(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 Na(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}function Ua(e,t){let r=Ra(e).return?.();Na(r)&&r.catch(n=>{t.error("could not cause iterator to return",n)})}var yn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Xe=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},bn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Dr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function gn(e){return e[Symbol.asyncIterator]!=null}function Ma(e,t){if(e.byteLength>t)throw new Xe("Message length too long")}var xn=e=>{let t=Pt(e),r=ct(t);return $i(e,r),xn.bytes=t,r};xn.bytes=0;function En(e,t){t=t??{};let r=t.lengthEncoder??xn,n=t?.maxDataLength??4194304;function*o(s){Ma(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return gn(e)?async function*(){for await(let s of e)yield*o(s)}():function*(){for(let s of e)yield*o(s)}()}En.single=(e,t)=>{t=t??{};let r=t.lengthEncoder??xn,n=t?.maxDataLength??4194304;return Ma(e,n),new rt(r(e.byteLength),e)};var Ie;(function(e){e[e.LENGTH=0]="LENGTH",e[e.DATA=1]="DATA"})(Ie||(Ie={}));var Is=e=>{let t=Xi(e);return Is.bytes=Pt(t),t};Is.bytes=0;function Cr(e,t){let r=new rt,n=Ie.LENGTH,o=-1,s=t?.lengthDecoder??Is,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;r.byteLength>0;){if(n===Ie.LENGTH)try{if(o=s(r),o<0)throw new yn("Invalid message length");if(o>a)throw new Xe("Message length too long");let u=s.bytes;r.consume(u),t?.onLength!=null&&t.onLength(o),n=Ie.DATA}catch(u){if(u instanceof RangeError){if(r.byteLength>i)throw new bn("Message length length too long");break}throw u}if(n===Ie.DATA){if(r.byteLength<o)break;let u=r.sublist(0,o);r.consume(o),t?.onData!=null&&t.onData(u),yield u,n=Ie.LENGTH}}}return gn(e)?async function*(){for await(let u of e)r.append(u),yield*c();if(r.byteLength>0)throw new Dr("Unexpected end of input")}():function*(){for(let u of e)r.append(u),yield*c();if(r.byteLength>0)throw new Dr("Unexpected end of input")}()}Cr.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 Cr(n,{...t??{},onLength:s=>{r=s}})};var Sn=class extends Le{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=()=>{Ua(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=Ir(this._rawInboundStream,o=>Cr(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=dn({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"))}}),Ir(this.outboundStream,n=>En(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 Oa(){return BigInt(`0x${H(on(8),"base16")}`)}var qa=(e,t)=>{let r=z(t.toString(16).padStart(16,"0"),"base16"),n=Ot(e),o=new Uint8Array(n.byteLength+r.length);return o.set(n,0),o.set(r,n.byteLength),o},Ha=e=>me.encode(e);var Va=function(e){return Array.isArray(e)?e:[e]},Qf=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=Sr(ee(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return ys(ms(r)).equals(t)}return!1},Fa=async e=>{if(e.from==null)throw new Q("RPC message was missing from");if(!await Qf(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=Sr(ee(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:el(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?ms(r):r}},Pr=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:tl(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Ot(e.key):void 0}:{data:e.data,topic:e.topic},tl=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),z(t,"base16")},el=e=>BigInt(`0x${H(e,"base16")}`);var za=z("libp2p-pubsub:");async function Ga(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Ia(e)},o=pe([za,r(Pr(n)).subarray()]);return n.signature=await e.sign(o),n.key=e.publicKey,n}async function Za(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=pe([za,t({...Pr(e),signature:void 0,key:void 0}).subarray()]);return rl(e).verify(r,e.signature)}function rl(e){if(e.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(e.from==null)throw new Error("Could not get the public key from the originator id");if(e.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 vn=class extends Le{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:a=10,maxInboundStreams:c=1,maxOutboundStreams:u=1}=r;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=Va(n),this.enabled=r.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new vr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new Tr({concurrency:a}),this.maxInboundStreams=c,this.maxOutboundStreams=u,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(a=>{this.log(a)})}_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 Sn(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 Ir(r,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,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: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 Fa(i);await this.processMessage(t,a)}catch(a){this.log.error(a)}})).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 Ar,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 qa(t.key,t.sequenceNumber);case"StrictNoSign":return Ha(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(Pr)})}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 Za(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===je.Reject||s===je.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Ga(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 Nr("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:Oa()};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())}};var An=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,r){this.entries.set(t,{value:r,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[r,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(r);else break}}has(t){return this.entries.has(t)}get(t){let r=this.entries.get(t);return r!=null&&r.validUntilMs>=Date.now()?r.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var Bs="/floodsub/1.0.0";var Be;(function(e){let t;(function(o){let s;o.codec=()=>(s==null&&(s=St((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.subscribe!=null&&(a.uint32(8),a.bool(i.subscribe)),i.topic!=null&&(a.uint32(18),a.string(i.topic)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let l=i.uint32();switch(l>>>3){case 1:{u.subscribe=i.bool();break}case 2:{u.topic=i.string();break}default:{i.skipType(l&7);break}}}return u})),s),o.encode=i=>Et(i,o.codec()),o.decode=(i,a)=>xt(i,o.codec(),a)})(t=e.SubOpts||(e.SubOpts={}));let r;(function(o){let s;o.codec=()=>(s==null&&(s=St((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.from!=null&&(a.uint32(10),a.bytes(i.from)),i.data!=null&&(a.uint32(18),a.bytes(i.data)),i.sequenceNumber!=null&&(a.uint32(26),a.bytes(i.sequenceNumber)),i.topic!=null&&(a.uint32(34),a.string(i.topic)),i.signature!=null&&(a.uint32(42),a.bytes(i.signature)),i.key!=null&&(a.uint32(50),a.bytes(i.key)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let l=i.uint32();switch(l>>>3){case 1:{u.from=i.bytes();break}case 2:{u.data=i.bytes();break}case 3:{u.sequenceNumber=i.bytes();break}case 4:{u.topic=i.string();break}case 5:{u.signature=i.bytes();break}case 6:{u.key=i.bytes();break}default:{i.skipType(l&7);break}}}return u})),s),o.encode=i=>Et(i,o.codec()),o.decode=(i,a)=>xt(i,o.codec(),a)})(r=e.Message||(e.Message={}));let n;e.codec=()=>(n==null&&(n=St((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.subscriptions!=null)for(let a of o.subscriptions)s.uint32(10),e.SubOpts.codec().encode(a,s);if(o.messages!=null)for(let a of o.messages)s.uint32(18),e.Message.codec().encode(a,s);o.control!=null&&(s.uint32(26),In.codec().encode(o.control,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={subscriptions:[],messages:[]},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{if(i.limits?.subscriptions!=null&&a.subscriptions.length===i.limits.subscriptions)throw new Lt('Decode error - map field "subscriptions" had too many elements');a.subscriptions.push(e.SubOpts.codec().decode(o,o.uint32(),{limits:i.limits?.subscriptions$}));break}case 2:{if(i.limits?.messages!=null&&a.messages.length===i.limits.messages)throw new Lt('Decode error - map field "messages" had too many elements');a.messages.push(e.Message.codec().decode(o,o.uint32(),{limits:i.limits?.messages$}));break}case 3:{a.control=In.codec().decode(o,o.uint32(),{limits:i.limits?.control});break}default:{o.skipType(u&7);break}}}return a})),n),e.encode=o=>Et(o,e.codec()),e.decode=(o,s)=>xt(o,e.codec(),s)})(Be||(Be={}));var In;(function(e){let t;e.codec=()=>(t==null&&(t=St((r,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),r.ihave!=null)for(let s of r.ihave)n.uint32(10),Bn.codec().encode(s,n);if(r.iwant!=null)for(let s of r.iwant)n.uint32(18),_n.codec().encode(s,n);if(r.graft!=null)for(let s of r.graft)n.uint32(26),Ln.codec().encode(s,n);if(r.prune!=null)for(let s of r.prune)n.uint32(34),Tn.codec().encode(s,n);o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={ihave:[],iwant:[],graft:[],prune:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{if(o.limits?.ihave!=null&&s.ihave.length===o.limits.ihave)throw new Lt('Decode error - map field "ihave" had too many elements');s.ihave.push(Bn.codec().decode(r,r.uint32(),{limits:o.limits?.ihave$}));break}case 2:{if(o.limits?.iwant!=null&&s.iwant.length===o.limits.iwant)throw new Lt('Decode error - map field "iwant" had too many elements');s.iwant.push(_n.codec().decode(r,r.uint32(),{limits:o.limits?.iwant$}));break}case 3:{if(o.limits?.graft!=null&&s.graft.length===o.limits.graft)throw new Lt('Decode error - map field "graft" had too many elements');s.graft.push(Ln.codec().decode(r,r.uint32(),{limits:o.limits?.graft$}));break}case 4:{if(o.limits?.prune!=null&&s.prune.length===o.limits.prune)throw new Lt('Decode error - map field "prune" had too many elements');s.prune.push(Tn.codec().decode(r,r.uint32(),{limits:o.limits?.prune$}));break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(In||(In={}));var Bn;(function(e){let t;e.codec=()=>(t==null&&(t=St((r,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),r.topic!=null&&(n.uint32(10),n.string(r.topic)),r.messageIDs!=null)for(let s of r.messageIDs)n.uint32(18),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={messageIDs:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.topic=r.string();break}case 2:{if(o.limits?.messageIDs!=null&&s.messageIDs.length===o.limits.messageIDs)throw new Lt('Decode error - map field "messageIDs" had too many elements');s.messageIDs.push(r.bytes());break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(Bn||(Bn={}));var _n;(function(e){let t;e.codec=()=>(t==null&&(t=St((r,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),r.messageIDs!=null)for(let s of r.messageIDs)n.uint32(10),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={messageIDs:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{if(o.limits?.messageIDs!=null&&s.messageIDs.length===o.limits.messageIDs)throw new Lt('Decode error - map field "messageIDs" had too many elements');s.messageIDs.push(r.bytes());break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(_n||(_n={}));var Ln;(function(e){let t;e.codec=()=>(t==null&&(t=St((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.topic!=null&&(n.uint32(10),n.string(r.topic)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.topic=r.string();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(Ln||(Ln={}));var Tn;(function(e){let t;e.codec=()=>(t==null&&(t=St((r,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),r.topic!=null&&(n.uint32(10),n.string(r.topic)),r.peers!=null)for(let s of r.peers)n.uint32(18),Dn.codec().encode(s,n);r.backoff!=null&&(n.uint32(24),n.uint64(r.backoff)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={peers:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.topic=r.string();break}case 2:{if(o.limits?.peers!=null&&s.peers.length===o.limits.peers)throw new Lt('Decode error - map field "peers" had too many elements');s.peers.push(Dn.codec().decode(r,r.uint32(),{limits:o.limits?.peers$}));break}case 3:{s.backoff=r.uint64();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(Tn||(Tn={}));var Dn;(function(e){let t;e.codec=()=>(t==null&&(t=St((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.peerID!=null&&(n.uint32(10),n.bytes(r.peerID)),r.signedPeerRecord!=null&&(n.uint32(18),n.bytes(r.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.peerID=r.bytes();break}case 2:{s.signedPeerRecord=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(Dn||(Dn={}));var _s=class extends vn{seenCache;constructor(t,r){super(t,{...r,canRelayMessage:!0,multicodecs:[Bs]}),this.log=t.logger.forComponent("libp2p:floodsub"),this.seenCache=new An({validityMs:r?.seenTTL??3e4})}[Cs]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[Ps]=["@libp2p/pubsub"];[Ks]=["@libp2p/identify"];decodeRpc(t){return Be.decode(t)}encodeRpc(t){return Be.encode(t)}decodeMessage(t){return Be.Message.decode(t)}encodeMessage(t){return Be.Message.encode(t)}async processMessage(t,r){let n=await super.getMsgId(r),o=H(n,"base64");this.seenCache.has(o)||(this.seenCache.put(o,!0),await super.processMessage(t,r))}async publishMessage(t,r){let n=this.getSubscribers(r.topic),o=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:o}):(n.forEach(s=>{if(this.components.peerId.equals(s)){this.log("not sending message on topic %s to myself",r.topic);return}if(s.equals(t)){this.log("not sending message on topic %s to sender %p",r.topic,s);return}this.log("publish msgs on topics %s %p",r.topic,s),o.push(s),this.send(s,{messages:[r]})}),{recipients:o})}};function nl(e={}){return t=>new _s(t,e)}return tc(ol);})();
2
+ "use strict";var Libp2PFloodsub=(()=>{var Ya=Object.create;var kr=Object.defineProperty;var Xa=Object.getOwnPropertyDescriptor;var ja=Object.getOwnPropertyNames;var Wa=Object.getPrototypeOf,Ja=Object.prototype.hasOwnProperty;var Qa=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yt=(e,t)=>{for(var r in t)kr(e,r,{get:t[r],enumerable:!0})},Ds=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ja(t))!Ja.call(e,o)&&o!==r&&kr(e,o,{get:()=>t[o],enumerable:!(n=Xa(t,o))||n.enumerable});return e};var tc=(e,t,r)=>(r=e!=null?Ya(Wa(e)):{},Ds(t||!e||!e.__esModule?kr(r,"default",{value:e,enumerable:!0}):r,e)),ec=e=>Ds(kr({},"__esModule",{value:!0}),e);var Ka=Qa((ny,xs)=>{"use strict";var Wf=Object.prototype.hasOwnProperty,pt="~";function Br(){}Object.create&&(Br.prototype=Object.create(null),new Br().__proto__||(pt=!1));function Jf(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function Pa(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new Jf(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 mn(e,t){--e._eventsCount===0?e._events=new Br:delete e._events[t]}function lt(){this._events=new Br,this._eventsCount=0}lt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)Wf.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 a=pt?pt+t:t;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,d,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,o),!0;case 5:return c.fn.call(c.context,r,n,o,s),!0;case 6:return c.fn.call(c.context,r,n,o,s,i),!0}for(l=1,d=new Array(u-1);l<u;l++)d[l-1]=arguments[l];c.fn.apply(c.context,d)}else{var f=c.length,h;for(l=0;l<f;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),u){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,r);break;case 3:c[l].fn.call(c[l].context,r,n);break;case 4:c[l].fn.call(c[l].context,r,n,o);break;default:if(!d)for(h=1,d=new Array(u-1);h<u;h++)d[h-1]=arguments[h];c[l].fn.apply(c[l].context,d)}}return!0};lt.prototype.on=function(t,r,n){return Pa(this,t,r,n,!1)};lt.prototype.once=function(t,r,n){return Pa(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 mn(this,s),this;var i=this._events[s];if(i.fn)i.fn===r&&(!o||i.once)&&(!n||i.context===n)&&mn(this,s);else{for(var a=0,c=[],u=i.length;a<u;a++)(i[a].fn!==r||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:mn(this,s)}return this};lt.prototype.removeAllListeners=function(t){var r;return t?(r=pt?pt+t:t,this._events[r]&&mn(this,r)):(this._events=new Br,this._eventsCount=0),this};lt.prototype.off=lt.prototype.removeListener;lt.prototype.addListener=lt.prototype.on;lt.prefixed=pt;lt.EventEmitter=lt;typeof xs<"u"&&(xs.exports=lt)});var il={};yt(il,{floodsub:()=>sl,multicodec:()=>Bs});var Cn=Symbol.for("@libp2p/peer-id");var je;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(je||(je={}));var Cs=Symbol.for("@libp2p/pubsub");var Z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},_e=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Rr=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 Nr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var de=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Le=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){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 Ps=Symbol.for("@libp2p/service-capabilities"),Ks=Symbol.for("@libp2p/service-dependencies");var Nn={};yt(Nn,{base58btc:()=>$,base58flickr:()=>cc});var Kl=new Uint8Array(0);function ks(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Nt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Rs(e){return new TextEncoder().encode(e)}function Ns(e){return new TextDecoder().decode(e)}function rc(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 a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var E=0,S=0,b=0,A=p.length;b!==A&&p[b]===0;)b++,E++;for(var w=(A-b)*d+1>>>0,L=new Uint8Array(w);b!==A;){for(var P=p[b],M=0,U=w-1;(P!==0||M<S)&&U!==-1;U--,M++)P+=256*L[U]>>>0,L[U]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");S=M,b++}for(var k=w-S;k!==w&&L[k]===0;)k++;for(var x=c.repeat(E);k<w;++k)x+=e.charAt(L[k]);return x}function f(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var E=0;if(p[E]!==" "){for(var S=0,b=0;p[E]===c;)S++,E++;for(var A=(p.length-E)*u+1>>>0,w=new Uint8Array(A);p[E];){var L=r[p.charCodeAt(E)];if(L===255)return;for(var P=0,M=A-1;(L!==0||P<b)&&M!==-1;M--,P++)L+=a*w[M]>>>0,w[M]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");b=P,E++}if(p[E]!==" "){for(var U=A-b;U!==A&&w[U]===0;)U++;for(var k=new Uint8Array(S+(A-U)),x=S;U!==A;)k[x++]=w[U++];return k}}}function h(p){var E=f(p);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:f,decode:h}}var nc=rc,oc=nc,Ms=oc;var Pn=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")}},Kn=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 Os(this,t)}},kn=class{decoders;constructor(t){this.decoders=t}or(t){return Os(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 Os(e,t){return new kn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Rn=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 Pn(t,r,n),this.decoder=new Kn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Te({name:e,prefix:t,encode:r,decode:n}){return new Rn(e,t,r,n)}function te({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ms(r,e);return Te({prefix:t,name:e,encode:n,decode:s=>Nt(o(s))})}function sc(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let d=t[e[u]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|d,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ic(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function ac(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=ac(n);return Te({prefix:t,name:e,encode(s){return ic(s,n,r)},decode(s){return sc(s,o,r,e)}})}var $=te({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),cc=te({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Un={};yt(Un,{base32:()=>De,base32hex:()=>hc,base32hexpad:()=>pc,base32hexpadupper:()=>mc,base32hexupper:()=>dc,base32pad:()=>fc,base32padupper:()=>lc,base32upper:()=>uc,base32z:()=>yc});var De=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),uc=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),fc=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),lc=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),hc=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),dc=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),pc=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),mc=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),yc=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Mn={};yt(Mn,{base36:()=>We,base36upper:()=>bc});var We=te({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),bc=te({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var gc=Vs,qs=128,wc=127,xc=~wc,Ec=Math.pow(2,31);function Vs(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Ec;)t[r++]=e&255|qs,e/=128;for(;e&xc;)t[r++]=e&255|qs,e>>>=7;return t[r]=e|0,Vs.bytes=r-n+1,t}var Sc=On,vc=128,Hs=127;function On(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw On.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Hs)<<o:(i&Hs)*Math.pow(2,o),o+=7}while(i>=vc);return On.bytes=s-n,r}var Ac=Math.pow(2,7),Ic=Math.pow(2,14),Bc=Math.pow(2,21),_c=Math.pow(2,28),Lc=Math.pow(2,35),Tc=Math.pow(2,42),Dc=Math.pow(2,49),Cc=Math.pow(2,56),Pc=Math.pow(2,63),Kc=function(e){return e<Ac?1:e<Ic?2:e<Bc?3:e<_c?4:e<Lc?5:e<Tc?6:e<Dc?7:e<Cc?8:e<Pc?9:10},kc={encode:gc,decode:Sc,encodingLength:Kc},Rc=kc,Je=Rc;function Qe(e,t=0){return[Je.decode(e,t),Je.decode.bytes]}function Ce(e,t,r=0){return Je.encode(e,t,r),t}function Pe(e){return Je.encodingLength(e)}function Kt(e,t){let r=t.byteLength,n=Pe(e),o=n+Pe(r),s=new Uint8Array(o+r);return Ce(e,s,0),Ce(r,s,n),s.set(t,o),new Ke(e,r,t,s)}function ee(e){let t=Nt(e),[r,n]=Qe(t),[o,s]=Qe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ke(r,o,i,t)}function Fs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ks(e.bytes,r.bytes)}}var Ke=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function zs(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Uc(r,qn(e),t??$.encoder);default:return Mc(r,qn(e),t??De.encoder)}}var Gs=new WeakMap;function qn(e){let t=Gs.get(e);if(t==null){let r=new Map;return Gs.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!==tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Oc)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=Kt(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&&Fs(t.multihash,n.multihash)}toString(t){return zs(this,t)}toJSON(){return{"/":zs(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??Zs(n,o,s.bytes))}else if(r[qc]===!0){let{version:n,multihash:o,code:s}=r,i=ee(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!==tr)throw new Error(`Version 0 CID must use dag-pb (code: ${tr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Zs(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,tr,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=Nt(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 Ke(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,f]=Qe(t.subarray(r));return r+=f,l},o=n(),s=tr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,d=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:u}}static parse(t,r){let[n,o]=Nc(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 qn(s).set(n,t),s}};function Nc(e,t){switch(e[0]){case"Q":{let r=t??$;return[$.prefix,r.decode(`${$.prefix}${e}`)]}case $.prefix:{let r=t??$;return[$.prefix,r.decode(e)]}case De.prefix:{let r=t??De;return[De.prefix,r.decode(e)]}case We.prefix:{let r=t??We;return[We.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 Uc(e,t,r){let{prefix:n}=r;if(n!==$.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 Mc(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 tr=112,Oc=18;function Zs(e,t,r){let n=Pe(e),o=n+Pe(t),s=new Uint8Array(o+r.byteLength);return Ce(e,s,0),Ce(t,s,n),s.set(r,o),s}var qc=Symbol.for("@ipld/js-cid/CID");var Hn={};yt(Hn,{identity:()=>Tt});var $s=0,Hc="identity",Ys=Nt;function Vc(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Kt($s,Ys(e))}var Tt={code:$s,name:Hc,encode:Ys,digest:Vc};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 Ut(e=0){return new Uint8Array(e)}function ct(e=0){return new Uint8Array(e)}function pe(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 js=Symbol.for("@achingbrain/uint8arraylist");function Xs(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 Mr(e){return!!e?.[js]}var rt=class e{bufs;length;[js]=!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(Mr(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(Mr(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=Xs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Xs(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(Mr(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 pe(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:pe(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],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,d=r>a&&r<=c;if(u&&d){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Mr(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 a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,d;for(let l=r;l<=c;l+=d){d=0;for(let f=u;f>=0;f--){let h=this.get(l+f);if(n[f]!==h){d=Math.max(1,f-a[h]);break}}if(d===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=Ut(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=Ut(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=Ut(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=Ut(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=Ut(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=Ut(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=Ut(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=Ut(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 Vn={};yt(Vn,{base10:()=>Fc});var Fc=te({prefix:"9",name:"base10",alphabet:"0123456789"});var Fn={};yt(Fn,{base16:()=>zc,base16upper:()=>Gc});var zc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Gc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var zn={};yt(zn,{base2:()=>Zc});var Zc=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Gn={};yt(Gn,{base256emoji:()=>Wc});var Ws=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}"),$c=Ws.reduce((e,t,r)=>(e[r]=t,e),[]),Yc=Ws.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Xc(e){return e.reduce((t,r)=>(t+=$c[r],t),"")}function jc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Yc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Wc=Te({prefix:"\u{1F680}",name:"base256emoji",encode:Xc,decode:jc});var Zn={};yt(Zn,{base64:()=>Jc,base64pad:()=>Qc,base64url:()=>tu,base64urlpad:()=>eu});var Jc=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),tu=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),eu=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var $n={};yt($n,{base8:()=>ru});var ru=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Yn={};yt(Yn,{identity:()=>nu});var nu=Te({prefix:"\0",name:"identity",encode:e=>Ns(e),decode:e=>Rs(e)});var yh=new TextEncoder,bh=new TextDecoder;var Wn={};yt(Wn,{sha256:()=>me,sha512:()=>au});var iu=20;function jn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Xn(e,t,r,n,o)}var Xn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??iu,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Js(n,this.code,r?.truncate):n.then(o=>Js(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Js(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Kt(t,e)}function ti(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var me=jn({name:"sha2-256",code:18,encode:ti("SHA-256")}),au=jn({name:"sha2-512",code:19,encode:ti("SHA-512")});var Jn={...Yn,...zn,...$n,...Vn,...Fn,...Un,...Mn,...Nn,...Zn,...Gn},Th={...Wn,...Hn};function ri(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ei=ri("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Qn=ri("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}),cu={utf8:ei,"utf-8":ei,hex:Jn.base16,latin1:Qn,ascii:Qn,binary:Qn,...Jn},Or=cu;function z(e,t="utf8"){let r=Or[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function H(e,t="utf8"){let r=Or[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var uu=parseInt("11111",2),to=parseInt("10000000",2),fu=parseInt("01111111",2),ni={0:er,1:er,2:lu,3:pu,4:mu,5:du,6:hu,16:er,22:er,48:er};function Mt(e,t={offset:0}){let r=e[t.offset]&uu;if(t.offset++,ni[r]!=null)return ni[r](e,t);throw new Error("No decoder for tag "+r)}function rr(e,t){let r=0;if((e[t.offset]&to)===to){let n=e[t.offset]&fu,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 er(e,t){rr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Mt(e,t);if(n===null)break;r.push(n)}return r}function lu(e,t){let r=rr(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 hu(e,t){let r=rr(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 a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let d=0;for(let l=0;l<c.length;l++)d+=c[l]<<l*7;a+=`.${d}`,c=[]}}return a}function du(e,t){return t.offset++,null}function pu(e,t){let r=rr(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 mu(e,t){let r=rr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function yu(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 eo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=yu(e.byteLength);return new rt(Uint8Array.from([t.byteLength|to]),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]),eo(t),t)}function qr(e){let t=Uint8Array.from([0]),r=new rt(t,e);return new rt(Uint8Array.from([3]),eo(r),r)}function ne(e,t=48){let r=new rt;for(let n of e)r.append(n);return new rt(Uint8Array.from([t]),eo(r),r)}async function oi(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 bu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),gu=Uint8Array.from([6,5,43,129,4,0,34]),wu=Uint8Array.from([6,5,43,129,4,0,35]),xu={ext:!0,kty:"EC",crv:"P-256"},Eu={ext:!0,kty:"EC",crv:"P-384"},Su={ext:!0,kty:"EC",crv:"P-521"},ro=32,no=48,oo=66;function so(e){let t=Mt(e);return si(t)}function si(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===ro*2+1)return n=H(t.subarray(r,r+ro),"base64url"),o=H(t.subarray(r+ro),"base64url"),new ke({...xu,key_ops:["verify"],x:n,y:o});if(t.byteLength===no*2+1)return n=H(t.subarray(r,r+no),"base64url"),o=H(t.subarray(r+no),"base64url"),new ke({...Eu,key_ops:["verify"],x:n,y:o});if(t.byteLength===oo*2+1)return n=H(t.subarray(r,r+oo),"base64url"),o=H(t.subarray(r+oo),"base64url"),new ke({...Su,key_ops:["verify"],x:n,y:o});throw new Z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ii(e){return ne([gt(Uint8Array.from([1])),ne([vu(e.crv)],160),ne([qr(new rt(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function vu(e){if(e==="P-256")return bu;if(e==="P-384")return gu;if(e==="P-521")return wu;throw new Z(`Invalid curve ${e}`)}var ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ii(this.jwk)),this._raw}toMultihash(){return Tt.digest(Ot(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return $.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 oi(this.jwk,r,t,n)}};var ye=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ht(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function nr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function wt(e,...t){if(!Ht(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 Hr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");nr(e.outputLen),nr(e.blockLen)}function Ne(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 ci(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 Vt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Vr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Dt(e,t){return e<<32-t|e>>>t}var ui=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Au=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Bt(e){if(wt(e),ui)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Au[e[r]];return t}var qt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ai(e){if(e>=qt._0&&e<=qt._9)return e-qt._0;if(e>=qt.A&&e<=qt.F)return e-(qt.A-10);if(e>=qt.a&&e<=qt.f)return e-(qt.a-10)}function be(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ui)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=ai(e.charCodeAt(s)),a=ai(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function io(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function or(e){return typeof e=="string"&&(e=io(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 Re=class{};function ao(e){let t=n=>e().update(or(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function oe(e=32){if(ye&&typeof ye.getRandomValues=="function")return ye.getRandomValues(new Uint8Array(e));if(ye&&typeof ye.randomBytes=="function")return Uint8Array.from(ye.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Iu(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),a=Number(r&s),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function fi(e,t,r){return e&t^~e&r}function li(e,t,r){return e&t^e&r^t&r}var sr=class extends Re{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=Vr(this.buffer)}update(t){Ne(this),t=or(t),wt(t);let{view:r,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=Vr(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(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ne(this),ci(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Vt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;Iu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Vr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,d[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:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ft=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 Fr=BigInt(4294967295),hi=BigInt(32);function Bu(e,t=!1){return t?{h:Number(e&Fr),l:Number(e>>hi&Fr)}:{h:Number(e>>hi&Fr)|0,l:Number(e&Fr)|0}}function di(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:a}=Bu(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var co=(e,t,r)=>e>>>r,uo=(e,t,r)=>e<<32-r|t>>>r,ge=(e,t,r)=>e>>>r|t<<32-r,we=(e,t,r)=>e<<32-r|t>>>r,ir=(e,t,r)=>e<<64-r|t>>>r-32,ar=(e,t,r)=>e>>>r-32|t<<64-r;function kt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var pi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),mi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,yi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),bi=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,gi=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),wi=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Lu=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]),se=new Uint32Array(64),zr=class extends sr{constructor(t=32){super(64,t,8,!1),this.A=Ft[0]|0,this.B=Ft[1]|0,this.C=Ft[2]|0,this.D=Ft[3]|0,this.E=Ft[4]|0,this.F=Ft[5]|0,this.G=Ft[6]|0,this.H=Ft[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){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=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)se[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let f=se[l-15],h=se[l-2],p=Dt(f,7)^Dt(f,18)^f>>>3,E=Dt(h,17)^Dt(h,19)^h>>>10;se[l]=E+se[l-7]+p+se[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:d}=this;for(let l=0;l<64;l++){let f=Dt(a,6)^Dt(a,11)^Dt(a,25),h=d+f+fi(a,c,u)+Lu[l]+se[l]|0,E=(Dt(n,2)^Dt(n,13)^Dt(n,22))+li(n,o,s)|0;d=u,u=c,c=a,a=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,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,u,d)}roundClean(){Vt(se)}destroy(){this.set(0,0,0,0,0,0,0,0),Vt(this.buffer)}};var xi=di(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Tu=xi[0],Du=xi[1],ie=new Uint32Array(80),ae=new Uint32Array(80),fo=class extends sr{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:a,Dl:c,Eh:u,El:d,Fh:l,Fl:f,Gh:h,Gl:p,Hh:E,Hl:S}=this;return[t,r,n,o,s,i,a,c,u,d,l,f,h,p,E,S]}set(t,r,n,o,s,i,a,c,u,d,l,f,h,p,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=a|0,this.Dl=c|0,this.Eh=u|0,this.El=d|0,this.Fh=l|0,this.Fl=f|0,this.Gh=h|0,this.Gl=p|0,this.Hh=E|0,this.Hl=S|0}process(t,r){for(let w=0;w<16;w++,r+=4)ie[w]=t.getUint32(r),ae[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let L=ie[w-15]|0,P=ae[w-15]|0,M=ge(L,P,1)^ge(L,P,8)^co(L,P,7),U=we(L,P,1)^we(L,P,8)^uo(L,P,7),k=ie[w-2]|0,x=ae[w-2]|0,T=ge(k,x,19)^ir(k,x,61)^co(k,x,6),R=we(k,x,19)^ar(k,x,61)^uo(k,x,6),D=yi(U,R,ae[w-7],ae[w-16]),g=bi(D,M,T,ie[w-7],ie[w-16]);ie[w]=g|0,ae[w]=D|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:d,Eh:l,El:f,Fh:h,Fl:p,Gh:E,Gl:S,Hh:b,Hl:A}=this;for(let w=0;w<80;w++){let L=ge(l,f,14)^ge(l,f,18)^ir(l,f,41),P=we(l,f,14)^we(l,f,18)^ar(l,f,41),M=l&h^~l&E,U=f&p^~f&S,k=gi(A,P,U,Du[w],ae[w]),x=wi(k,b,L,M,Tu[w],ie[w]),T=k|0,R=ge(n,o,28)^ir(n,o,34)^ir(n,o,39),D=we(n,o,28)^ar(n,o,34)^ar(n,o,39),g=n&s^n&a^s&a,m=o&i^o&c^i&c;b=E|0,A=S|0,E=h|0,S=p|0,h=l|0,p=f|0,{h:l,l:f}=kt(u|0,d|0,x|0,T|0),u=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let y=pi(T,D,m);n=mi(y,x,R,g),o=y|0}({h:n,l:o}=kt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=kt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=kt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:d}=kt(this.Dh|0,this.Dl|0,u|0,d|0),{h:l,l:f}=kt(this.Eh|0,this.El|0,l|0,f|0),{h,l:p}=kt(this.Fh|0,this.Fl|0,h|0,p|0),{h:E,l:S}=kt(this.Gh|0,this.Gl|0,E|0,S|0),{h:b,l:A}=kt(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,a,c,u,d,l,f,h,p,E,S,b,A)}roundClean(){Vt(ie,ae)}destroy(){Vt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Gr=ao(()=>new zr);var Ei=ao(()=>new fo);var po=BigInt(0),ho=BigInt(1);function zt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function vt(e,t,r=""){let n=Ht(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function cr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Si(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?po:BigInt("0x"+e)}function Ue(e){return Si(Bt(e))}function Gt(e){return wt(e),Si(Bt(Uint8Array.from(e).reverse()))}function Zr(e,t){return be(e.toString(16).padStart(t*2,"0"))}function mo(e,t){return Zr(e,t).reverse()}function V(e,t,r){let n;if(typeof t=="string")try{n=be(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ht(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 vi(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 yo(e){return Uint8Array.from(e)}var lo=e=>typeof e=="bigint"&&po<=e;function Ai(e,t,r){return lo(e)&&lo(t)&&lo(r)&&t<=e&&e<r}function ur(e,t,r,n){if(!Ai(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function $r(e){let t;for(t=0;e>po;e>>=ho,t+=1);return t}var ce=e=>(ho<<BigInt(e))-ho;function Ii(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),a=0,c=()=>{s.fill(1),i.fill(0),a=0},u=(...h)=>r(i,s,...h),d=(h=n(0))=>{i=u(o(0),h),s=u(),h.length!==0&&(i=u(o(1),h),s=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,p=[];for(;h<t;){s=u();let E=s.slice();p.push(E),h+=s.length}return ht(...p)};return(h,p)=>{c(),d(h);let E;for(;!(E=p(l()));)d();return c(),E}}function ue(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[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(r).forEach(([o,s])=>n(o,s,!0))}var bo=()=>{throw new Error("not implemented")};function Me(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),xe=BigInt(2),Li=BigInt(3),Ti=BigInt(4),Di=BigInt(5),Cu=BigInt(7),Ci=BigInt(8),Pu=BigInt(9),Pi=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 Bi(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,a=dt;for(;r!==dt;){let u=n/r,d=n%r,l=o-i*u,f=s-a*u;n=r,r=d,o=i,s=a,i=l,a=f}if(n!==nt)throw new Error("invert: does not exist");return J(o,t)}function go(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ki(e,t){let r=(e.ORDER+nt)/Ti,n=e.pow(t,r);return go(e,n,t),n}function Ku(e,t){let r=(e.ORDER-Di)/Ci,n=e.mul(t,xe),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,xe),o),a=e.mul(s,e.sub(i,e.ONE));return go(e,a,t),a}function ku(e){let t=At(e),r=ki(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Cu)/Pi;return(a,c)=>{let u=a.pow(c,i),d=a.mul(u,n),l=a.mul(u,o),f=a.mul(u,s),h=a.eql(a.sqr(d),c),p=a.eql(a.sqr(l),c);u=a.cmov(u,d,h),d=a.cmov(f,l,p);let E=a.eql(a.sqr(d),c),S=a.cmov(u,d,E);return go(a,S,c),S}}function ki(e){if(e<Li)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%xe===dt;)t/=xe,r++;let n=xe,o=At(e);for(;_i(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ki;let s=o.pow(n,t),i=(t+nt)/xe;return function(c,u){if(c.is0(u))return u;if(_i(c,u)!==1)throw new Error("Cannot find square root");let d=r,l=c.mul(c.ONE,s),f=c.pow(u,t),h=c.pow(u,i);for(;!c.eql(f,c.ONE);){if(c.is0(f))return c.ZERO;let p=1,E=c.sqr(f);for(;!c.eql(E,c.ONE);)if(p++,E=c.sqr(E),p===d)throw new Error("Cannot find square root");let S=nt<<BigInt(d-p-1),b=c.pow(l,S);d=p,l=c.sqr(b),f=c.mul(f,l),h=c.mul(h,b)}return h}}function Ru(e){return e%Ti===Li?Ki:e%Ci===Di?Ku:e%Pi===Pu?ku(e):ki(e)}var Zt=(e,t)=>(J(e,t)&nt)===nt,Nu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function wo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Nu.reduce((n,o)=>(n[o]="function",n),t);return ue(e,r),e}function Uu(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 fr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function _i(e,t){let r=(e.ORDER-nt)/xe,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 Yr(e,t){t!==void 0&&nr(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function At(e,t,r=!1,n={}){if(e<=dt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),a=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:u}=Yr(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,l=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:u,MASK:ce(c),ZERO:dt,ONE:nt,allowedLengths:a,create:f=>J(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return dt<=f&&f<e},is0:f=>f===dt,isValidNot0:f=>!l.is0(f)&&l.isValid(f),isOdd:f=>(f&nt)===nt,neg:f=>J(-f,e),eql:(f,h)=>f===h,sqr:f=>J(f*f,e),add:(f,h)=>J(f+h,e),sub:(f,h)=>J(f-h,e),mul:(f,h)=>J(f*h,e),pow:(f,h)=>Uu(l,f,h),div:(f,h)=>J(f*Bi(h,e),e),sqrN:f=>f*f,addN:(f,h)=>f+h,subN:(f,h)=>f-h,mulN:(f,h)=>f*h,inv:f=>Bi(f,e),sqrt:s||(f=>(d||(d=Ru(e)),d(l,f))),toBytes:f=>r?mo(f,u):Zr(f,u),fromBytes:(f,h=!0)=>{if(a){if(!a.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);let E=new Uint8Array(u);E.set(f,r?0:E.length-f.length),f=E}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let p=r?Gt(f):Ue(f);if(i&&(p=J(p,e)),!h&&!l.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:f=>fr(l,f),cmov:(f,h,p)=>p?h:f});return Object.freeze(l)}function Ri(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 xo(e){let t=Ri(e);return t+Math.ceil(t/2)}function Eo(e,t,r=!1){let n=e.length,o=Ri(t),s=xo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Gt(e):Ue(e),a=J(i,t-nt)+nt;return r?mo(a,o):Zr(a,o)}var Oe=BigInt(0),Ee=BigInt(1);function lr(e,t){let r=t.negate();return e?r:t}function $t(e,t){let r=fr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Oi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function So(e,t){Oi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=ce(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ni(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=Ee);let u=t*n,d=u+Math.abs(a)-1,l=a===0,f=a<0,h=t%2!==0;return{nextN:c,offset:d,isZero:l,isNeg:f,isNegF:h,offsetF:u}}function Mu(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 Ou(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 vo=new WeakMap,qi=new WeakMap;function Ao(e){return qi.get(e)||1}function Ui(e){if(e!==Oe)throw new Error("invalid wNAF")}var qe=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>Oe;)r&Ee&&(n=n.add(o)),o=o.double(),r>>=Ee;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=So(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.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=So(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:d,isNeg:l,isNegF:f,offsetF:h}=Ni(n,a,i);n=c,d?s=s.add(lr(f,r[h])):o=o.add(lr(l,r[u]))}return Ui(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=So(t,this.bits);for(let i=0;i<s.windows&&n!==Oe;i++){let{nextN:a,offset:c,isZero:u,isNeg:d}=Ni(n,i,s);if(n=a,!u){let l=r[c];o=o.add(d?l.negate():l)}}return Ui(n),o}getPrecomputes(t,r,n){let o=vo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),vo.set(r,o))),o}cached(t,r,n){let o=Ao(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Ao(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Oi(r,this.bits),qi.set(t,r),vo.delete(t)}hasCache(t){return Ao(t)!==1}};function Hi(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Oe||n>Oe;)r&Ee&&(s=s.add(o)),n&Ee&&(i=i.add(o)),o=o.double(),r>>=Ee,n>>=Ee;return{p1:s,p2:i}}function He(e,t,r,n){Mu(r,e),Ou(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,a=$r(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=ce(c),d=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,f=i;for(let h=l;h>=0;h-=c){d.fill(i);for(let E=0;E<s;E++){let S=n[E],b=Number(S>>BigInt(h)&u);d[b]=d[b].add(r[E])}let p=i;for(let E=d.length-1,S=i;E>0;E--)S=S.add(d[E]),p=p.add(S);if(f=f.add(p),h!==0)for(let E=0;E<c;E++)f=f.double()}return f}function Mi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return wo(t),t}else return At(e,{isLE:r})}function Xr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Oe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Mi(t.p,r.Fp,n),s=Mi(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var fe=BigInt(0),ot=BigInt(1),Io=BigInt(2),qu=BigInt(8);function Hu(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function Vu(e,t={}){let r=Xr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;ue(t,{},{uvRatio:"function"});let a=Io<<BigInt(o.BYTES*8)-ot,c=S=>n.create(S),u=t.uvRatio||((S,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,b))}}catch{return{isValid:!1,value:fe}}});if(!Hu(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function d(S,b,A=!1){let w=A?ot:fe;return ur("coordinate "+S,b,w,a),b}function l(S){if(!(S instanceof p))throw new Error("ExtendedPoint expected")}let f=Me((S,b)=>{let{X:A,Y:w,Z:L}=S,P=S.is0();b==null&&(b=P?qu:n.inv(L));let M=c(A*b),U=c(w*b),k=n.mul(L,b);if(P)return{x:fe,y:ot};if(k!==ot)throw new Error("invZ was invalid");return{x:M,y:U}}),h=Me(S=>{let{a:b,d:A}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:w,Y:L,Z:P,T:M}=S,U=c(w*w),k=c(L*L),x=c(P*P),T=c(x*x),R=c(U*b),D=c(x*c(R+k)),g=c(T+c(A*c(U*k)));if(D!==g)throw new Error("bad point: equation left != right (1)");let m=c(w*L),y=c(P*M);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(b,A,w,L){this.X=d("x",b),this.Y=d("y",A),this.Z=d("z",w,!0),this.T=d("t",L),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof p)throw new Error("extended point not allowed");let{x:A,y:w}=b||{};return d("x",A),d("y",w),new p(A,w,ot,c(A*w))}static fromBytes(b,A=!1){let w=n.BYTES,{a:L,d:P}=s;b=yo(vt(b,w,"point")),zt(A,"zip215");let M=yo(b),U=b[w-1];M[w-1]=U&-129;let k=Gt(M),x=A?a:n.ORDER;ur("point.y",k,fe,x);let T=c(k*k),R=c(T-ot),D=c(P*T-L),{isValid:g,value:m}=u(R,D);if(!g)throw new Error("bad point: invalid y coordinate");let y=(m&ot)===ot,v=(U&128)!==0;if(!A&&m===fe&&v)throw new Error("bad point: x=0 and x_0=1");return v!==y&&(m=c(-m)),p.fromAffine({x:m,y:k})}static fromHex(b,A=!1){return p.fromBytes(V("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(Io),this}assertValidity(){h(this)}equals(b){l(b);let{X:A,Y:w,Z:L}=this,{X:P,Y:M,Z:U}=b,k=c(A*U),x=c(P*L),T=c(w*U),R=c(M*L);return k===x&&T===R}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=s,{X:A,Y:w,Z:L}=this,P=c(A*A),M=c(w*w),U=c(Io*c(L*L)),k=c(b*P),x=A+w,T=c(c(x*x)-P-M),R=k+M,D=R-U,g=k-M,m=c(T*D),y=c(R*g),v=c(T*g),I=c(D*R);return new p(m,y,I,v)}add(b){l(b);let{a:A,d:w}=s,{X:L,Y:P,Z:M,T:U}=this,{X:k,Y:x,Z:T,T:R}=b,D=c(L*k),g=c(P*x),m=c(U*w*R),y=c(M*T),v=c((L+P)*(k+x)-D-g),I=y-m,C=y+m,B=c(g-A*D),_=c(v*I),K=c(C*B),N=c(v*B),Y=c(I*C);return new p(_,K,Y,N)}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=>$t(p,L));return $t(p,[A,w])[0]}multiplyUnsafe(b,A=p.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===fe?p.ZERO:this.is0()||b===ot?this:E.unsafe(this,b,w=>$t(p,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(b){return f(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 Bt(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 $t(p,b)}static msm(b,A){return He(p,o,b,A)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,ot,c(s.Gx*s.Gy)),p.ZERO=new p(fe,ot,ot,fe),p.Fp=n,p.Fn=o;let E=new qe(p,o.BITS);return p.BASE.precompute(8),p}var jr=class{constructor(t){this.ep=t}static fromBytes(t){bo()}static fromHex(t){bo()}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 Bt(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 Fu(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ue(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,a=r.randomBytes||oe,c=r.adjustScalarBytes||(x=>x),u=r.domain||((x,T,R)=>{if(zt(R,"phflag"),T.length||R)throw new Error("Contexts/pre-hash are not supported");return x});function d(x){return i.create(Gt(x))}function l(x){let T=w.secretKey;x=V("private key",x,T);let R=V("hashed private key",t(x),2*T),D=c(R.slice(0,T)),g=R.slice(T,2*T),m=d(D);return{head:D,prefix:g,scalar:m}}function f(x){let{head:T,prefix:R,scalar:D}=l(x),g=o.multiply(D),m=g.toBytes();return{head:T,prefix:R,scalar:D,point:g,pointBytes:m}}function h(x){return f(x).pointBytes}function p(x=Uint8Array.of(),...T){let R=ht(...T);return d(t(u(R,V("context",x),!!n)))}function E(x,T,R={}){x=V("message",x),n&&(x=n(x));let{prefix:D,scalar:g,pointBytes:m}=f(T),y=p(R.context,D,x),v=o.multiply(y).toBytes(),I=p(R.context,v,m,x),C=i.create(y+I*g);if(!i.isValid(C))throw new Error("sign failed: invalid s");let B=ht(v,i.toBytes(C));return vt(B,w.signature,"result")}let S={zip215:!0};function b(x,T,R,D=S){let{context:g,zip215:m}=D,y=w.signature;x=V("signature",x,y),T=V("message",T),R=V("publicKey",R,w.publicKey),m!==void 0&&zt(m,"zip215"),n&&(T=n(T));let v=y/2,I=x.subarray(0,v),C=Gt(x.subarray(v,y)),B,_,K;try{B=e.fromBytes(R,m),_=e.fromBytes(I,m),K=o.multiplyUnsafe(C)}catch{return!1}if(!m&&B.isSmallOrder())return!1;let N=p(g,_.toBytes(),B.toBytes(),T);return _.add(B.multiplyUnsafe(N)).subtract(K).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function L(x=a(w.seed)){return vt(x,w.seed,"seed")}function P(x){let T=k.randomSecretKey(x);return{secretKey:T,publicKey:h(T)}}function M(x){return Ht(x)&&x.length===i.BYTES}function U(x,T){try{return!!e.fromBytes(x,T)}catch{return!1}}let k={getExtendedPublicKey:f,randomSecretKey:L,isValidSecretKey:M,isValidPublicKey:U,toMontgomery(x){let{y:T}=e.fromBytes(x),R=w.publicKey,D=R===32;if(!D&&R!==57)throw new Error("only defined for 25519 and 448");let g=D?s.div(ot+T,ot-T):s.div(T-ot,T+ot);return s.toBytes(g)},toMontgomerySecret(x){let T=w.secretKey;vt(x,T);let R=t(x.subarray(0,T));return c(R).subarray(0,T)},randomPrivateKey:L,precompute(x=8,T=e.BASE){return T.precompute(x,!1)}};return Object.freeze({keygen:P,getPublicKey:h,sign:E,verify:b,utils:k,Point:e,lengths:w})}function zu(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=At(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 Gu(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Vi(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=zu(e),s=Vu(t,r),i=Fu(s,n,o);return Gu(e,i)}var Zu=BigInt(0),Yt=BigInt(1),Fi=BigInt(2),Ud=BigInt(3),$u=BigInt(5),Yu=BigInt(8),Ve=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),hr={p:Ve,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Yu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Xu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ve,a=e*e%s*e%s,c=G(a,Fi,s)*a%s,u=G(c,Yt,s)*e%s,d=G(u,$u,s)*u%s,l=G(d,t,s)*d%s,f=G(l,r,s)*l%s,h=G(f,n,s)*f%s,p=G(h,o,s)*h%s,E=G(p,o,s)*h%s,S=G(E,t,s)*d%s;return{pow_p_5_8:G(S,Fi,s)*e%s,b2:a}}function ju(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Bo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function To(e,t){let r=Ve,n=J(t*t*t,r),o=J(n*n*t,r),s=Xu(e*o).pow_p_5_8,i=J(e*n*s,r),a=J(t*i*i,r),c=i,u=J(i*Bo,r),d=a===e,l=a===J(-e,r),f=a===J(-e*Bo,r);return d&&(i=c),(l||f)&&(i=u),Zt(i,r)&&(i=J(-i,r)),{isValid:d||l,value:i}}var le=At(hr.p,{isLE:!0}),Wu=At(hr.n,{isLE:!0}),Ju={...hr,Fp:le,hash:Ei,adjustScalarBytes:ju,uvRatio:To},Xt=Vi(Ju);var _o=Bo,Qu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),tf=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),ef=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),rf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),zi=e=>To(Yt,e),nf=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Lo=e=>Xt.Point.Fp.create(Gt(e)&nf);function Gi(e){let{d:t}=hr,r=Ve,n=b=>le.create(b),o=n(_o*e*e),s=n((o+Yt)*ef),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=To(s,a),d=n(u*e);Zt(d,r)||(d=n(-d)),c||(u=d),c||(i=o);let l=n(i*(o-Yt)*rf-a),f=u*u,h=n((u+u)*a),p=n(l*Qu),E=n(Yt-f),S=n(Yt+f);return new Xt.Point(n(h*S),n(E*p),n(p*S),n(h*E))}function of(e){wt(e,64);let t=Lo(e.subarray(0,32)),r=Gi(t),n=Lo(e.subarray(32,64)),o=Gi(n);return new jt(r.add(o))}var jt=class e extends jr{constructor(t){super(t)}static fromAffine(t){return new e(Xt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return of(V("ristrettoHash",t,64))}static fromBytes(t){wt(t,32);let{a:r,d:n}=hr,o=Ve,s=L=>le.create(L),i=Lo(t);if(!vi(le.toBytes(i),t)||Zt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Yt+r*a),u=s(Yt-r*a),d=s(c*c),l=s(u*u),f=s(r*n*d-l),{isValid:h,value:p}=zi(s(f*l)),E=s(p*u),S=s(p*E*f),b=s((i+i)*E);Zt(b,o)&&(b=s(-b));let A=s(c*S),w=s(b*A);if(!h||Zt(w,o)||A===Zu)throw new Error("invalid ristretto255 encoding 2");return new e(new Xt.Point(b,A,Yt,w))}static fromHex(t){return e.fromBytes(V("ristrettoHex",t,32))}static msm(t,r){return He(e,Xt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ve,i=S=>le.create(S),a=i(i(n+r)*i(n-r)),c=i(t*r),u=i(c*c),{value:d}=zi(i(a*u)),l=i(d*a),f=i(d*c),h=i(l*f*o),p;if(Zt(o*h,s)){let S=i(r*_o),b=i(t*_o);t=S,r=b,p=i(l*tf)}else p=f;Zt(t*h,s)&&(r=i(-r));let E=i((n-r)*p);return Zt(E,s)&&(E=i(-E)),le.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>le.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(e.ZERO)}};jt.BASE=new jt(Xt.Point.BASE);jt.ZERO=new jt(Xt.Point.ZERO);jt.Fp=le;jt.Fn=Wu;var dr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Wr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Zi={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Wr("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 _t=Zi;var Jr=32;var Do,sf=(async()=>{try{return await _t.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function af(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await _t.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await _t.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 cf(e,t,r){return Xt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function $i(e,t,r){return Do==null&&(Do=await sf),Do?af(e,t,r):cf(e,t,r)}function Qr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var tn=class{type="Ed25519";raw;constructor(t){this.raw=Co(t,Jr)}toMultihash(){return Tt.digest(Ot(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return $.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=$i(this.raw,r,t);return Qr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Po(e){return e=Co(e,Jr),new tn(e)}function Co(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 ff=Math.pow(2,7),lf=Math.pow(2,14),hf=Math.pow(2,21),Ko=Math.pow(2,28),ko=Math.pow(2,35),Ro=Math.pow(2,42),No=Math.pow(2,49),q=128,ut=127;function Ct(e){if(e<ff)return 1;if(e<lf)return 2;if(e<hf)return 3;if(e<Ko)return 4;if(e<ko)return 5;if(e<Ro)return 6;if(e<No)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Uo(e,t,r=0){switch(Ct(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 df(e,t,r=0){switch(Ct(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 Mo(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)*Ko,r<q)||(r=e[t+5],n+=(r&ut)*ko,r<q)||(r=e[t+6],n+=(r&ut)*Ro,r<q)||(r=e[t+7],n+=(r&ut)*No,r<q))return n;throw new RangeError("Could not decode varint")}function pf(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)*Ko,r<q)||(r=e.get(t+5),n+=(r&ut)*ko,r<q)||(r=e.get(t+6),n+=(r&ut)*Ro,r<q)||(r=e.get(t+7),n+=(r&ut)*No,r<q))return n;throw new RangeError("Could not decode varint")}function Xi(e,t,r=0){return t==null&&(t=ct(Ct(e))),t instanceof Uint8Array?Uo(e,t,r):df(e,t,r)}function ji(e,t=0){return e instanceof Uint8Array?Mo(e,t):pf(e,t)}var Oo=new Float32Array([-0]),he=new Uint8Array(Oo.buffer);function Ji(e,t,r){Oo[0]=e,t[r]=he[0],t[r+1]=he[1],t[r+2]=he[2],t[r+3]=he[3]}function Qi(e,t){return he[0]=e[t],he[1]=e[t+1],he[2]=e[t+2],he[3]=e[t+3],Oo[0]}var qo=new Float64Array([-0]),ft=new Uint8Array(qo.buffer);function ta(e,t,r){qo[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 ea(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],qo[0]}var mf=BigInt(Number.MAX_SAFE_INTEGER),yf=BigInt(Number.MIN_SAFE_INTEGER),It=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 Se;if(t<mf&&t>yf)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>ra&&(o=0n,++n>ra&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Se;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):Se}},Se=new It(0,0);Se.toBigInt=function(){return 0n};Se.zzEncode=Se.zzDecode=function(){return this};Se.length=function(){return 1};var ra=4294967296n;function na(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 oa(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&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 Ho(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 Pt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function en(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Vo=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,Pt(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 Pt(this,4);return en(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pt(this,4);return en(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pt(this,4);let t=Qi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Pt(this,4);let t=ea(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 Pt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return oa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Pt(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 It(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 Pt(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 Pt(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 Pt(this,8);let t=en(this.buf,this.pos+=4),r=en(this.buf,this.pos+=4);return new It(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=Mo(this.buf,this.pos);return this.pos+=Ct(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 Fo(e){return new Vo(e instanceof Uint8Array?e:e.subarray())}function xt(e,t,r){let n=Fo(e);return t.decode(n,void 0,r)}function zo(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 a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ve=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Go(){}var $o=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},bf=zo();function gf(e){return globalThis.Buffer!=null?ct(e):bf(e)}var mr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ve(Go,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ve(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Yo((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(rn,10,It.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=It.fromBigInt(t);return this._push(rn,r.length(),r)}uint64Number(t){return this._push(Uo,Ct(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=It.fromBigInt(t).zzEncode();return this._push(rn,r.length(),r)}sint64Number(t){let r=It.fromNumber(t).zzEncode();return this._push(rn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Zo,1,t?1:0)}fixed32(t){return this._push(pr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=It.fromBigInt(t);return this._push(pr,4,r.lo)._push(pr,4,r.hi)}fixed64Number(t){let r=It.fromNumber(t);return this._push(pr,4,r.lo)._push(pr,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(Ji,4,t)}double(t){return this._push(ta,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Zo,1,0):this.uint32(r)._push(xf,r,t)}string(t){let r=na(t);return r!==0?this.uint32(r)._push(Ho,r,t):this._push(Zo,1,0)}fork(){return this.states=new $o(this),this.head=this.tail=new ve(Go,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 ve(Go,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=gf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Zo(e,t,r){t[r]=e&255}function wf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Yo=class extends ve{next;constructor(t,r){super(wf,t,r),this.next=void 0}};function rn(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 pr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function xf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(mr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Ef,t,e),this},mr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Sf,t,e),this});function Ef(e,t,r){t.set(e,r)}function Sf(e,t,r){e.length<40?Ho(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(z(e),r)}function Xo(){return new mr}function Et(e,t){let r=Xo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Fe;(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"})(Fe||(Fe={}));function nn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function jo(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return nn("enum",Fe.VARINT,r,n)}function St(e,t){return nn("message",Fe.LENGTH_DELIMITED,e,t)}var Lt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var tt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(tt||(tt={}));var Wo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Wo||(Wo={}));(function(e){e.codec=()=>jo(Wo)})(tt||(tt={}));var Rt;(function(e){let t;e.codec=()=>(t==null&&(t=St((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 a=r.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(Rt||(Rt={}));var Jo;(function(e){let t;e.codec=()=>(t==null&&(t=St((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 a=r.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(Jo||(Jo={}));function on(e){if(isNaN(e)||e<=0)throw new Z("random bytes length must be a Number bigger than 0");return oe(e)}var br={};yt(br,{MAX_RSA_KEY_SIZE:()=>Qo,generateRSAKeyPair:()=>fa,jwkToJWKKeyPair:()=>la,jwkToPkcs1:()=>Bf,jwkToPkix:()=>ns,jwkToRSAPrivateKey:()=>as,pkcs1MessageToJwk:()=>es,pkcs1MessageToRSAPrivateKey:()=>os,pkcs1ToJwk:()=>If,pkcs1ToRSAPrivateKey:()=>ua,pkixMessageToJwk:()=>rs,pkixMessageToRSAPublicKey:()=>is,pkixToJwk:()=>_f,pkixToRSAPublicKey:()=>ss});var sn=Gr;var ze=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=br.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return $.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 ca(this.jwk,r,t,n)}},yr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=br.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}sign(t,r){return aa(this.jwk,t,r)}};var Qo=8192,ts=18,vf=1062,Af=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function If(e){let t=Mt(e);return es(t)}function es(e){return{n:H(e[1],"base64url"),e:H(e[2],"base64url"),d:H(e[3],"base64url"),p:H(e[4],"base64url"),q:H(e[5],"base64url"),dp:H(e[6],"base64url"),dq:H(e[7],"base64url"),qi:H(e[8],"base64url"),kty:"RSA"}}function Bf(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 ne([gt(Uint8Array.from([0])),gt(z(e.n,"base64url")),gt(z(e.e,"base64url")),gt(z(e.d,"base64url")),gt(z(e.p,"base64url")),gt(z(e.q,"base64url")),gt(z(e.dp,"base64url")),gt(z(e.dq,"base64url")),gt(z(e.qi,"base64url"))]).subarray()}function _f(e){let t=Mt(e,{offset:0});return rs(t)}function rs(e){let t=Mt(e[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function ns(e){if(e.n==null||e.e==null)throw new Z("JWK was missing components");return ne([Af,qr(ne([gt(z(e.n,"base64url")),gt(z(e.e,"base64url"))]))]).subarray()}function ua(e){let t=Mt(e);return os(t)}function os(e){let t=es(e);return as(t)}function ss(e,t){if(e.byteLength>=vf)throw new _e("Key size is too large");let r=Mt(e,{offset:0});return is(r,e,t)}function is(e,t,r){let n=rs(e);if(r==null){let o=sn(Rt.encode({Type:tt.RSA,Data:t}));r=Kt(ts,o)}return new ze(n,r)}function as(e){if(da(e)>Qo)throw new Z("Key size is too large");let t=la(e),r=sn(Rt.encode({Type:tt.RSA,Data:ns(t.publicKey)})),n=Kt(ts,r);return new yr(t.privateKey,new ze(t.publicKey,n))}async function fa(e){if(e>Qo)throw new Z("Key size is too large");let t=await ha(e),r=sn(Rt.encode({Type:tt.RSA,Data:ns(t.publicKey)})),n=Kt(ts,r);return new yr(t.privateKey,new ze(t.publicKey,n))}function la(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 ha(e,t){let r=await _t.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Lf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function aa(e,t,r){let n=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await _t.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 ca(e,t,r,n){let o=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await _t.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Lf(e,t){if(e.privateKey==null||e.publicKey==null)throw new Z("Private and public key are required");let r=await Promise.all([_t.get().subtle.exportKey("jwk",e.privateKey),_t.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function da(e){if(e.kty!=="RSA")throw new Z("invalid key type");if(e.n==null)throw new Z("invalid key modulus");return z(e.n,"base64url").length*8}var an=class extends Re{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Hr(t);let n=or(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),Vt(s)}update(t){return Ne(this),this.iHash.update(t),this}digestInto(t){Ne(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:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},cs=(e,t,r)=>new an(e,t).update(r).digest();cs.create=(e,t)=>new an(e,t);var pa=(e,t)=>(e+(e>=0?t:-t)/ma)/t;function Tf(e,t,r){let[[n,o],[s,i]]=t,a=pa(i*e,r),c=pa(-o*e,r),u=e-a*n-c*s,d=-a*o-c*i,l=u<Jt,f=d<Jt;l&&(u=-u),f&&(d=-d);let h=ce(Math.ceil($r(r)/2))+Ze;if(u<Jt||u>=h||d<Jt||d>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:f,k2:d}}function fs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function us(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return zt(r.lowS,"lowS"),zt(r.prehash,"prehash"),r.format!==void 0&&fs(r.format),r}var ls=class extends Error{constructor(t=""){super(t)}},Wt={Err:ls,_tlv:{encode:(e,t)=>{let{Err:r}=Wt;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=cr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?cr(o.length/2|128):"";return cr(e)+s+o+t},decode(e,t){let{Err:r}=Wt,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 c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of u)i=i<<8|d;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Wt;if(e<Jt)throw new t("integer: negative integers are not allowed");let r=cr(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}=Wt;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 Ue(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Wt,o=V("signature",e),{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:u,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Wt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Jt=BigInt(0),Ze=BigInt(1),ma=BigInt(2),cn=BigInt(3),Df=BigInt(4);function Ge(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=V("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 Cf(e,t={}){let r=Xr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;ue(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=ba(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(D,g,m){let{x:y,y:v}=g.toAffine(),I=n.toBytes(y);if(zt(m,"isCompressed"),m){d();let C=!n.isOdd(v);return ht(ya(C),I)}else return ht(Uint8Array.of(4),I,n.toBytes(v))}function f(D){vt(D,void 0,"Point");let{publicKey:g,publicKeyUncompressed:m}=u,y=D.length,v=D[0],I=D.subarray(1);if(y===g&&(v===2||v===3)){let C=n.fromBytes(I);if(!n.isValid(C))throw new Error("bad point: is not on curve, wrong x");let B=E(C),_;try{_=n.sqrt(B)}catch(Y){let F=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+F)}d();let K=n.isOdd(_);return(v&1)===1!==K&&(_=n.neg(_)),{x:C,y:_}}else if(y===m&&v===4){let C=n.BYTES,B=n.fromBytes(I.subarray(0,C)),_=n.fromBytes(I.subarray(C,C*2));if(!S(B,_))throw new Error("bad point: is not on curve");return{x:B,y:_}}else throw new Error(`bad point: got length ${y}, expected compressed=${g} or uncompressed=${m}`)}let h=t.toBytes||l,p=t.fromBytes||f;function E(D){let g=n.sqr(D),m=n.mul(g,D);return n.add(n.add(m,n.mul(D,s.a)),s.b)}function S(D,g){let m=n.sqr(g),y=E(D);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,cn),Df),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(D,g,m=!1){if(!n.isValid(g)||m&&n.is0(g))throw new Error(`bad point coordinate ${D}`);return g}function L(D){if(!(D instanceof x))throw new Error("ProjectivePoint expected")}function P(D){if(!c||!c.basises)throw new Error("no endo");return Tf(D,c.basises,o.ORDER)}let M=Me((D,g)=>{let{X:m,Y:y,Z:v}=D;if(n.eql(v,n.ONE))return{x:m,y};let I=D.is0();g==null&&(g=I?n.ONE:n.inv(v));let C=n.mul(m,g),B=n.mul(y,g),_=n.mul(v,g);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:C,y:B}}),U=Me(D=>{if(D.is0()){if(t.allowInfinityPoint&&!n.is0(D.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:m}=D.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(!D.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function k(D,g,m,y,v){return m=new x(n.mul(m.X,D),m.Y,m.Z),g=lr(y,g),m=lr(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(p(vt(g,void 0,"point")));return m.assertValidity(),m}static fromHex(g){return x.fromBytes(V("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,m=!0){return R.createCache(this,g),m||this.multiply(cn),this}assertValidity(){U(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:I,Y:C,Z:B}=g,_=n.eql(n.mul(m,B),n.mul(I,v)),K=n.eql(n.mul(y,B),n.mul(C,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,cn),{X:v,Y:I,Z:C}=this,B=n.ZERO,_=n.ZERO,K=n.ZERO,N=n.mul(v,v),Y=n.mul(I,I),F=n.mul(C,C),O=n.mul(v,I);return O=n.add(O,O),K=n.mul(v,C),K=n.add(K,K),B=n.mul(g,K),_=n.mul(y,F),_=n.add(B,_),B=n.sub(Y,_),_=n.add(Y,_),_=n.mul(B,_),B=n.mul(O,B),K=n.mul(y,K),F=n.mul(g,F),O=n.sub(N,F),O=n.mul(g,O),O=n.add(O,K),K=n.add(N,N),N=n.add(K,N),N=n.add(N,F),N=n.mul(N,O),_=n.add(_,N),F=n.mul(I,C),F=n.add(F,F),N=n.mul(F,O),B=n.sub(B,N),K=n.mul(F,Y),K=n.add(K,K),K=n.add(K,K),new x(B,_,K)}add(g){L(g);let{X:m,Y:y,Z:v}=this,{X:I,Y:C,Z:B}=g,_=n.ZERO,K=n.ZERO,N=n.ZERO,Y=s.a,F=n.mul(s.b,cn),O=n.mul(m,I),X=n.mul(y,C),et=n.mul(v,B),mt=n.add(m,y),j=n.add(I,C);mt=n.mul(mt,j),j=n.add(O,X),mt=n.sub(mt,j),j=n.add(m,v);let it=n.add(I,B);return j=n.mul(j,it),it=n.add(O,et),j=n.sub(j,it),it=n.add(y,v),_=n.add(C,B),it=n.mul(it,_),_=n.add(X,et),it=n.sub(it,_),N=n.mul(Y,j),_=n.mul(F,et),N=n.add(_,N),_=n.sub(X,N),N=n.add(X,N),K=n.mul(_,N),X=n.add(O,O),X=n.add(X,O),et=n.mul(Y,et),j=n.mul(F,j),X=n.add(X,et),et=n.sub(O,et),et=n.mul(Y,et),j=n.add(j,et),O=n.mul(X,j),K=n.add(K,O),O=n.mul(it,j),_=n.mul(mt,_),_=n.sub(_,O),O=n.mul(mt,X),N=n.mul(it,N),N=n.add(N,O),new x(_,K,N)}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,I=C=>R.cached(this,C,B=>$t(x,B));if(m){let{k1neg:C,k1:B,k2neg:_,k2:K}=P(g),{p:N,f:Y}=I(B),{p:F,f:O}=I(K);v=Y.add(O),y=k(m.beta,N,F,C,_)}else{let{p:C,f:B}=I(g);y=C,v=B}return $t(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===Jt||y.is0())return x.ZERO;if(g===Ze)return y;if(R.hasCache(this))return this.multiply(g);if(m){let{k1neg:v,k1:I,k2neg:C,k2:B}=P(g),{p1:_,p2:K}=Hi(x,y,I,B);return k(m.beta,_,K,v,C)}else return R.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 M(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return i===Ze?!0:g?g(x,this):R.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===Ze?this:g?g(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return zt(g,"isCompressed"),this.assertValidity(),h(x,this,g)}toHex(g=!0){return Bt(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 $t(x,g)}static msm(g,m){return He(x,o,g,m)}static fromPrivateKey(g){return x.BASE.multiply(Ge(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,R=new qe(x,t.endo?Math.ceil(T/2):T);return x.BASE.precompute(8),x}function ya(e){return Uint8Array.of(e?2:3)}function ba(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Pf(e,t={}){let{Fn:r}=e,n=t.randomBytes||oe,o=Object.assign(ba(e.Fp,r),{seed:xo(r.ORDER)});function s(h){try{return!!Ge(r,h)}catch{return!1}}function i(h,p){let{publicKey:E,publicKeyUncompressed:S}=o;try{let b=h.length;return p===!0&&b!==E||p===!1&&b!==S?!1:!!e.fromBytes(h)}catch{return!1}}function a(h=n(o.seed)){return Eo(vt(h,o.seed,"seed"),r.ORDER)}function c(h,p=!0){return e.BASE.multiply(Ge(r,h)).toBytes(p)}function u(h){let p=a(h);return{secretKey:p,publicKey:c(p)}}function d(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let{secretKey:p,publicKey:E,publicKeyUncompressed:S}=o;if(r.allowedLengths||p===E)return;let b=V("key",h).length;return b===E||b===S}function l(h,p,E=!0){if(d(h)===!0)throw new Error("first arg must be private key");if(d(p)===!1)throw new Error("second arg must be public key");let S=Ge(r,h);return e.fromHex(p).multiply(S).toBytes(E)}return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:h=>Ge(r,h),precompute(h=8,p=e.BASE){return p.precompute(h,!1)}},lengths:o})}function Kf(e,t,r={}){Hr(t),ue(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||oe,o=r.hmac||((m,...y)=>cs(t,m,ht(...y))),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:h}=Pf(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function S(m){let y=a>>Ze;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){fs(y);let v=h.signature,I=y==="compact"?v:y==="recovered"?v+1:void 0;return vt(m,I,`${y} signature`)}class w{constructor(y,v,I){this.r=b("r",y),this.s=b("s",v),I!=null&&(this.recovery=I),Object.freeze(this)}static fromBytes(y,v=E){A(y,v);let I;if(v==="der"){let{r:K,s:N}=Wt.toSig(vt(y));return new w(K,N)}v==="recovered"&&(I=y[0],v="compact",y=y.subarray(1));let C=i.BYTES,B=y.subarray(0,C),_=y.subarray(C,C*2);return new w(i.fromBytes(B),i.fromBytes(_),I)}static fromHex(y,v){return this.fromBytes(be(y),v)}addRecoveryBit(y){return new w(this.r,this.s,y)}recoverPublicKey(y){let v=s.ORDER,{r:I,s:C,recovery:B}=this;if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");if(a*ma<v&&B>1)throw new Error("recovery id is ambiguous for h>1 curve");let K=B===2||B===3?I+a:I;if(!s.isValid(K))throw new Error("recovery id 2 or 3 invalid");let N=s.toBytes(K),Y=e.fromBytes(ht(ya((B&1)===0),N)),F=i.inv(K),O=P(V("msgHash",y)),X=i.create(-O*F),et=i.create(C*F),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(fs(y),y==="der")return be(Wt.hexFromSig(this));let v=i.toBytes(this.r),I=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,I)}return ht(v,I)}toHex(y){return Bt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return w.fromBytes(V("sig",y),"compact")}static fromDER(y){return w.fromBytes(V("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 Bt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Bt(this.toBytes("compact"))}}let L=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let v=Ue(y),I=y.length*8-c;return I>0?v>>BigInt(I):v},P=r.bits2int_modN||function(y){return i.create(L(y))},M=ce(c);function U(m){return ur("num < 2^"+c,m,Jt,M),i.toBytes(m)}function k(m,y){return vt(m,void 0,"message"),y?vt(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:I,prehash:C,extraEntropy:B}=us(v,p);m=k(m,C);let _=P(m),K=Ge(i,y),N=[U(K),U(_)];if(B!=null&&B!==!1){let X=B===!0?n(h.secretKey):B;N.push(V("extraEntropy",X))}let Y=ht(...N),F=_;function O(X){let et=L(X);if(!i.isValidNot0(et))return;let mt=i.inv(et),j=e.BASE.multiply(et).toAffine(),it=i.create(j.x);if(it===Jt)return;let Kr=i.create(mt*i.create(F+it*K));if(Kr===Jt)return;let Ls=(j.x===it?0:2)|Number(j.y&Ze),Ts=Kr;return I&&S(Kr)&&(Ts=i.neg(Kr),Ls^=1),new w(it,Ts,Ls)}return{seed:Y,k2sig:O}}function T(m,y,v={}){m=V("message",m);let{seed:I,k2sig:C}=x(m,y,v);return Ii(t.outputLen,i.BYTES,o)(I,C)}function R(m){let y,v=typeof m=="string"||Ht(m),I=!v&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!v&&!I)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(I)y=new w(m.r,m.s);else if(v){try{y=w.fromBytes(V("sig",m),"der")}catch(C){if(!(C instanceof Wt.Err))throw C}if(!y)try{y=w.fromBytes(V("sig",m),"compact")}catch{return!1}}return y||!1}function D(m,y,v,I={}){let{lowS:C,prehash:B,format:_}=us(I,p);if(v=V("publicKey",v),y=k(V("message",y),B),"strict"in I)throw new Error("options.strict was renamed to lowS");let K=_===void 0?R(m):w.fromBytes(V("sig",m),_);if(K===!1)return!1;try{let N=e.fromBytes(v);if(C&&K.hasHighS())return!1;let{r:Y,s:F}=K,O=P(y),X=i.inv(F),et=i.create(O*X),mt=i.create(Y*X),j=e.BASE.multiplyUnsafe(et).add(N.multiplyUnsafe(mt));return j.is0()?!1:i.create(j.x)===Y}catch{return!1}}function g(m,y,v={}){let{prehash:I}=us(v,p);return y=k(y,I),w.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:h,Point:e,sign:T,verify:D,recoverPublicKey:g,Signature:w,hash:t})}function kf(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=At(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 Rf(e){let{CURVE:t,curveOpts:r}=kf(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 Nf(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Yr(r.Fn.ORDER,r.Fn.BITS))})}function ga(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=Rf(e),s=Cf(t,r),i=Kf(s,n,o);return Nf(e,i)}function wa(e,t){let r=n=>ga({...e,hash:n});return{...r(t),create:r}}var ds={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Uf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var xa=BigInt(2);function Mf(e){let t=ds.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,d=u*u*e%t,l=G(d,r,t)*d%t,f=G(l,r,t)*d%t,h=G(f,xa,t)*u%t,p=G(h,o,t)*h%t,E=G(p,s,t)*p%t,S=G(E,a,t)*E%t,b=G(S,c,t)*S%t,A=G(b,a,t)*E%t,w=G(A,r,t)*d%t,L=G(w,i,t)*p%t,P=G(L,n,t)*u%t,M=G(P,xa,t);if(!hs.eql(hs.sqr(M),e))throw new Error("Cannot find square root");return M}var hs=At(ds.p,{sqrt:Mf}),$e=wa({...ds,Fp:hs,lowS:!0,endo:Uf},Gr);function Ea(e,t,r,n){let o=me.digest(r instanceof Uint8Array?r:r.subarray());if(Qr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),$e.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new dr(String(s))});try{return n?.signal?.throwIfAborted(),$e.verify(t,o.digest,e)}catch(s){throw new dr(String(s))}}var un=class{type="secp256k1";raw;_key;constructor(t){this._key=va(t),this.raw=Sa(this._key)}toMultihash(){return Tt.digest(Ot(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return $.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 Ea(this._key,r,t,n)}};function ps(e){return new un(e)}function Sa(e){return $e.ProjectivePoint.fromHex(e).toRawBytes(!0)}function va(e){try{return $e.ProjectivePoint.fromHex(e),e}catch(t){throw new _e(String(t))}}function ms(e,t){let{Type:r,Data:n}=Rt.decode(e),o=n??new Uint8Array;switch(r){case tt.RSA:return ss(o,t);case tt.Ed25519:return Po(o);case tt.secp256k1:return ps(o);case tt.ECDSA:return so(o);default:throw new de}}function Aa(e){let{Type:t,Data:r}=Rt.decode(e.digest),n=r??new Uint8Array;switch(t){case tt.Ed25519:return Po(n);case tt.secp256k1:return ps(n);case tt.ECDSA:return so(n);default:throw new de}}function Ot(e){return Rt.encode({Type:tt[e.type],Data:e.raw})}var Ia=Symbol.for("nodejs.util.inspect.custom"),Of=114,gr=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()})`}[Cn]=!0;toString(){return this.string==null&&(this.string=$.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Of,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")}[Ia](){return`PeerId(${this.toString()})`}},wr=class extends gr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},xr=class extends gr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Er=class extends gr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},qf=2336,fn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Tt.digest(z(this.url))}[Ia](){return`PeerId(${this.url})`}[Cn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(qf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};function ys(e){if(e.type==="Ed25519")return new xr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Er({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new wr({multihash:e.toCID().multihash,publicKey:e});throw new de}function Ba(e){return ys(e.publicKey)}function Sr(e){if(Vf(e))return new wr({multihash:e});if(Hf(e))try{let t=Aa(e);if(t.type==="Ed25519")return new xr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Er({multihash:e,publicKey:t})}catch{let r=H(e.digest);return new fn(new URL(r))}throw new Rr("Supplied PeerID Multihash is invalid")}function Hf(e){return e.code===Tt.code}function Vf(e){return e.code===me.code}function Ae(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 ln(e){let t=ee($.decode(`z${e}`));return Sr(t)}var vr=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 Ae(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 Ae(this.map.values(),t=>t.key)}values(){return Ae(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Ar=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 Ae(this.set.entries(),t=>{let r=ln(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=ln(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ae(this.set.values(),t=>ln(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 Qt(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var hn=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}},Ye=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new hn(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 hn(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 bs=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function dn(e={}){return Ff(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 Ff(e,t){t=t??{};let r=t.onEnd,n=new Ye,o,s,i,a=Qt(),c=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(()=>{a.resolve(),a=Qt()})}},u=S=>s!=null?s(S):(n.push(S),o),d=S=>(n=new Ye,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 u({done:!1,value:S})},f=S=>i?o:(i=!0,S!=null?d(S):u({done:!0})),h=()=>(n=new Ye,f(),{done:!0}),p=S=>(f(S),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:p,push:l,end:f,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,P)=>{w=()=>{P(new bs)},b.addEventListener("abort",w)}));try{await Promise.race([a.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 pn=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 _a(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new pn(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new pn(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 gs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Qt(),this.haveNext=Qt()}[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=Qt(),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=Qt(),await _a(this.readNext.promise,r?.signal,r)}};function La(){return new gs}function zf(e){return e[Symbol.asyncIterator]!=null}async function Gf(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*Zf(e){let t=new AbortController,r=La();Gf(e,r,t.signal).catch(()=>{});try{yield*r}finally{t.abort()}}function*$f(e){for(let t of e)yield*t}function Yf(...e){let t=[];for(let r of e)zf(r)||t.push(r);return t.length===e.length?$f(t):Zf(e)}var Ta=Yf;function Ir(e,...t){if(e==null)throw new Error("Empty pipeline");if(ws(e)){let n=e;e=()=>n.source}else if(Ca(e)||Da(e)){let n=e;e=()=>n}let r=[e,...t];if(r.length>1&&ws(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++)ws(r[n])&&(r[n]=jf(r[n]));return Xf(...r)}var Xf=(...e)=>{let t;for(;e.length>0;)t=e.shift()(t);return t},Da=e=>e?.[Symbol.asyncIterator]!=null,Ca=e=>e?.[Symbol.iterator]!=null,ws=e=>e==null?!1:e.sink!=null&&e.source!=null,jf=e=>t=>{let r=e.sink(t);if(r?.then!=null){let n=dn({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=e.source;if(Da(s))o=async function*(){yield*s,n.end()};else if(Ca(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Ta(n,o())}return e.source};var Es=tc(Ka(),1);var _r=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Ss=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},ka=e=>globalThis.DOMException===void 0?new Ss(e):new DOMException(e),Ra=e=>{let t=e.reason===void 0?ka("This operation was aborted."):e.reason;return t instanceof Error?t:ka(t)};function vs(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,u=new Promise((d,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(Ra(h)),a=()=>{l(Ra(h))},h.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(d,l);return}let f=new _r;i=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(h){l(h)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?d():o instanceof Error?l(o):(f.message=o??`Promise timed out after ${r} milliseconds`,l(f))},r),(async()=>{try{d(await e)}catch(h){l(h)}})()}).finally(()=>{u.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}function As(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 Lr=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=As(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 Tr=class extends Es.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:Lr,...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#I(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=vs(Promise.resolve(s),{milliseconds:r.timeout})),r.signal&&(s=Promise.race([s,this.#I(r.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof _r&&!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 Na(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 Ua(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}function Ma(e,t){let r=Na(e).return?.();Ua(r)&&r.catch(n=>{t.error("could not cause iterator to return",n)})}var yn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Xe=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},bn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Dr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function gn(e){return e[Symbol.asyncIterator]!=null}function Oa(e,t){if(e.byteLength>t)throw new Xe("Message length too long")}var xn=e=>{let t=Ct(e),r=ct(t);return Xi(e,r),xn.bytes=t,r};xn.bytes=0;function En(e,t){t=t??{};let r=t.lengthEncoder??xn,n=t?.maxDataLength??4194304;function*o(s){Oa(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return gn(e)?(async function*(){for await(let s of e)yield*o(s)})():(function*(){for(let s of e)yield*o(s)})()}En.single=(e,t)=>{t=t??{};let r=t.lengthEncoder??xn,n=t?.maxDataLength??4194304;return Oa(e,n),new rt(r(e.byteLength),e)};var Ie;(function(e){e[e.LENGTH=0]="LENGTH",e[e.DATA=1]="DATA"})(Ie||(Ie={}));var Is=e=>{let t=ji(e);return Is.bytes=Ct(t),t};Is.bytes=0;function Cr(e,t){let r=new rt,n=Ie.LENGTH,o=-1,s=t?.lengthDecoder??Is,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;r.byteLength>0;){if(n===Ie.LENGTH)try{if(o=s(r),o<0)throw new yn("Invalid message length");if(o>a)throw new Xe("Message length too long");let u=s.bytes;r.consume(u),t?.onLength!=null&&t.onLength(o),n=Ie.DATA}catch(u){if(u instanceof RangeError){if(r.byteLength>i)throw new bn("Message length length too long");break}throw u}if(n===Ie.DATA){if(r.byteLength<o)break;let u=r.sublist(0,o);r.consume(o),t?.onData!=null&&t.onData(u),yield u,n=Ie.LENGTH}}}return gn(e)?(async function*(){for await(let u of e)r.append(u),yield*c();if(r.byteLength>0)throw new Dr("Unexpected end of input")})():(function*(){for(let u of e)r.append(u),yield*c();if(r.byteLength>0)throw new Dr("Unexpected end of input")})()}Cr.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 Cr(n,{...t??{},onLength:s=>{r=s}})};var Sn=class extends Le{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=()=>{Ma(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=Ir(this._rawInboundStream,o=>Cr(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=dn({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"))}}),Ir(this.outboundStream,n=>En(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 qa(){return BigInt(`0x${H(on(8),"base16")}`)}var Ha=(e,t)=>{let r=z(t.toString(16).padStart(16,"0"),"base16"),n=Ot(e),o=new Uint8Array(n.byteLength+r.length);return o.set(n,0),o.set(r,n.byteLength),o},Va=e=>me.encode(e);var Fa=function(e){return Array.isArray(e)?e:[e]},el=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=Sr(ee(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return ys(ms(r)).equals(t)}return!1},za=async e=>{if(e.from==null)throw new Q("RPC message was missing from");if(!await el(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=Sr(ee(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:nl(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?ms(r):r}},Pr=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:rl(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Ot(e.key):void 0}:{data:e.data,topic:e.topic},rl=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),z(t,"base16")},nl=e=>BigInt(`0x${H(e,"base16")}`);var Ga=z("libp2p-pubsub:");async function Za(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Ba(e)},o=pe([Ga,r(Pr(n)).subarray()]);return n.signature=await e.sign(o),n.key=e.publicKey,n}async function $a(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=pe([Ga,t({...Pr(e),signature:void 0,key:void 0}).subarray()]);return ol(e).verify(r,e.signature)}function ol(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 vn=class extends Le{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:a=10,maxInboundStreams:c=1,maxOutboundStreams:u=1}=r;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=Fa(n),this.enabled=r.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new vr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new Tr({concurrency:a}),this.maxInboundStreams=c,this.maxOutboundStreams=u,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(a=>{this.log(a)})}_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 Sn(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 Ir(r,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,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: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 za(i);await this.processMessage(t,a)}catch(a){this.log.error(a)}})).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 Ar,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 Ha(t.key,t.sequenceNumber);case"StrictNoSign":return Va(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(Pr)})}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 $a(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===je.Reject||s===je.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Za(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 Nr("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:qa()};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())}};var An=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,r){this.entries.set(t,{value:r,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[r,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(r);else break}}has(t){return this.entries.has(t)}get(t){let r=this.entries.get(t);return r!=null&&r.validUntilMs>=Date.now()?r.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var Bs="/floodsub/1.0.0";var Be;(function(e){let t;(function(o){let s;o.codec=()=>(s==null&&(s=St((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.subscribe!=null&&(a.uint32(8),a.bool(i.subscribe)),i.topic!=null&&(a.uint32(18),a.string(i.topic)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let l=i.uint32();switch(l>>>3){case 1:{u.subscribe=i.bool();break}case 2:{u.topic=i.string();break}default:{i.skipType(l&7);break}}}return u})),s),o.encode=i=>Et(i,o.codec()),o.decode=(i,a)=>xt(i,o.codec(),a)})(t=e.SubOpts||(e.SubOpts={}));let r;(function(o){let s;o.codec=()=>(s==null&&(s=St((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.from!=null&&(a.uint32(10),a.bytes(i.from)),i.data!=null&&(a.uint32(18),a.bytes(i.data)),i.sequenceNumber!=null&&(a.uint32(26),a.bytes(i.sequenceNumber)),i.topic!=null&&(a.uint32(34),a.string(i.topic)),i.signature!=null&&(a.uint32(42),a.bytes(i.signature)),i.key!=null&&(a.uint32(50),a.bytes(i.key)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let l=i.uint32();switch(l>>>3){case 1:{u.from=i.bytes();break}case 2:{u.data=i.bytes();break}case 3:{u.sequenceNumber=i.bytes();break}case 4:{u.topic=i.string();break}case 5:{u.signature=i.bytes();break}case 6:{u.key=i.bytes();break}default:{i.skipType(l&7);break}}}return u})),s),o.encode=i=>Et(i,o.codec()),o.decode=(i,a)=>xt(i,o.codec(),a)})(r=e.Message||(e.Message={}));let n;e.codec=()=>(n==null&&(n=St((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.subscriptions!=null)for(let a of o.subscriptions)s.uint32(10),e.SubOpts.codec().encode(a,s);if(o.messages!=null)for(let a of o.messages)s.uint32(18),e.Message.codec().encode(a,s);o.control!=null&&(s.uint32(26),In.codec().encode(o.control,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={subscriptions:[],messages:[]},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{if(i.limits?.subscriptions!=null&&a.subscriptions.length===i.limits.subscriptions)throw new Lt('Decode error - map field "subscriptions" had too many elements');a.subscriptions.push(e.SubOpts.codec().decode(o,o.uint32(),{limits:i.limits?.subscriptions$}));break}case 2:{if(i.limits?.messages!=null&&a.messages.length===i.limits.messages)throw new Lt('Decode error - map field "messages" had too many elements');a.messages.push(e.Message.codec().decode(o,o.uint32(),{limits:i.limits?.messages$}));break}case 3:{a.control=In.codec().decode(o,o.uint32(),{limits:i.limits?.control});break}default:{o.skipType(u&7);break}}}return a})),n),e.encode=o=>Et(o,e.codec()),e.decode=(o,s)=>xt(o,e.codec(),s)})(Be||(Be={}));var In;(function(e){let t;e.codec=()=>(t==null&&(t=St((r,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),r.ihave!=null)for(let s of r.ihave)n.uint32(10),Bn.codec().encode(s,n);if(r.iwant!=null)for(let s of r.iwant)n.uint32(18),_n.codec().encode(s,n);if(r.graft!=null)for(let s of r.graft)n.uint32(26),Ln.codec().encode(s,n);if(r.prune!=null)for(let s of r.prune)n.uint32(34),Tn.codec().encode(s,n);o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={ihave:[],iwant:[],graft:[],prune:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{if(o.limits?.ihave!=null&&s.ihave.length===o.limits.ihave)throw new Lt('Decode error - map field "ihave" had too many elements');s.ihave.push(Bn.codec().decode(r,r.uint32(),{limits:o.limits?.ihave$}));break}case 2:{if(o.limits?.iwant!=null&&s.iwant.length===o.limits.iwant)throw new Lt('Decode error - map field "iwant" had too many elements');s.iwant.push(_n.codec().decode(r,r.uint32(),{limits:o.limits?.iwant$}));break}case 3:{if(o.limits?.graft!=null&&s.graft.length===o.limits.graft)throw new Lt('Decode error - map field "graft" had too many elements');s.graft.push(Ln.codec().decode(r,r.uint32(),{limits:o.limits?.graft$}));break}case 4:{if(o.limits?.prune!=null&&s.prune.length===o.limits.prune)throw new Lt('Decode error - map field "prune" had too many elements');s.prune.push(Tn.codec().decode(r,r.uint32(),{limits:o.limits?.prune$}));break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(In||(In={}));var Bn;(function(e){let t;e.codec=()=>(t==null&&(t=St((r,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),r.topic!=null&&(n.uint32(10),n.string(r.topic)),r.messageIDs!=null)for(let s of r.messageIDs)n.uint32(18),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={messageIDs:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.topic=r.string();break}case 2:{if(o.limits?.messageIDs!=null&&s.messageIDs.length===o.limits.messageIDs)throw new Lt('Decode error - map field "messageIDs" had too many elements');s.messageIDs.push(r.bytes());break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(Bn||(Bn={}));var _n;(function(e){let t;e.codec=()=>(t==null&&(t=St((r,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),r.messageIDs!=null)for(let s of r.messageIDs)n.uint32(10),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={messageIDs:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{if(o.limits?.messageIDs!=null&&s.messageIDs.length===o.limits.messageIDs)throw new Lt('Decode error - map field "messageIDs" had too many elements');s.messageIDs.push(r.bytes());break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(_n||(_n={}));var Ln;(function(e){let t;e.codec=()=>(t==null&&(t=St((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.topic!=null&&(n.uint32(10),n.string(r.topic)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.topic=r.string();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(Ln||(Ln={}));var Tn;(function(e){let t;e.codec=()=>(t==null&&(t=St((r,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),r.topic!=null&&(n.uint32(10),n.string(r.topic)),r.peers!=null)for(let s of r.peers)n.uint32(18),Dn.codec().encode(s,n);r.backoff!=null&&(n.uint32(24),n.uint64(r.backoff)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={peers:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.topic=r.string();break}case 2:{if(o.limits?.peers!=null&&s.peers.length===o.limits.peers)throw new Lt('Decode error - map field "peers" had too many elements');s.peers.push(Dn.codec().decode(r,r.uint32(),{limits:o.limits?.peers$}));break}case 3:{s.backoff=r.uint64();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(Tn||(Tn={}));var Dn;(function(e){let t;e.codec=()=>(t==null&&(t=St((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.peerID!=null&&(n.uint32(10),n.bytes(r.peerID)),r.signedPeerRecord!=null&&(n.uint32(18),n.bytes(r.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.peerID=r.bytes();break}case 2:{s.signedPeerRecord=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Et(r,e.codec()),e.decode=(r,n)=>xt(r,e.codec(),n)})(Dn||(Dn={}));var _s=class extends vn{seenCache;constructor(t,r){super(t,{...r,canRelayMessage:!0,multicodecs:[Bs]}),this.log=t.logger.forComponent("libp2p:floodsub"),this.seenCache=new An({validityMs:r?.seenTTL??3e4})}[Cs]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[Ps]=["@libp2p/pubsub"];[Ks]=["@libp2p/identify"];decodeRpc(t){return Be.decode(t)}encodeRpc(t){return Be.encode(t)}decodeMessage(t){return Be.Message.decode(t)}encodeMessage(t){return Be.Message.encode(t)}async processMessage(t,r){let n=await super.getMsgId(r),o=H(n,"base64");this.seenCache.has(o)||(this.seenCache.put(o,!0),await super.processMessage(t,r))}async publishMessage(t,r){let n=this.getSubscribers(r.topic),o=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:o}):(n.forEach(s=>{if(this.components.peerId.equals(s)){this.log("not sending message on topic %s to myself",r.topic);return}if(s.equals(t)){this.log("not sending message on topic %s to sender %p",r.topic,s);return}this.log("publish msgs on topics %s %p",r.topic,s),o.push(s),this.send(s,{messages:[r]})}),{recipients:o})}};function sl(e={}){return t=>new _s(t,e)}return ec(il);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: