@libp2p/floodsub 10.1.35 → 10.1.36
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 +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/message/rpc.d.ts +1 -1
- package/dist/src/message/rpc.d.ts.map +1 -1
- package/dist/src/message/rpc.js +0 -4
- package/dist/src/message/rpc.js.map +1 -1
- package/package.json +13 -20
- package/src/index.ts +2 -1
- package/src/message/rpc.ts +2 -5
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 Ra=Object.create;var Br=Object.defineProperty;var ka=Object.getOwnPropertyDescriptor;var Ua=Object.getOwnPropertyNames;var Ka=Object.getPrototypeOf,Ma=Object.prototype.hasOwnProperty;var Oa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),xt=(r,t)=>{for(var e in t)Br(r,e,{get:t[e],enumerable:!0})},ds=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ua(t))!Ma.call(r,o)&&o!==e&&Br(r,o,{get:()=>t[o],enumerable:!(n=ka(t,o))||n.enumerable});return r};var qa=(r,t,e)=>(e=r!=null?Ra(Ka(r)):{},ds(t||!r||!r.__esModule?Br(e,"default",{value:r,enumerable:!0}):e,r)),Ha=r=>ds(Br({},"__esModule",{value:!0}),r);var ma=Oa((Im,os)=>{"use strict";var Sf=Object.prototype.hasOwnProperty,bt="~";function xr(){}Object.create&&(xr.prototype=Object.create(null),new xr().__proto__||(bt=!1));function vf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function pa(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new vf(e,n||r,o),i=bt?bt+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function nn(r,t){--r._eventsCount===0?r._events=new xr:delete r._events[t]}function pt(){this._events=new xr,this._eventsCount=0}pt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Sf.call(e,n)&&t.push(bt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};pt.prototype.listeners=function(t){var e=bt?bt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};pt.prototype.listenerCount=function(t){var e=bt?bt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};pt.prototype.emit=function(t,e,n,o,s,i){var a=bt?bt+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,s),!0;case 6:return c.fn.call(c.context,e,n,o,s,i),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var b=c.length,v;for(l=0;l<b;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,e);break;case 3:c[l].fn.call(c[l].context,e,n);break;case 4:c[l].fn.call(c[l].context,e,n,o);break;default:if(!u)for(v=1,u=new Array(f-1);v<f;v++)u[v-1]=arguments[v];c[l].fn.apply(c[l].context,u)}}return!0};pt.prototype.on=function(t,e,n){return pa(this,t,e,n,!1)};pt.prototype.once=function(t,e,n){return pa(this,t,e,n,!0)};pt.prototype.removeListener=function(t,e,n,o){var s=bt?bt+t:t;if(!this._events[s])return this;if(!e)return nn(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&nn(this,s);else{for(var a=0,c=[],f=i.length;a<f;a++)(i[a].fn!==e||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:nn(this,s)}return this};pt.prototype.removeAllListeners=function(t){var e;return t?(e=bt?bt+t:t,this._events[e]&&nn(this,e)):(this._events=new xr,this._eventsCount=0),this};pt.prototype.off=pt.prototype.removeListener;pt.prototype.addListener=pt.prototype.on;pt.prefixed=bt;pt.EventEmitter=pt;typeof os<"u"&&(os.exports=pt)});var Pf={};xt(Pf,{floodsub:()=>Df,multicodec:()=>fs});var wn=Symbol.for("@libp2p/peer-id");var Ze;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ze||(Ze={}));var ps=Symbol.for("@libp2p/pubsub");var $=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ie=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var _r=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 Lr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ue=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Be=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var ms=Symbol.for("@libp2p/service-capabilities"),ys=Symbol.for("@libp2p/service-dependencies");var In={};xt(In,{base58btc:()=>j,base58flickr:()=>Ya});var sl=new Uint8Array(0);function bs(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ot(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function gs(r){return new TextEncoder().encode(r)}function xs(r){return new TextDecoder().decode(r)}function Va(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(I){if(I instanceof Uint8Array||(ArrayBuffer.isView(I)?I=new Uint8Array(I.buffer,I.byteOffset,I.byteLength):Array.isArray(I)&&(I=Uint8Array.from(I))),!(I instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(I.length===0)return"";for(var m=0,A=0,D=0,O=I.length;D!==O&&I[D]===0;)D++,m++;for(var x=(O-D)*u+1>>>0,h=new Uint8Array(x);D!==O;){for(var y=I[D],B=0,_=x-1;(y!==0||B<A)&&_!==-1;_--,B++)y+=256*h[_]>>>0,h[_]=y%a>>>0,y=y/a>>>0;if(y!==0)throw new Error("Non-zero carry");A=B,D++}for(var L=x-A;L!==x&&h[L]===0;)L++;for(var R=c.repeat(m);L<x;++L)R+=r.charAt(h[L]);return R}function b(I){if(typeof I!="string")throw new TypeError("Expected String");if(I.length===0)return new Uint8Array;var m=0;if(I[m]!==" "){for(var A=0,D=0;I[m]===c;)A++,m++;for(var O=(I.length-m)*f+1>>>0,x=new Uint8Array(O);I[m];){var h=e[I.charCodeAt(m)];if(h===255)return;for(var y=0,B=O-1;(h!==0||y<D)&&B!==-1;B--,y++)h+=a*x[B]>>>0,x[B]=h%256>>>0,h=h/256>>>0;if(h!==0)throw new Error("Non-zero carry");D=y,m++}if(I[m]!==" "){for(var _=O-D;_!==O&&x[_]===0;)_++;for(var L=new Uint8Array(A+(O-_)),R=A;_!==O;)L[R++]=x[_++];return L}}}function v(I){var m=b(I);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:b,decode:v}}var za=Va,Fa=za,Es=Fa;var En=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Sn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ss(this,t)}},vn=class{decoders;constructor(t){this.decoders=t}or(t){return Ss(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ss(r,t){return new vn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var An=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new En(t,e,n),this.decoder=new Sn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function _e({name:r,prefix:t,encode:e,decode:n}){return new An(r,t,e,n)}function Jt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Es(e,r);return _e({prefix:t,name:r,encode:n,decode:s=>Ot(o(s))})}function Ga(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),a=0,c=0,f=0;for(let u=0;u<s;++u){let l=o[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,a+=e,a>=8&&(a-=8,i[f++]=255&c>>a)}if(a>=e||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function Za(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function X({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return _e({prefix:t,name:r,encode(o){return Za(o,n,e)},decode(o){return Ga(o,n,e,r)}})}var j=Jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ya=Jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Bn={};xt(Bn,{base32:()=>Le,base32hex:()=>Xa,base32hexpad:()=>Qa,base32hexpadupper:()=>tc,base32hexupper:()=>Ja,base32pad:()=>$a,base32padupper:()=>ja,base32upper:()=>Wa,base32z:()=>ec});var Le=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Wa=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$a=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ja=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xa=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ja=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Qa=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tc=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ec=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _n={};xt(_n,{base36:()=>Ye,base36upper:()=>rc});var Ye=Jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rc=Jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var nc=Is,vs=128,oc=127,sc=~oc,ic=Math.pow(2,31);function Is(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ic;)t[e++]=r&255|vs,r/=128;for(;r≻)t[e++]=r&255|vs,r>>>=7;return t[e]=r|0,Is.bytes=e-n+1,t}var ac=Ln,cc=128,As=127;function Ln(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ln.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&As)<<o:(i&As)*Math.pow(2,o),o+=7}while(i>=cc);return Ln.bytes=s-n,e}var uc=Math.pow(2,7),fc=Math.pow(2,14),lc=Math.pow(2,21),hc=Math.pow(2,28),dc=Math.pow(2,35),pc=Math.pow(2,42),mc=Math.pow(2,49),yc=Math.pow(2,56),bc=Math.pow(2,63),gc=function(r){return r<uc?1:r<fc?2:r<lc?3:r<hc?4:r<dc?5:r<pc?6:r<mc?7:r<yc?8:r<bc?9:10},xc={encode:nc,decode:ac,encodingLength:gc},wc=xc,We=wc;function $e(r,t=0){return[We.decode(r,t),We.decode.bytes]}function Te(r,t,e=0){return We.encode(r,t,e),t}function De(r){return We.encodingLength(r)}function Dt(r,t){let e=t.byteLength,n=De(r),o=n+De(e),s=new Uint8Array(o+e);return Te(r,s,0),Te(e,s,n),s.set(t,o),new Pe(r,e,t,s)}function Qt(r){let t=Ot(r),[e,n]=$e(t),[o,s]=$e(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Pe(e,o,i,t)}function Bs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&bs(r.bytes,e.bytes)}}var Pe=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function _s(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Sc(e,Tn(r),t??j.encoder);default:return vc(e,Tn(r),t??Le.encoder)}}var Ls=new WeakMap;function Tn(r){let t=Ls.get(r);if(t==null){let e=new Map;return Ls.set(r,e),e}return t}var ft=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==je)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ac)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Dt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Bs(t.multihash,n.multihash)}toString(t){return _s(this,t)}toJSON(){return{"/":_s(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Ts(n,o,s.bytes))}else if(e[Ic]===!0){let{version:n,multihash:o,code:s}=e,i=Qt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==je)throw new Error(`Version 0 CID must use dag-pb (code: ${je}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ts(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,je,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Ot(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Pe(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,b]=$e(t.subarray(e));return e+=b,l},o=n(),s=je;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,e){let[n,o]=Ec(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Tn(s).set(n,t),s}};function Ec(r,t){switch(r[0]){case"Q":{let e=t??j;return[j.prefix,e.decode(`${j.prefix}${r}`)]}case j.prefix:{let e=t??j;return[j.prefix,e.decode(r)]}case Le.prefix:{let e=t??Le;return[Le.prefix,e.decode(r)]}case Ye.prefix:{let e=t??Ye;return[Ye.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Sc(r,t,e){let{prefix:n}=e;if(n!==j.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function vc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var je=112,Ac=18;function Ts(r,t,e){let n=De(r),o=n+De(t),s=new Uint8Array(o+e.byteLength);return Te(r,s,0),Te(t,s,n),s.set(e,o),s}var Ic=Symbol.for("@ipld/js-cid/CID");var Dn={};xt(Dn,{identity:()=>Pt});var Ds=0,Bc="identity",Ps=Ot;function _c(r){return Dt(Ds,Ps(r))}var Pt={code:Ds,name:Bc,encode:Ps,digest:_c};function wt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function qt(r=0){return new Uint8Array(r)}function lt(r=0){return new Uint8Array(r)}function fe(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=lt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Ns=Symbol.for("@achingbrain/uint8arraylist");function Cs(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Dr(r){return!!r?.[Ns]}var nt=class r{bufs;length;[Ns]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Dr(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Dr(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Cs(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Cs(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Dr(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return fe(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:fe(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=e>a&&e<=c;if(f&&u){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Dr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=e;l<=c;l+=u){u=0;for(let b=f;b>=0;b--){let v=this.get(l+b);if(n[b]!==v){u=Math.max(1,b-a[v]);break}}if(u===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=qt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=qt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=qt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=qt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=qt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=qt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=qt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=qt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!wt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Pn={};xt(Pn,{base10:()=>Lc});var Lc=Jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Cn={};xt(Cn,{base16:()=>Tc,base16upper:()=>Dc});var Tc=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Dc=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Nn={};xt(Nn,{base2:()=>Pc});var Pc=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Rn={};xt(Rn,{base256emoji:()=>Uc});var Rs=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}"),Cc=Rs.reduce((r,t,e)=>(r[e]=t,r),[]),Nc=Rs.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Rc(r){return r.reduce((t,e)=>(t+=Cc[e],t),"")}function kc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Nc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Uc=_e({prefix:"\u{1F680}",name:"base256emoji",encode:Rc,decode:kc});var kn={};xt(kn,{base64:()=>Kc,base64pad:()=>Mc,base64url:()=>Oc,base64urlpad:()=>qc});var Kc=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mc=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Oc=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),qc=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Un={};xt(Un,{base8:()=>Hc});var Hc=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Kn={};xt(Kn,{identity:()=>Vc});var Vc=_e({prefix:"\0",name:"identity",encode:r=>xs(r),decode:r=>gs(r)});var Vl=new TextEncoder,zl=new TextDecoder;var qn={};xt(qn,{sha256:()=>le,sha512:()=>Gc});function On({name:r,code:t,encode:e}){return new Mn(r,t,e)}var Mn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Dt(this.code,e):e.then(n=>Dt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Us(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var le=On({name:"sha2-256",code:18,encode:Us("SHA-256")}),Gc=On({name:"sha2-512",code:19,encode:Us("SHA-512")});var Hn={...Kn,...Nn,...Un,...Pn,...Cn,...Bn,..._n,...In,...kn,...Rn},eh={...qn,...Dn};function Ms(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ks=Ms("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Vn=Ms("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=lt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Zc={utf8:Ks,"utf-8":Ks,hex:Hn.base16,latin1:Vn,ascii:Vn,binary:Vn,...Hn},Pr=Zc;function Z(r,t="utf8"){let e=Pr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function G(r,t="utf8"){let e=Pr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Yc=parseInt("11111",2),zn=parseInt("10000000",2),Wc=parseInt("01111111",2),Os={0:Xe,1:Xe,2:$c,3:Jc,4:Qc,5:Xc,6:jc,16:Xe,22:Xe,48:Xe};function Ht(r,t={offset:0}){let e=r[t.offset]&Yc;if(t.offset++,Os[e]!=null)return Os[e](r,t);throw new Error("No decoder for tag "+e)}function Je(r,t){let e=0;if((r[t.offset]&zn)===zn){let n=r[t.offset]&Wc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Xe(r,t){Je(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Ht(r,t);if(n===null)break;e.push(n)}return e}function $c(r,t){let e=Je(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function jc(r,t){let e=Je(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function Xc(r,t){return t.offset++,null}function Jc(r,t){let e=Je(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Qc(r,t){let e=Je(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function tu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new nt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Fn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=tu(r.byteLength);return new nt(Uint8Array.from([t.byteLength|zn]),t)}function Et(r){let t=new nt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new nt(Uint8Array.from([2]),Fn(t),t)}function Cr(r){let t=Uint8Array.from([0]),e=new nt(t,r);return new nt(Uint8Array.from([3]),Fn(e),e)}function ee(r,t=48){let e=new nt;for(let n of r)e.append(n);return new nt(Uint8Array.from([t]),Fn(e),e)}async function qs(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var eu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ru=Uint8Array.from([6,5,43,129,4,0,34]),nu=Uint8Array.from([6,5,43,129,4,0,35]),ou={ext:!0,kty:"EC",crv:"P-256"},su={ext:!0,kty:"EC",crv:"P-384"},iu={ext:!0,kty:"EC",crv:"P-521"},Gn=32,Zn=48,Yn=66;function Wn(r){let t=Ht(r);return Hs(t)}function Hs(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Gn*2+1)return n=G(t.subarray(e,e+Gn),"base64url"),o=G(t.subarray(e+Gn),"base64url"),new Ce({...ou,key_ops:["verify"],x:n,y:o});if(t.byteLength===Zn*2+1)return n=G(t.subarray(e,e+Zn),"base64url"),o=G(t.subarray(e+Zn),"base64url"),new Ce({...su,key_ops:["verify"],x:n,y:o});if(t.byteLength===Yn*2+1)return n=G(t.subarray(e,e+Yn),"base64url"),o=G(t.subarray(e+Yn),"base64url"),new Ce({...iu,key_ops:["verify"],x:n,y:o});throw new $(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Vs(r){return ee([Et(Uint8Array.from([1])),ee([au(r.crv)],160),ee([Cr(new nt(Uint8Array.from([4]),Z(r.x??"","base64url"),Z(r.y??"","base64url")))],161)]).subarray()}function au(r){if(r==="P-256")return eu;if(r==="P-384")return ru;if(r==="P-521")return nu;throw new $(`Invalid curve ${r}`)}var Ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Vs(this.jwk)),this._raw}toMultihash(){return Pt.digest(Vt(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}async verify(t,e){return qs(this.jwk,e,t)}};var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function cu(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Nr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function de(r,...t){if(!cu(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function zs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Nr(r.outputLen),Nr(r.blockLen)}function Re(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Fs(r,t){de(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function zt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Rr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Ct(r,t){return r<<32-t|r>>>t}function Gs(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Qe(r){return typeof r=="string"&&(r=Gs(r)),de(r),r}function $n(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];de(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Ne=class{};function jn(r){let t=n=>r().update(Qe(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function ke(r=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(r));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function uu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,f=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+f,a,n)}function Zs(r,t,e){return r&t^~r&e}function Ys(r,t,e){return r&t^r&e^t&e}var tr=class extends Ne{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Rr(this.buffer)}update(t){Re(this),t=Qe(t),de(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Rr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),Fs(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,zt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;uu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Rr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ft=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var kr=BigInt(4294967295),Ws=BigInt(32);function fu(r,t=!1){return t?{h:Number(r&kr),l:Number(r>>Ws&kr)}:{h:Number(r>>Ws&kr)|0,l:Number(r&kr)|0}}function $s(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=fu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Xn=(r,t,e)=>r>>>e,Jn=(r,t,e)=>r<<32-e|t>>>e,pe=(r,t,e)=>r>>>e|t<<32-e,me=(r,t,e)=>r<<32-e|t>>>e,er=(r,t,e)=>r<<64-e|t>>>e-32,rr=(r,t,e)=>r>>>e-32|t<<64-e;function kt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var js=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Xs=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Js=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Qs=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,ti=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ei=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var hu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),re=new Uint32Array(64),Ur=class extends tr{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:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)re[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let b=re[l-15],v=re[l-2],I=Ct(b,7)^Ct(b,18)^b>>>3,m=Ct(v,17)^Ct(v,19)^v>>>10;re[l]=m+re[l-7]+I+re[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let b=Ct(a,6)^Ct(a,11)^Ct(a,25),v=u+b+Zs(a,c,f)+hu[l]+re[l]|0,m=(Ct(n,2)^Ct(n,13)^Ct(n,22))+Ys(n,o,s)|0;u=f,f=c,c=a,a=i+v|0,i=s,s=o,o=n,n=v+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){zt(re)}destroy(){this.set(0,0,0,0,0,0,0,0),zt(this.buffer)}};var ri=$s(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),du=ri[0],pu=ri[1],ne=new Uint32Array(80),oe=new Uint32Array(80),Qn=class extends tr{constructor(t=64){super(128,t,16,!1),this.Ah=ct[0]|0,this.Al=ct[1]|0,this.Bh=ct[2]|0,this.Bl=ct[3]|0,this.Ch=ct[4]|0,this.Cl=ct[5]|0,this.Dh=ct[6]|0,this.Dl=ct[7]|0,this.Eh=ct[8]|0,this.El=ct[9]|0,this.Fh=ct[10]|0,this.Fl=ct[11]|0,this.Gh=ct[12]|0,this.Gl=ct[13]|0,this.Hh=ct[14]|0,this.Hl=ct[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:b,Gh:v,Gl:I,Hh:m,Hl:A}=this;return[t,e,n,o,s,i,a,c,f,u,l,b,v,I,m,A]}set(t,e,n,o,s,i,a,c,f,u,l,b,v,I,m,A){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=b|0,this.Gh=v|0,this.Gl=I|0,this.Hh=m|0,this.Hl=A|0}process(t,e){for(let x=0;x<16;x++,e+=4)ne[x]=t.getUint32(e),oe[x]=t.getUint32(e+=4);for(let x=16;x<80;x++){let h=ne[x-15]|0,y=oe[x-15]|0,B=pe(h,y,1)^pe(h,y,8)^Xn(h,y,7),_=me(h,y,1)^me(h,y,8)^Jn(h,y,7),L=ne[x-2]|0,R=oe[x-2]|0,K=pe(L,R,19)^er(L,R,61)^Xn(L,R,6),P=me(L,R,19)^rr(L,R,61)^Jn(L,R,6),k=Js(_,P,oe[x-7],oe[x-16]),N=Qs(k,B,K,ne[x-7],ne[x-16]);ne[x]=N|0,oe[x]=k|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:b,Fh:v,Fl:I,Gh:m,Gl:A,Hh:D,Hl:O}=this;for(let x=0;x<80;x++){let h=pe(l,b,14)^pe(l,b,18)^er(l,b,41),y=me(l,b,14)^me(l,b,18)^rr(l,b,41),B=l&v^~l&m,_=b&I^~b&A,L=ti(O,y,_,pu[x],oe[x]),R=ei(L,D,h,B,du[x],ne[x]),K=L|0,P=pe(n,o,28)^er(n,o,34)^er(n,o,39),k=me(n,o,28)^rr(n,o,34)^rr(n,o,39),N=n&s^n&a^s&a,et=o&i^o&c^i&c;D=m|0,O=A|0,m=v|0,A=I|0,v=l|0,I=b|0,{h:l,l:b}=kt(f|0,u|0,R|0,K|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let E=js(K,k,et);n=Xs(E,R,P,N),o=E|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:f,l:u}=kt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:b}=kt(this.Eh|0,this.El|0,l|0,b|0),{h:v,l:I}=kt(this.Fh|0,this.Fl|0,v|0,I|0),{h:m,l:A}=kt(this.Gh|0,this.Gl|0,m|0,A|0),{h:D,l:O}=kt(this.Hh|0,this.Hl|0,D|0,O|0),this.set(n,o,s,i,a,c,f,u,l,b,v,I,m,A,D,O)}roundClean(){zt(ne,oe)}destroy(){zt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Kr=jn(()=>new Ur);var ni=jn(()=>new Qn);var no=BigInt(0),ro=BigInt(1);function Ue(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function oo(r){if(!Ue(r))throw new Error("Uint8Array expected")}function Ut(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function nr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function ii(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?no:BigInt("0x"+r)}var ai=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",mu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function se(r){if(oo(r),ai)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=mu[r[e]];return t}var Gt={_0:48,_9:57,A:65,F:70,a:97,f:102};function oi(r){if(r>=Gt._0&&r<=Gt._9)return r-Gt._0;if(r>=Gt.A&&r<=Gt.F)return r-(Gt.A-10);if(r>=Gt.a&&r<=Gt.f)return r-(Gt.a-10)}function or(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(ai)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=oi(r.charCodeAt(s)),a=oi(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Zt(r){return ii(se(r))}function ye(r){return oo(r),ii(se(Uint8Array.from(r).reverse()))}function be(r,t){return or(r.toString(16).padStart(t*2,"0"))}function Ke(r,t){return be(r,t).reverse()}function Y(r,t,e){let n;if(typeof t=="string")try{n=or(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Ue(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function ie(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];oo(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var to=r=>typeof r=="bigint"&&no<=r;function Mr(r,t,e){return to(r)&&to(t)&&to(e)&&t<=r&&r<e}function Bt(r,t,e,n){if(!Mr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ci(r){let t;for(t=0;r>no;r>>=ro,t+=1);return t}var ge=r=>(ro<<BigInt(r))-ro,eo=r=>new Uint8Array(r),si=r=>Uint8Array.from(r);function ui(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=eo(r),o=eo(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...l)=>e(o,n,...l),c=(l=eo(0))=>{o=a(si([0]),l),n=a(),l.length!==0&&(o=a(si([1]),l),n=a())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,b=[];for(;l<t;){n=a();let v=n.slice();b.push(v),l+=n.length}return ie(...b)};return(l,b)=>{i(),c(l);let v;for(;!(v=b(f()));)c();return i(),v}}var yu={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Ue(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Yt(r,t,e={}){let n=(o,s,i)=>{let a=yu[s];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}function Me(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var mt=BigInt(0),st=BigInt(1),xe=BigInt(2),bu=BigInt(3),li=BigInt(4),hi=BigInt(5),di=BigInt(8);function F(r,t){let e=r%t;return e>=mt?e:t+e}function W(r,t,e){let n=r;for(;t-- >mt;)n*=n,n%=e;return n}function Or(r,t){if(r===mt)throw new Error("invert: expected non-zero number");if(t<=mt)throw new Error("invert: expected positive modulus, got "+t);let e=F(r,t),n=t,o=mt,s=st,i=st,a=mt;for(;e!==mt;){let f=n/e,u=n%e,l=o-i*f,b=s-a*f;n=e,e=u,o=i,s=a,i=l,a=b}if(n!==st)throw new Error("invert: does not exist");return F(o,t)}function pi(r,t){let e=(r.ORDER+st)/li,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function gu(r,t){let e=(r.ORDER-hi)/di,n=r.mul(t,xe),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,xe),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function xu(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-st,e=0;for(;t%xe===mt;)t/=xe,e++;let n=xe,o=Wt(r);for(;fi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return pi;let s=o.pow(n,t),i=(t+st)/xe;return function(c,f){if(c.is0(f))return f;if(fi(c,f)!==1)throw new Error("Cannot find square root");let u=e,l=c.mul(c.ONE,s),b=c.pow(f,t),v=c.pow(f,i);for(;!c.eql(b,c.ONE);){if(c.is0(b))return c.ZERO;let I=1,m=c.sqr(b);for(;!c.eql(m,c.ONE);)if(I++,m=c.sqr(m),I===u)throw new Error("Cannot find square root");let A=st<<BigInt(u-I-1),D=c.pow(l,A);u=I,l=c.sqr(D),b=c.mul(b,l),v=c.mul(v,D)}return v}}function wu(r){return r%li===bu?pi:r%di===hi?gu:xu(r)}var mi=(r,t)=>(F(r,t)&st)===st,Eu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function so(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Eu.reduce((n,o)=>(n[o]="function",n),t);return Yt(r,e)}function Su(r,t,e){if(e<mt)throw new Error("invalid exponent, negatives unsupported");if(e===mt)return r.ONE;if(e===st)return t;let n=r.ONE,o=t;for(;e>mt;)e&st&&(n=r.mul(n,o)),o=r.sqr(o),e>>=st;return n}function Oe(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function fi(r,t){let e=(r.ORDER-st)/xe,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function io(r,t){t!==void 0&&Nr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Wt(r,t,e=!1,n={}){if(r<=mt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=io(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:ge(o),ZERO:mt,ONE:st,create:c=>F(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return mt<=c&&c<r},is0:c=>c===mt,isOdd:c=>(c&st)===st,neg:c=>F(-c,r),eql:(c,f)=>c===f,sqr:c=>F(c*c,r),add:(c,f)=>F(c+f,r),sub:(c,f)=>F(c-f,r),mul:(c,f)=>F(c*f,r),pow:(c,f)=>Su(a,c,f),div:(c,f)=>F(c*Or(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Or(c,r),sqrt:n.sqrt||(c=>(i||(i=wu(r)),i(a,c))),toBytes:c=>e?Ke(c,s):be(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?ye(c):Zt(c)},invertBatch:c=>Oe(a,c),cmov:(c,f,u)=>u?f:c});return Object.freeze(a)}function yi(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function ao(r){let t=yi(r);return t+Math.ceil(t/2)}function bi(r,t,e=!1){let n=r.length,o=yi(t),s=ao(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ye(r):Zt(r),a=F(i,t-st)+st;return e?Ke(a,o):be(a,o)}var gi=BigInt(0),ho=BigInt(1);function co(r,t){let e=t.negate();return r?e:t}function wi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function uo(r,t){wi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ge(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function xi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ho);let f=t*n,u=f+Math.abs(a)-1,l=a===0,b=a<0,v=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:b,isNegF:v,offsetF:f}}function vu(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Au(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var fo=new WeakMap,Ei=new WeakMap;function lo(r){return Ei.get(r)||1}function qr(r,t){return{constTimeNegate:co,hasPrecomputes(e){return lo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>gi;)n&ho&&(o=o.add(s)),s=s.double(),n>>=ho;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=uo(n,t),i=[],a=e,c=a;for(let f=0;f<o;f++){c=a,i.push(c);for(let u=1;u<s;u++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=uo(e,t);for(let c=0;c<a.windows;c++){let{nextN:f,offset:u,isZero:l,isNeg:b,isNegF:v,offsetF:I}=xi(o,c,a);o=f,l?i=i.add(co(v,n[I])):s=s.add(co(b,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=uo(e,t);for(let a=0;a<i.windows&&o!==gi;a++){let{nextN:c,offset:f,isZero:u,isNeg:l}=xi(o,a,i);if(o=c,!u){let b=n[f];s=s.add(l?b.negate():b)}}return s},getPrecomputes(e,n,o){let s=fo.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&fo.set(n,o(s))),s},wNAFCached(e,n,o){let s=lo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=lo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){wi(n,t),Ei.set(e,n),fo.delete(e)}}}function Hr(r,t,e,n){vu(e,r),Au(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=ci(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=ge(c),u=new Array(Number(f)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,b=i;for(let v=l;v>=0;v-=c){u.fill(i);for(let m=0;m<s;m++){let A=n[m],D=Number(A>>BigInt(v)&f);u[D]=u[D].add(e[m])}let I=i;for(let m=u.length-1,A=i;m>0;m--)A=A.add(u[m]),I=I.add(A);if(b=b.add(I),v!==0)for(let m=0;m<c;m++)b=b.double()}return b}function sr(r){return so(r.Fp),Yt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...io(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Kt=BigInt(0),yt=BigInt(1),Si=BigInt(2),Iu=BigInt(8),Bu={zip215:!0};function _u(r){let t=sr(r);return Yt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function vi(r){let t=_u(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,f=Si<<BigInt(a*8)-yt,u=e.create,l=Wt(t.n,t.nBitLength);function b(g,d){let p=e.sqr(g),S=e.sqr(d),C=e.add(e.mul(t.a,p),S),U=e.add(e.ONE,e.mul(t.d,e.mul(p,S)));return e.eql(C,U)}if(!b(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let v=t.uvRatio||((g,d)=>{try{return{isValid:!0,value:e.sqrt(g*e.inv(d))}}catch{return{isValid:!1,value:Kt}}}),I=t.adjustScalarBytes||(g=>g),m=t.domain||((g,d,p)=>{if(Ut("phflag",p),d.length||p)throw new Error("Contexts/pre-hash are not supported");return g});function A(g,d,p=!1){let S=p?yt:Kt;Bt("coordinate "+g,d,S,f)}function D(g){if(!(g instanceof h))throw new Error("ExtendedPoint expected")}let O=Me((g,d)=>{let{ex:p,ey:S,ez:C}=g,U=g.is0();d==null&&(d=U?Iu:e.inv(C));let M=u(p*d),q=u(S*d),H=u(C*d);if(U)return{x:Kt,y:yt};if(H!==yt)throw new Error("invZ was invalid");return{x:M,y:q}}),x=Me(g=>{let{a:d,d:p}=t;if(g.is0())throw new Error("bad point: ZERO");let{ex:S,ey:C,ez:U,et:M}=g,q=u(S*S),H=u(C*C),z=u(U*U),rt=u(z*z),J=u(q*d),at=u(z*u(J+H)),gt=u(rt+u(p*u(q*H)));if(at!==gt)throw new Error("bad point: equation left != right (1)");let ot=u(S*C),ut=u(U*M);if(ot!==ut)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(d,p,S,C){A("x",d),A("y",p),A("z",S,!0),A("t",C),this.ex=d,this.ey=p,this.ez=S,this.et=C,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof h)throw new Error("extended point not allowed");let{x:p,y:S}=d||{};return A("x",p),A("y",S),new h(p,S,yt,u(p*S))}static normalizeZ(d){let p=Oe(e,d.map(S=>S.ez));return d.map((S,C)=>S.toAffine(p[C])).map(h.fromAffine)}static msm(d,p){return Hr(h,l,d,p)}_setWindowSize(d){_.setWindowSize(this,d)}assertValidity(){x(this)}equals(d){D(d);let{ex:p,ey:S,ez:C}=this,{ex:U,ey:M,ez:q}=d,H=u(p*q),z=u(U*C),rt=u(S*q),J=u(M*C);return H===z&&rt===J}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:d}=t,{ex:p,ey:S,ez:C}=this,U=u(p*p),M=u(S*S),q=u(Si*u(C*C)),H=u(d*U),z=p+S,rt=u(u(z*z)-U-M),J=H+M,at=J-q,gt=H-M,ot=u(rt*at),ut=u(J*gt),It=u(rt*gt),Tt=u(at*J);return new h(ot,ut,Tt,It)}add(d){D(d);let{a:p,d:S}=t,{ex:C,ey:U,ez:M,et:q}=this,{ex:H,ey:z,ez:rt,et:J}=d,at=u(C*H),gt=u(U*z),ot=u(q*S*J),ut=u(M*rt),It=u((C+U)*(H+z)-at-gt),Tt=ut-ot,Ge=ut+ot,hs=u(gt-p*at),Da=u(It*Tt),Pa=u(Ge*hs),Ca=u(It*hs),Na=u(Tt*Ge);return new h(Da,Pa,Na,Ca)}subtract(d){return this.add(d.negate())}wNAF(d){return _.wNAFCached(this,d,h.normalizeZ)}multiply(d){let p=d;Bt("scalar",p,yt,n);let{p:S,f:C}=this.wNAF(p);return h.normalizeZ([S,C])[0]}multiplyUnsafe(d,p=h.ZERO){let S=d;return Bt("scalar",S,Kt,n),S===Kt?B:this.is0()||S===yt?this:_.wNAFCachedUnsafe(this,S,h.normalizeZ,p)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return _.unsafeLadder(this,n).is0()}toAffine(d){return O(this,d)}clearCofactor(){let{h:d}=t;return d===yt?this:this.multiplyUnsafe(d)}static fromHex(d,p=!1){let{d:S,a:C}=t,U=e.BYTES;d=Y("pointHex",d,U),Ut("zip215",p);let M=d.slice(),q=d[U-1];M[U-1]=q&-129;let H=ye(M),z=p?f:e.ORDER;Bt("pointHex.y",H,Kt,z);let rt=u(H*H),J=u(rt-yt),at=u(S*rt-C),{isValid:gt,value:ot}=v(J,at);if(!gt)throw new Error("Point.fromHex: invalid y coordinate");let ut=(ot&yt)===yt,It=(q&128)!==0;if(!p&&ot===Kt&&It)throw new Error("Point.fromHex: x=0 and x_0=1");return It!==ut&&(ot=u(-ot)),h.fromAffine({x:ot,y:H})}static fromPrivateKey(d){let{scalar:p}=K(d);return y.multiply(p)}toRawBytes(){let{x:d,y:p}=this.toAffine(),S=Ke(p,e.BYTES);return S[S.length-1]|=d&yt?128:0,S}toHex(){return se(this.toRawBytes())}}h.BASE=new h(t.Gx,t.Gy,yt,u(t.Gx*t.Gy)),h.ZERO=new h(Kt,yt,yt,Kt);let{BASE:y,ZERO:B}=h,_=qr(h,a*8);function L(g){return F(g,n)}function R(g){return L(ye(g))}function K(g){let d=e.BYTES;g=Y("private key",g,d);let p=Y("hashed private key",s(g),2*d),S=I(p.slice(0,d)),C=p.slice(d,2*d),U=R(S);return{head:S,prefix:C,scalar:U}}function P(g){let{head:d,prefix:p,scalar:S}=K(g),C=y.multiply(S),U=C.toRawBytes();return{head:d,prefix:p,scalar:S,point:C,pointBytes:U}}function k(g){return P(g).pointBytes}function N(g=Uint8Array.of(),...d){let p=ie(...d);return R(s(m(p,Y("context",g),!!o)))}function et(g,d,p={}){g=Y("message",g),o&&(g=o(g));let{prefix:S,scalar:C,pointBytes:U}=P(d),M=N(p.context,S,g),q=y.multiply(M).toRawBytes(),H=N(p.context,q,U,g),z=L(M+H*C);Bt("signature.s",z,Kt,n);let rt=ie(q,Ke(z,e.BYTES));return Y("result",rt,e.BYTES*2)}let E=Bu;function w(g,d,p,S=E){let{context:C,zip215:U}=S,M=e.BYTES;g=Y("signature",g,2*M),d=Y("message",d),p=Y("publicKey",p,M),U!==void 0&&Ut("zip215",U),o&&(d=o(d));let q=ye(g.slice(M,2*M)),H,z,rt;try{H=h.fromHex(p,U),z=h.fromHex(g.slice(0,M),U),rt=y.multiplyUnsafe(q)}catch{return!1}if(!U&&H.isSmallOrder())return!1;let J=N(C,z.toRawBytes(),H.toRawBytes(),d);return z.add(H.multiplyUnsafe(J)).subtract(rt).clearCofactor().equals(h.ZERO)}return y._setWindowSize(8),{CURVE:t,getPublicKey:k,sign:et,verify:w,ExtendedPoint:h,utils:{getExtendedPublicKey:P,randomPrivateKey:()=>i(e.BYTES),precompute(g=8,d=h.BASE){return d._setWindowSize(g),d.multiply(BigInt(3)),d}}}}var po=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ai=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),od=BigInt(0),Lu=BigInt(1),Ii=BigInt(2),sd=BigInt(3),Tu=BigInt(5),Du=BigInt(8);function Pu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=po,a=r*r%s*r%s,c=W(a,Ii,s)*a%s,f=W(c,Lu,s)*r%s,u=W(f,Tu,s)*f%s,l=W(u,t,s)*u%s,b=W(l,e,s)*l%s,v=W(b,n,s)*b%s,I=W(v,o,s)*v%s,m=W(I,o,s)*v%s,A=W(m,t,s)*u%s;return{pow_p_5_8:W(A,Ii,s)*r%s,b2:a}}function Cu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Nu(r,t){let e=po,n=F(t*t*t,e),o=F(n*n*t,e),s=Pu(r*o).pow_p_5_8,i=F(r*n*s,e),a=F(t*i*i,e),c=i,f=F(i*Ai,e),u=a===r,l=a===F(-r,e),b=a===F(-r*Ai,e);return u&&(i=c),(l||b)&&(i=f),mi(i,e)&&(i=F(-i,e)),{isValid:u||l,value:i}}var Bi=Wt(po,void 0,!0),Ru={a:Bi.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Bi,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Du,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ni,randomBytes:ke,adjustScalarBytes:Cu,uvRatio:Nu},_i=vi(Ru);var Vr=32;function Li(r,t,e){return _i.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var zr=class{type="Ed25519";raw;constructor(t){this.raw=mo(t,Vr)}toMultihash(){return Pt.digest(Vt(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return Li(this.raw,e,t)}};function yo(r){return r=mo(r,Vr),new zr(r)}function mo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new $(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Uu=Math.pow(2,7),Ku=Math.pow(2,14),Mu=Math.pow(2,21),bo=Math.pow(2,28),go=Math.pow(2,35),xo=Math.pow(2,42),wo=Math.pow(2,49),V=128,ht=127;function Nt(r){if(r<Uu)return 1;if(r<Ku)return 2;if(r<Mu)return 3;if(r<bo)return 4;if(r<go)return 5;if(r<xo)return 6;if(r<wo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Eo(r,t,e=0){switch(Nt(r)){case 8:t[e++]=r&255|V,r/=128;case 7:t[e++]=r&255|V,r/=128;case 6:t[e++]=r&255|V,r/=128;case 5:t[e++]=r&255|V,r/=128;case 4:t[e++]=r&255|V,r>>>=7;case 3:t[e++]=r&255|V,r>>>=7;case 2:t[e++]=r&255|V,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Ou(r,t,e=0){switch(Nt(r)){case 8:t.set(e++,r&255|V),r/=128;case 7:t.set(e++,r&255|V),r/=128;case 6:t.set(e++,r&255|V),r/=128;case 5:t.set(e++,r&255|V),r/=128;case 4:t.set(e++,r&255|V),r>>>=7;case 3:t.set(e++,r&255|V),r>>>=7;case 2:t.set(e++,r&255|V),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function So(r,t){let e=r[t],n=0;if(n+=e&ht,e<V||(e=r[t+1],n+=(e&ht)<<7,e<V)||(e=r[t+2],n+=(e&ht)<<14,e<V)||(e=r[t+3],n+=(e&ht)<<21,e<V)||(e=r[t+4],n+=(e&ht)*bo,e<V)||(e=r[t+5],n+=(e&ht)*go,e<V)||(e=r[t+6],n+=(e&ht)*xo,e<V)||(e=r[t+7],n+=(e&ht)*wo,e<V))return n;throw new RangeError("Could not decode varint")}function qu(r,t){let e=r.get(t),n=0;if(n+=e&ht,e<V||(e=r.get(t+1),n+=(e&ht)<<7,e<V)||(e=r.get(t+2),n+=(e&ht)<<14,e<V)||(e=r.get(t+3),n+=(e&ht)<<21,e<V)||(e=r.get(t+4),n+=(e&ht)*bo,e<V)||(e=r.get(t+5),n+=(e&ht)*go,e<V)||(e=r.get(t+6),n+=(e&ht)*xo,e<V)||(e=r.get(t+7),n+=(e&ht)*wo,e<V))return n;throw new RangeError("Could not decode varint")}function Di(r,t,e=0){return t==null&&(t=lt(Nt(r))),t instanceof Uint8Array?Eo(r,t,e):Ou(r,t,e)}function Pi(r,t=0){return r instanceof Uint8Array?So(r,t):qu(r,t)}var vo=new Float32Array([-0]),ae=new Uint8Array(vo.buffer);function Ni(r,t,e){vo[0]=r,t[e]=ae[0],t[e+1]=ae[1],t[e+2]=ae[2],t[e+3]=ae[3]}function Ri(r,t){return ae[0]=r[t],ae[1]=r[t+1],ae[2]=r[t+2],ae[3]=r[t+3],vo[0]}var Ao=new Float64Array([-0]),dt=new Uint8Array(Ao.buffer);function ki(r,t,e){Ao[0]=r,t[e]=dt[0],t[e+1]=dt[1],t[e+2]=dt[2],t[e+3]=dt[3],t[e+4]=dt[4],t[e+5]=dt[5],t[e+6]=dt[6],t[e+7]=dt[7]}function Ui(r,t){return dt[0]=r[t],dt[1]=r[t+1],dt[2]=r[t+2],dt[3]=r[t+3],dt[4]=r[t+4],dt[5]=r[t+5],dt[6]=r[t+6],dt[7]=r[t+7],Ao[0]}var Hu=BigInt(Number.MAX_SAFE_INTEGER),Vu=BigInt(Number.MIN_SAFE_INTEGER),_t=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return we;if(t<Hu&&t>Vu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Ki&&(o=0n,++n>Ki&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return we;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):we}},we=new _t(0,0);we.toBigInt=function(){return 0n};we.zzEncode=we.zzDecode=function(){return this};we.length=function(){return 1};var Ki=4294967296n;function Mi(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Oi(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Io(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Rt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Fr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Bo=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,Rt(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 Rt(this,4);return Fr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Rt(this,4);return Fr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Rt(this,4);let t=Ri(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Rt(this,4);let t=Ui(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Rt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Oi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Rt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Rt(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 _t(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Rt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Rt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Rt(this,8);let t=Fr(this.buf,this.pos+=4),e=Fr(this.buf,this.pos+=4);return new _t(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=So(this.buf,this.pos);return this.pos+=Nt(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 _o(r){return new Bo(r instanceof Uint8Array?r:r.subarray())}function St(r,t,e){let n=_o(r);return t.decode(n,void 0,e)}function Lo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return lt(i);o+i>t&&(n=lt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ee=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function To(){}var Po=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},zu=Lo();function Fu(r){return globalThis.Buffer!=null?lt(r):zu(r)}var ar=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ee(To,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ee(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Co((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(Gr,10,_t.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=_t.fromBigInt(t);return this._push(Gr,e.length(),e)}uint64Number(t){return this._push(Eo,Nt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=_t.fromBigInt(t).zzEncode();return this._push(Gr,e.length(),e)}sint64Number(t){let e=_t.fromNumber(t).zzEncode();return this._push(Gr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Do,1,t?1:0)}fixed32(t){return this._push(ir,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=_t.fromBigInt(t);return this._push(ir,4,e.lo)._push(ir,4,e.hi)}fixed64Number(t){let e=_t.fromNumber(t);return this._push(ir,4,e.lo)._push(ir,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ni,4,t)}double(t){return this._push(ki,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Do,1,0):this.uint32(e)._push(Zu,e,t)}string(t){let e=Mi(t);return e!==0?this.uint32(e)._push(Io,e,t):this._push(Do,1,0)}fork(){return this.states=new Po(this),this.head=this.tail=new Ee(To,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Ee(To,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Fu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Do(r,t,e){t[e]=r&255}function Gu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Co=class extends Ee{next;constructor(t,e){super(Gu,t,e),this.next=void 0}};function Gr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function ir(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Zu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ar.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Yu,t,r),this},ar.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Wu,t,r),this});function Yu(r,t,e){t.set(r,e)}function Wu(r,t,e){r.length<40?Io(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Z(r),e)}function No(){return new ar}function vt(r,t){let e=No();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var qe;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(qe||(qe={}));function Zr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ro(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Zr("enum",qe.VARINT,e,n)}function At(r,t){return Zr("message",qe.LENGTH_DELIMITED,r,t)}var Lt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var ko;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ko||(ko={}));(function(r){r.codec=()=>Ro(ko)})(tt||(tt={}));var Mt;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(Mt||(Mt={}));var Uo;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(Uo||(Uo={}));function Yr(r){if(isNaN(r)||r<=0)throw new $("random bytes length must be a Number bigger than 0");return ke(r)}var cr=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 Vi={get(r=globalThis){let t=r.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 ce=Vi;var fr={};xt(fr,{MAX_RSA_KEY_SIZE:()=>Ko,generateRSAKeyPair:()=>Zi,jwkToJWKKeyPair:()=>Yi,jwkToPkcs1:()=>Ju,jwkToPkix:()=>Ho,jwkToRSAPrivateKey:()=>Go,pkcs1MessageToJwk:()=>Oo,pkcs1MessageToRSAPrivateKey:()=>Vo,pkcs1ToJwk:()=>Xu,pkcs1ToRSAPrivateKey:()=>Gi,pkixMessageToJwk:()=>qo,pkixMessageToRSAPublicKey:()=>Fo,pkixToJwk:()=>Qu,pkixToRSAPublicKey:()=>zo});var $r=Kr;var He=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=fr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ft.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return Fi(this.jwk,e,t)}},ur=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=fr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}sign(t){return zi(this.jwk,t)}};var Ko=8192,Mo=18,$u=1062,ju=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Xu(r){let t=Ht(r);return Oo(t)}function Oo(r){return{n:G(r[1],"base64url"),e:G(r[2],"base64url"),d:G(r[3],"base64url"),p:G(r[4],"base64url"),q:G(r[5],"base64url"),dp:G(r[6],"base64url"),dq:G(r[7],"base64url"),qi:G(r[8],"base64url"),kty:"RSA"}}function Ju(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new $("JWK was missing components");return ee([Et(Uint8Array.from([0])),Et(Z(r.n,"base64url")),Et(Z(r.e,"base64url")),Et(Z(r.d,"base64url")),Et(Z(r.p,"base64url")),Et(Z(r.q,"base64url")),Et(Z(r.dp,"base64url")),Et(Z(r.dq,"base64url")),Et(Z(r.qi,"base64url"))]).subarray()}function Qu(r){let t=Ht(r,{offset:0});return qo(t)}function qo(r){let t=Ht(r[1],{offset:0});return{kty:"RSA",n:G(t[0],"base64url"),e:G(t[1],"base64url")}}function Ho(r){if(r.n==null||r.e==null)throw new $("JWK was missing components");return ee([ju,Cr(ee([Et(Z(r.n,"base64url")),Et(Z(r.e,"base64url"))]))]).subarray()}function Gi(r){let t=Ht(r);return Vo(t)}function Vo(r){let t=Oo(r);return Go(t)}function zo(r,t){if(r.byteLength>=$u)throw new Ie("Key size is too large");let e=Ht(r,{offset:0});return Fo(e,r,t)}function Fo(r,t,e){let n=qo(r);if(e==null){let o=$r(Mt.encode({Type:tt.RSA,Data:t}));e=Dt(Mo,o)}return new He(n,e)}function Go(r){if($i(r)>Ko)throw new $("Key size is too large");let t=Yi(r),e=$r(Mt.encode({Type:tt.RSA,Data:Ho(t.publicKey)})),n=Dt(Mo,e);return new ur(t.privateKey,new He(t.publicKey,n))}async function Zi(r){if(r>Ko)throw new $("Key size is too large");let t=await Wi(r),e=$r(Mt.encode({Type:tt.RSA,Data:Ho(t.publicKey)})),n=Dt(Mo,e);return new ur(t.privateKey,new He(t.publicKey,n))}function Yi(r){if(r==null)throw new $("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Wi(r){let t=await ce.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await tf(t);return{privateKey:e[0],publicKey:e[1]}}async function zi(r,t){let e=await ce.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await ce.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Fi(r,t,e){let n=await ce.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return ce.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function tf(r){if(r.privateKey==null||r.publicKey==null)throw new $("Private and public key are required");return Promise.all([ce.get().subtle.exportKey("jwk",r.privateKey),ce.get().subtle.exportKey("jwk",r.publicKey)])}function $i(r){if(r.kty!=="RSA")throw new $("invalid key type");if(r.n==null)throw new $("invalid key modulus");return Z(r.n,"base64url").length*8}var jr=class extends Ne{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,zs(t);let n=Qe(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),zt(s)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(this),de(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Zo=(r,t,e)=>new jr(r,t).update(e).digest();Zo.create=(r,t)=>new jr(r,t);function ji(r){r.lowS!==void 0&&Ut("lowS",r.lowS),r.prehash!==void 0&&Ut("prehash",r.prehash)}function ef(r){let t=sr(r);Yt(t,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...t})}var $o=class extends Error{constructor(t=""){super(t)}},$t={Err:$o,_tlv:{encode:(r,t)=>{let{Err:e}=$t;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=nr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?nr(o.length/2|128):"";return nr(r)+s+o+t},decode(r,t){let{Err:e}=$t,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=$t;if(r<jt)throw new t("integer: negative integers are not allowed");let e=nr(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=$t;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Zt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=$t,o=Y("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=$t,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};function Yo(r,t){return se(be(r,t))}var jt=BigInt(0),it=BigInt(1),Kp=BigInt(2),Wo=BigInt(3),rf=BigInt(4);function nf(r){let t=ef(r),{Fp:e}=t,n=Wt(t.n,t.nBitLength),o=t.toBytes||((x,h,y)=>{let B=h.toAffine();return ie(Uint8Array.from([4]),e.toBytes(B.x),e.toBytes(B.y))}),s=t.fromBytes||(x=>{let h=x.subarray(1),y=e.fromBytes(h.subarray(0,e.BYTES)),B=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:y,y:B}});function i(x){let{a:h,b:y}=t,B=e.sqr(x),_=e.mul(B,x);return e.add(e.add(_,e.mul(x,h)),y)}function a(x,h){let y=e.sqr(h),B=i(x);return e.eql(y,B)}if(!a(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let c=e.mul(e.pow(t.a,Wo),rf),f=e.mul(e.sqr(t.b),BigInt(27));if(e.is0(e.add(c,f)))throw new Error("bad curve params: a or b");function u(x){return Mr(x,it,t.n)}function l(x){let{allowedPrivateKeyLengths:h,nByteLength:y,wrapPrivateKey:B,n:_}=t;if(h&&typeof x!="bigint"){if(Ue(x)&&(x=se(x)),typeof x!="string"||!h.includes(x.length))throw new Error("invalid private key");x=x.padStart(y*2,"0")}let L;try{L=typeof x=="bigint"?x:Zt(Y("private key",x,y))}catch{throw new Error("invalid private key, expected hex or "+y+" bytes, got "+typeof x)}return B&&(L=F(L,_)),Bt("private key",L,it,_),L}function b(x){if(!(x instanceof m))throw new Error("ProjectivePoint expected")}let v=Me((x,h)=>{let{px:y,py:B,pz:_}=x;if(e.eql(_,e.ONE))return{x:y,y:B};let L=x.is0();h==null&&(h=L?e.ONE:e.inv(_));let R=e.mul(y,h),K=e.mul(B,h),P=e.mul(_,h);if(L)return{x:e.ZERO,y:e.ZERO};if(!e.eql(P,e.ONE))throw new Error("invZ was invalid");return{x:R,y:K}}),I=Me(x=>{if(x.is0()){if(t.allowInfinityPoint&&!e.is0(x.py))return;throw new Error("bad point: ZERO")}let{x:h,y}=x.toAffine();if(!e.isValid(h)||!e.isValid(y))throw new Error("bad point: x or y not FE");if(!a(h,y))throw new Error("bad point: equation left != right");if(!x.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class m{constructor(h,y,B){if(h==null||!e.isValid(h))throw new Error("x required");if(y==null||!e.isValid(y)||e.is0(y))throw new Error("y required");if(B==null||!e.isValid(B))throw new Error("z required");this.px=h,this.py=y,this.pz=B,Object.freeze(this)}static fromAffine(h){let{x:y,y:B}=h||{};if(!h||!e.isValid(y)||!e.isValid(B))throw new Error("invalid affine point");if(h instanceof m)throw new Error("projective point not allowed");let _=L=>e.eql(L,e.ZERO);return _(y)&&_(B)?m.ZERO:new m(y,B,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let y=Oe(e,h.map(B=>B.pz));return h.map((B,_)=>B.toAffine(y[_])).map(m.fromAffine)}static fromHex(h){let y=m.fromAffine(s(Y("pointHex",h)));return y.assertValidity(),y}static fromPrivateKey(h){return m.BASE.multiply(l(h))}static msm(h,y){return Hr(m,n,h,y)}_setWindowSize(h){O.setWindowSize(this,h)}assertValidity(){I(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){b(h);let{px:y,py:B,pz:_}=this,{px:L,py:R,pz:K}=h,P=e.eql(e.mul(y,K),e.mul(L,_)),k=e.eql(e.mul(B,K),e.mul(R,_));return P&&k}negate(){return new m(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:y}=t,B=e.mul(y,Wo),{px:_,py:L,pz:R}=this,K=e.ZERO,P=e.ZERO,k=e.ZERO,N=e.mul(_,_),et=e.mul(L,L),E=e.mul(R,R),w=e.mul(_,L);return w=e.add(w,w),k=e.mul(_,R),k=e.add(k,k),K=e.mul(h,k),P=e.mul(B,E),P=e.add(K,P),K=e.sub(et,P),P=e.add(et,P),P=e.mul(K,P),K=e.mul(w,K),k=e.mul(B,k),E=e.mul(h,E),w=e.sub(N,E),w=e.mul(h,w),w=e.add(w,k),k=e.add(N,N),N=e.add(k,N),N=e.add(N,E),N=e.mul(N,w),P=e.add(P,N),E=e.mul(L,R),E=e.add(E,E),N=e.mul(E,w),K=e.sub(K,N),k=e.mul(E,et),k=e.add(k,k),k=e.add(k,k),new m(K,P,k)}add(h){b(h);let{px:y,py:B,pz:_}=this,{px:L,py:R,pz:K}=h,P=e.ZERO,k=e.ZERO,N=e.ZERO,et=t.a,E=e.mul(t.b,Wo),w=e.mul(y,L),T=e.mul(B,R),g=e.mul(_,K),d=e.add(y,B),p=e.add(L,R);d=e.mul(d,p),p=e.add(w,T),d=e.sub(d,p),p=e.add(y,_);let S=e.add(L,K);return p=e.mul(p,S),S=e.add(w,g),p=e.sub(p,S),S=e.add(B,_),P=e.add(R,K),S=e.mul(S,P),P=e.add(T,g),S=e.sub(S,P),N=e.mul(et,p),P=e.mul(E,g),N=e.add(P,N),P=e.sub(T,N),N=e.add(T,N),k=e.mul(P,N),T=e.add(w,w),T=e.add(T,w),g=e.mul(et,g),p=e.mul(E,p),T=e.add(T,g),g=e.sub(w,g),g=e.mul(et,g),p=e.add(p,g),w=e.mul(T,p),k=e.add(k,w),w=e.mul(S,p),P=e.mul(d,P),P=e.sub(P,w),w=e.mul(d,T),N=e.mul(S,N),N=e.add(N,w),new m(P,k,N)}subtract(h){return this.add(h.negate())}is0(){return this.equals(m.ZERO)}wNAF(h){return O.wNAFCached(this,h,m.normalizeZ)}multiplyUnsafe(h){let{endo:y,n:B}=t;Bt("scalar",h,jt,B);let _=m.ZERO;if(h===jt)return _;if(this.is0()||h===it)return this;if(!y||O.hasPrecomputes(this))return O.wNAFCachedUnsafe(this,h,m.normalizeZ);let{k1neg:L,k1:R,k2neg:K,k2:P}=y.splitScalar(h),k=_,N=_,et=this;for(;R>jt||P>jt;)R&it&&(k=k.add(et)),P&it&&(N=N.add(et)),et=et.double(),R>>=it,P>>=it;return L&&(k=k.negate()),K&&(N=N.negate()),N=new m(e.mul(N.px,y.beta),N.py,N.pz),k.add(N)}multiply(h){let{endo:y,n:B}=t;Bt("scalar",h,it,B);let _,L;if(y){let{k1neg:R,k1:K,k2neg:P,k2:k}=y.splitScalar(h),{p:N,f:et}=this.wNAF(K),{p:E,f:w}=this.wNAF(k);N=O.constTimeNegate(R,N),E=O.constTimeNegate(P,E),E=new m(e.mul(E.px,y.beta),E.py,E.pz),_=N.add(E),L=et.add(w)}else{let{p:R,f:K}=this.wNAF(h);_=R,L=K}return m.normalizeZ([_,L])[0]}multiplyAndAddUnsafe(h,y,B){let _=m.BASE,L=(K,P)=>P===jt||P===it||!K.equals(_)?K.multiplyUnsafe(P):K.multiply(P),R=L(this,y).add(L(h,B));return R.is0()?void 0:R}toAffine(h){return v(this,h)}isTorsionFree(){let{h,isTorsionFree:y}=t;if(h===it)return!0;if(y)return y(m,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:y}=t;return h===it?this:y?y(m,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Ut("isCompressed",h),this.assertValidity(),o(m,this,h)}toHex(h=!0){return Ut("isCompressed",h),se(this.toRawBytes(h))}}m.BASE=new m(t.Gx,t.Gy,e.ONE),m.ZERO=new m(e.ZERO,e.ONE,e.ZERO);let{endo:A,nBitLength:D}=t,O=qr(m,A?Math.ceil(D/2):D);return{CURVE:t,ProjectivePoint:m,normPrivateKeyToScalar:l,weierstrassEquation:i,isWithinCurveOrder:u}}function of(r){let t=sr(r);return Yt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Xi(r){let t=of(r),{Fp:e,n,nByteLength:o,nBitLength:s}=t,i=e.BYTES+1,a=2*e.BYTES+1;function c(E){return F(E,n)}function f(E){return Or(E,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:b,isWithinCurveOrder:v}=nf({...t,toBytes(E,w,T){let g=w.toAffine(),d=e.toBytes(g.x),p=ie;return Ut("isCompressed",T),T?p(Uint8Array.from([w.hasEvenY()?2:3]),d):p(Uint8Array.from([4]),d,e.toBytes(g.y))},fromBytes(E){let w=E.length,T=E[0],g=E.subarray(1);if(w===i&&(T===2||T===3)){let d=Zt(g);if(!Mr(d,it,e.ORDER))throw new Error("Point is not on curve");let p=b(d),S;try{S=e.sqrt(p)}catch(M){let q=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+q)}let C=(S&it)===it;return(T&1)===1!==C&&(S=e.neg(S)),{x:d,y:S}}else if(w===a&&T===4){let d=e.fromBytes(g.subarray(0,e.BYTES)),p=e.fromBytes(g.subarray(e.BYTES,2*e.BYTES));return{x:d,y:p}}else{let d=i,p=a;throw new Error("invalid Point, expected length of "+d+", or uncompressed "+p+", got "+w)}}});function I(E){let w=n>>it;return E>w}function m(E){return I(E)?c(-E):E}let A=(E,w,T)=>Zt(E.slice(w,T));class D{constructor(w,T,g){Bt("r",w,it,n),Bt("s",T,it,n),this.r=w,this.s=T,g!=null&&(this.recovery=g),Object.freeze(this)}static fromCompact(w){let T=o;return w=Y("compactSignature",w,T*2),new D(A(w,0,T),A(w,T,2*T))}static fromDER(w){let{r:T,s:g}=$t.toSig(Y("DER",w));return new D(T,g)}assertValidity(){}addRecoveryBit(w){return new D(this.r,this.s,w)}recoverPublicKey(w){let{r:T,s:g,recovery:d}=this,p=_(Y("msgHash",w));if(d==null||![0,1,2,3].includes(d))throw new Error("recovery id invalid");let S=d===2||d===3?T+t.n:T;if(S>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let C=(d&1)===0?"02":"03",U=u.fromHex(C+Yo(S,e.BYTES)),M=f(S),q=c(-p*M),H=c(g*M),z=u.BASE.multiplyAndAddUnsafe(U,q,H);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return I(this.s)}normalizeS(){return this.hasHighS()?new D(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return or(this.toDERHex())}toDERHex(){return $t.hexFromSig(this)}toCompactRawBytes(){return or(this.toCompactHex())}toCompactHex(){let w=o;return Yo(this.r,w)+Yo(this.s,w)}}let O={isValidPrivateKey(E){try{return l(E),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let E=ao(t.n);return bi(t.randomBytes(E),t.n)},precompute(E=8,w=u.BASE){return w._setWindowSize(E),w.multiply(BigInt(3)),w}};function x(E,w=!0){return u.fromPrivateKey(E).toRawBytes(w)}function h(E){if(typeof E=="bigint")return!1;if(E instanceof u)return!0;let T=Y("key",E).length,g=e.BYTES,d=g+1,p=2*g+1;if(!(t.allowedPrivateKeyLengths||o===d))return T===d||T===p}function y(E,w,T=!0){if(h(E)===!0)throw new Error("first arg must be private key");if(h(w)===!1)throw new Error("second arg must be public key");return u.fromHex(w).multiply(l(E)).toRawBytes(T)}let B=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let w=Zt(E),T=E.length*8-s;return T>0?w>>BigInt(T):w},_=t.bits2int_modN||function(E){return c(B(E))},L=ge(s);function R(E){return Bt("num < 2^"+s,E,jt,L),be(E,o)}function K(E,w,T=P){if(["recovered","canonical"].some(J=>J in T))throw new Error("sign() legacy options not supported");let{hash:g,randomBytes:d}=t,{lowS:p,prehash:S,extraEntropy:C}=T;p==null&&(p=!0),E=Y("msgHash",E),ji(T),S&&(E=Y("prehashed msgHash",g(E)));let U=_(E),M=l(w),q=[R(M),R(U)];if(C!=null&&C!==!1){let J=C===!0?d(e.BYTES):C;q.push(Y("extraEntropy",J))}let H=ie(...q),z=U;function rt(J){let at=B(J);if(!v(at))return;let gt=f(at),ot=u.BASE.multiply(at).toAffine(),ut=c(ot.x);if(ut===jt)return;let It=c(gt*c(z+ut*M));if(It===jt)return;let Tt=(ot.x===ut?0:2)|Number(ot.y&it),Ge=It;return p&&I(It)&&(Ge=m(It),Tt^=1),new D(ut,Ge,Tt)}return{seed:H,k2sig:rt}}let P={lowS:t.lowS,prehash:!1},k={lowS:t.lowS,prehash:!1};function N(E,w,T=P){let{seed:g,k2sig:d}=K(E,w,T),p=t;return ui(p.hash.outputLen,p.nByteLength,p.hmac)(g,d)}u.BASE._setWindowSize(8);function et(E,w,T,g=k){let d=E;w=Y("msgHash",w),T=Y("publicKey",T);let{lowS:p,prehash:S,format:C}=g;if(ji(g),"strict"in g)throw new Error("options.strict was renamed to lowS");if(C!==void 0&&C!=="compact"&&C!=="der")throw new Error("format must be compact or der");let U=typeof d=="string"||Ue(d),M=!U&&!C&&typeof d=="object"&&d!==null&&typeof d.r=="bigint"&&typeof d.s=="bigint";if(!U&&!M)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let q,H;try{if(M&&(q=new D(d.r,d.s)),U){try{C!=="compact"&&(q=D.fromDER(d))}catch(Tt){if(!(Tt instanceof $t.Err))throw Tt}!q&&C!=="der"&&(q=D.fromCompact(d))}H=u.fromHex(T)}catch{return!1}if(!q||p&&q.hasHighS())return!1;S&&(w=t.hash(w));let{r:z,s:rt}=q,J=_(w),at=f(rt),gt=c(J*at),ot=c(z*at),ut=u.BASE.multiplyAndAddUnsafe(H,gt,ot)?.toAffine();return ut?c(ut.x)===z:!1}return{CURVE:t,getPublicKey:x,getSharedSecret:y,sign:N,verify:et,ProjectivePoint:u,Signature:D,utils:O}}function sf(r){return{hash:r,hmac:(t,...e)=>Zo(r,t,$n(...e)),randomBytes:ke}}function Ji(r,t){let e=n=>Xi({...r,...sf(n)});return{...e(t),create:e}}var ea=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Qi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),af=BigInt(0),cf=BigInt(1),jo=BigInt(2),ta=(r,t)=>(r+t/jo)/t;function uf(r){let t=ea,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,u=f*f*r%t,l=W(u,e,t)*u%t,b=W(l,e,t)*u%t,v=W(b,jo,t)*f%t,I=W(v,o,t)*v%t,m=W(I,s,t)*I%t,A=W(m,a,t)*m%t,D=W(A,c,t)*A%t,O=W(D,a,t)*m%t,x=W(O,e,t)*u%t,h=W(x,i,t)*I%t,y=W(h,n,t)*f%t,B=W(y,jo,t);if(!Xo.eql(Xo.sqr(B),r))throw new Error("Cannot find square root");return B}var Xo=Wt(ea,void 0,void 0,{sqrt:uf}),Ve=Ji({a:af,b:BigInt(7),Fp:Xo,n:Qi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Qi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-cf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=ta(s*r,t),c=ta(-n*r,t),f=F(r-a*e-c*o,t),u=F(-a*n-c*s,t),l=f>i,b=u>i;if(l&&(f=t-f),b&&(u=t-u),f>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:b,k2:u}}}},Kr);function ra(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function na(r,t,e){let n=le.digest(e instanceof Uint8Array?e:e.subarray());if(ra(n))return n.then(({digest:o})=>Ve.verify(t,o,r)).catch(o=>{throw new cr(String(o))});try{return Ve.verify(t,n.digest,r)}catch(o){throw new cr(String(o))}}var Xr=class{type="secp256k1";raw;_key;constructor(t){this._key=sa(t),this.raw=oa(this._key)}toMultihash(){return Pt.digest(Vt(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return na(this._key,e,t)}};function Jo(r){return new Xr(r)}function oa(r){return Ve.ProjectivePoint.fromHex(r).toRawBytes(!0)}function sa(r){try{return Ve.ProjectivePoint.fromHex(r),r}catch(t){throw new Ie(String(t))}}function Qo(r,t){let{Type:e,Data:n}=Mt.decode(r),o=n??new Uint8Array;switch(e){case tt.RSA:return zo(o,t);case tt.Ed25519:return yo(o);case tt.secp256k1:return Jo(o);case tt.ECDSA:return Wn(o);default:throw new ue}}function ia(r){let{Type:t,Data:e}=Mt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return yo(n);case tt.secp256k1:return Jo(n);case tt.ECDSA:return Wn(n);default:throw new ue}}function Vt(r){return Mt.encode({Type:tt[r.type],Data:r.raw})}var aa=Symbol.for("nodejs.util.inspect.custom"),ff=114,lr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[wn]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ft.createV1(ff,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return wt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return wt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[aa](){return`PeerId(${this.toString()})`}},hr=class extends lr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},dr=class extends lr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},pr=class extends lr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},lf=2336,Jr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Pt.digest(Z(this.url))}[aa](){return`PeerId(${this.url})`}[wn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ft.createV1(lf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=G(t)),t.toString()===this.toString())}};function ts(r){if(r.type==="Ed25519")return new dr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new pr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new hr({multihash:r.toCID().multihash,publicKey:r});throw new ue}function ca(r){return ts(r.publicKey)}function mr(r){if(df(r))return new hr({multihash:r});if(hf(r))try{let t=ia(r);if(t.type==="Ed25519")return new dr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new pr({multihash:r,publicKey:t})}catch{let e=G(r.digest);return new Jr(new URL(e))}throw new _r("Supplied PeerID Multihash is invalid")}function hf(r){return r.code===Pt.code}function df(r){return r.code===le.code}function Se(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function Qr(r){let t=Qt(j.decode(`z${r}`));return mr(t)}var yr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return Se(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return Se(this.map.values(),t=>t.key)}values(){return Se(this.map.values(),t=>t.value)}get size(){return this.map.size}};var br=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Se(this.set.entries(),t=>{let e=Qr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Qr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Se(this.set.values(),t=>Qr(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function Xt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var tn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},ze=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new tn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new tn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var es=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function en(r={}){return pf(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function pf(r,t){t=t??{};let e=t.onEnd,n=new ze,o,s,i,a=Xt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((A,D)=>{s=O=>{s=null,n.push(O);try{A(r(n))}catch(x){D(x)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Xt()})}},f=A=>s!=null?s(A):(n.push(A),o),u=A=>(n=new ze,s!=null?s({error:A}):(n.push({error:A}),o)),l=A=>{if(i)return o;if(t?.objectMode!==!0&&A?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:A})},b=A=>i?o:(i=!0,A!=null?u(A):f({done:!0})),v=()=>(n=new ze,b(),{done:!0}),I=A=>(b(A),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:v,throw:I,push:l,end:b,get readableLength(){return n.size},onEmpty:async A=>{let D=A?.signal;if(D?.throwIfAborted(),n.isEmpty())return;let O,x;D!=null&&(O=new Promise((h,y)=>{x=()=>{y(new es)},D.addEventListener("abort",x)}));try{await Promise.race([a.promise,O])}finally{x!=null&&D!=null&&D?.removeEventListener("abort",x)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(A){return m.throw(A),e!=null&&(e(A),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(A){return m.end(A),e!=null&&(e(A),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:A=>m.onEmpty(A)},o}var rn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function ua(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new rn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new rn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var rs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Xt(),this.haveNext=Xt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Xt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Xt(),await ua(this.readNext.promise,e?.signal,e)}};function fa(){return new rs}function mf(r){return r[Symbol.asyncIterator]!=null}async function yf(r,t,e){try{await Promise.all(r.map(async n=>{for await(let o of n)await t.push(o,{signal:e}),e.throwIfAborted()})),await t.end(void 0,{signal:e})}catch(n){await t.end(n,{signal:e}).catch(()=>{})}}async function*bf(r){let t=new AbortController,e=fa();yf(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*gf(r){for(let t of r)yield*t}function xf(...r){let t=[];for(let e of r)mf(e)||t.push(e);return t.length===r.length?gf(t):bf(r)}var la=xf;function gr(r,...t){if(r==null)throw new Error("Empty pipeline");if(ns(r)){let n=r;r=()=>n.source}else if(da(r)||ha(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&ns(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)ns(e[n])&&(e[n]=Ef(e[n]));return wf(...e)}var wf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},ha=r=>r?.[Symbol.asyncIterator]!=null,da=r=>r?.[Symbol.iterator]!=null,ns=r=>r==null?!1:r.sink!=null&&r.source!=null,Ef=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=en({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(ha(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 r.source};var ss=qa(ma(),1);var wr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},is=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},ya=r=>globalThis.DOMException===void 0?new is(r):new DOMException(r),ba=r=>{let t=r.reason===void 0?ya("This operation was aborted."):r.reason;return t instanceof Error?t:ya(t)};function as(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,f=new Promise((u,l)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:v}=t;v.aborted&&l(ba(v)),a=()=>{l(ba(v))},v.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,l);return}let b=new wr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(v){l(v)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?l(o):(b.message=o??`Promise timed out after ${e} milliseconds`,l(b))},e),(async()=>{try{u(await r)}catch(v){l(v)}})()}).finally(()=>{f.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}function cs(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var Er=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let o=cs(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var Sr=class extends ss.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#x=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Er,...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#w(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},e)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#w&&this.#E){let e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#I(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#x++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=as(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#I(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof wr&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function ga(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function xa(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function wa(r,t){let e=ga(r).return?.();xa(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var on=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Fe=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},sn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},vr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function an(r){return r[Symbol.asyncIterator]!=null}function Ea(r,t){if(r.byteLength>t)throw new Fe("Message length too long")}var un=r=>{let t=Nt(r),e=lt(t);return Di(r,e),un.bytes=t,e};un.bytes=0;function fn(r,t){t=t??{};let e=t.lengthEncoder??un,n=t?.maxDataLength??4194304;function*o(s){Ea(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return an(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}fn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??un,n=t?.maxDataLength??4194304;return Ea(r,n),new nt(e(r.byteLength),r)};var ve;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ve||(ve={}));var us=r=>{let t=Pi(r);return us.bytes=Nt(t),t};us.bytes=0;function Ar(r,t){let e=new nt,n=ve.LENGTH,o=-1,s=t?.lengthDecoder??us,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===ve.LENGTH)try{if(o=s(e),o<0)throw new on("Invalid message length");if(o>a)throw new Fe("Message length too long");let f=s.bytes;e.consume(f),t?.onLength!=null&&t.onLength(o),n=ve.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>i)throw new sn("Message length length too long");break}throw f}if(n===ve.DATA){if(e.byteLength<o)break;let f=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(f),yield f,n=ve.LENGTH}}}return an(r)?async function*(){for await(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new vr("Unexpected end of input")}():function*(){for(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new vr("Unexpected end of input")}()}Ar.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return Ar(n,{...t??{},onLength:s=>{e=s}})};var ln=class extends Be{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=e.id,this.protocol=e.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let e=this.id.toString();throw new Error("No writable connection to "+e)}this.outboundStream.push(t instanceof Uint8Array?new nt(t):t)}attachInboundStream(t,e){let n=()=>{wa(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=gr(this._rawInboundStream,o=>Ar(o,e)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let e=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=en({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"))}}),gr(this.outboundStream,n=>fn(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),e==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function Sa(){return BigInt(`0x${G(Yr(8),"base16")}`)}var va=(r,t)=>{let e=Z(t.toString(16).padStart(16,"0"),"base16"),n=Vt(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},Aa=r=>le.encode(r);var Ia=function(r){return Array.isArray(r)?r:[r]},Bf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=mr(Qt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return ts(Qo(e)).equals(t)}return!1},Ba=async r=>{if(r.from==null)throw new Q("RPC message was missing from");if(!await Bf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=mr(Qt(r.from)),e=r.key??t.publicKey;if(e==null)throw new Q("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:Lf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?Qo(e):e}},Ir=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:_f(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Vt(r.key):void 0}:{data:r.data,topic:r.topic},_f=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),Z(t,"base16")},Lf=r=>BigInt(`0x${G(r,"base16")}`);var _a=Z("libp2p-pubsub:");async function La(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:ca(r)},o=fe([_a,e(Ir(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function Ta(r,t){if(r.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(r.signature==null)throw new Error("Message must contain a signature to be verified");if(r.from==null)throw new Error("Message must contain a from property to be verified");let e=fe([_a,t({...Ir(r),signature:void 0,key:void 0}).subarray()]);return Tf(r).verify(e,r.signature)}function Tf(r){if(r.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(r.from==null)throw new Error("Could not get the public key from the originator id");if(r.key!=null)return r.key;if(r.from.publicKey!=null)return r.from.publicKey;throw new Error("Could not get the public key from the originator id")}var hn=class extends Be{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,e){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:a=10,maxInboundStreams:c=1,maxOutboundStreams:f=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=Ia(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new yr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new Sr({concurrency:a}),this.maxInboundStreams=c,this.maxOutboundStreams=f,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let e={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.multicodecs.map(async e=>{await t.unhandle(e)})),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:e,connection:n}=t,o=n.remotePeer;if(e.protocol==null){e.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,e.protocol),i=s.attachInboundStream(e);this.processMessages(o,i,s).catch(a=>{this.log(a)})}_onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await e.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new ln(this.components,{id:t,protocol:e});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return e}}async processMessages(t,e,n){try{await gr(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),a=[];for(let c of i.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,e,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.id,subscriptions:o.map(({topic:i,subscribe:a})=>({topic:`${i??""}`,subscribe:!!a}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let a=await Ba(i);await this.processMessage(t,a)}catch(a){this.log.error(a)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new br,this.topics.set(n,o)),e.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,e){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,e)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new 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 va(t.key,t.sequenceNumber);case"StrictNoSign":return Aa(t.data);default:throw new Q("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,e){let{messages:n,subscriptions:o,subscribe:s}=e;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(Ir)})}sendRpc(t,e){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(e))}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new Q('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new Q("StrictNoSigning: signature should not be present");if(e.key!=null)throw new Q("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new Q("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new Q("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new Q("StrictSigning: Signing required and no sequenceNumber was present");if(!await Ta(e,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(e.topic);if(o!=null){let s=await o(t,e);if(s===Ze.Reject||s===Ze.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return La(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 Lr("not started yet");if(t==null)throw new $("Topic is required");let e=this.topics.get(t.toString());return e==null?[]:Array.from(e.values())}async publish(t,e){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:e??new Uint8Array(0),sequenceNumber:Sa()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let e=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,e),e){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};var dn=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,e){this.entries.set(t,{value:e,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[e,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(e);else break}}has(t){return this.entries.has(t)}get(t){let e=this.entries.get(t);return e!=null&&e.validUntilMs>=Date.now()?e.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var fs="/floodsub/1.0.0";var Ae;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=At((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 f={},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{f.subscribe=i.bool();break}case 2:{f.topic=i.string();break}default:{i.skipType(l&7);break}}}return f})),s),o.encode=i=>vt(i,o.codec()),o.decode=(i,a)=>St(i,o.codec(),a)})(t=r.SubOpts||(r.SubOpts={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=At((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 f={},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{f.from=i.bytes();break}case 2:{f.data=i.bytes();break}case 3:{f.sequenceNumber=i.bytes();break}case 4:{f.topic=i.string();break}case 5:{f.signature=i.bytes();break}case 6:{f.key=i.bytes();break}default:{i.skipType(l&7);break}}}return f})),s),o.encode=i=>vt(i,o.codec()),o.decode=(i,a)=>St(i,o.codec(),a)})(e=r.Message||(r.Message={}));let n;r.codec=()=>(n==null&&(n=At((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.subscriptions!=null)for(let a of o.subscriptions)s.uint32(10),r.SubOpts.codec().encode(a,s);if(o.messages!=null)for(let a of o.messages)s.uint32(18),r.Message.codec().encode(a,s);o.control!=null&&(s.uint32(26),pn.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 f=o.uint32();switch(f>>>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(r.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(r.Message.codec().decode(o,o.uint32(),{limits:i.limits?.messages$}));break}case 3:{a.control=pn.codec().decode(o,o.uint32(),{limits:i.limits?.control});break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>vt(o,r.codec()),r.decode=(o,s)=>St(o,r.codec(),s)})(Ae||(Ae={}));var pn;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.ihave!=null)for(let s of e.ihave)n.uint32(10),mn.codec().encode(s,n);if(e.iwant!=null)for(let s of e.iwant)n.uint32(18),yn.codec().encode(s,n);if(e.graft!=null)for(let s of e.graft)n.uint32(26),bn.codec().encode(s,n);if(e.prune!=null)for(let s of e.prune)n.uint32(34),gn.codec().encode(s,n);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={ihave:[],iwant:[],graft:[],prune:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.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(mn.codec().decode(e,e.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(yn.codec().decode(e,e.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(bn.codec().decode(e,e.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(gn.codec().decode(e,e.uint32(),{limits:o.limits?.prune$}));break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(pn||(pn={}));var mn;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.messageIDs!=null)for(let s of e.messageIDs)n.uint32(18),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={messageIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.topic=e.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(e.bytes());break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(mn||(mn={}));var yn;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.messageIDs!=null)for(let s of e.messageIDs)n.uint32(10),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={messageIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.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(e.bytes());break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(yn||(yn={}));var bn;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.topic=e.string();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(bn||(bn={}));var gn;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.peers!=null)for(let s of e.peers)n.uint32(18),xn.codec().encode(s,n);e.backoff!=null&&(n.uint32(24),n.uint64(e.backoff)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={peers:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.topic=e.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(xn.codec().decode(e,e.uint32(),{limits:o.limits?.peers$}));break}case 3:{s.backoff=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(gn||(gn={}));var xn;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.peerID!=null&&(n.uint32(10),n.bytes(e.peerID)),e.signedPeerRecord!=null&&(n.uint32(18),n.bytes(e.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.peerID=e.bytes();break}case 2:{s.signedPeerRecord=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(xn||(xn={}));var ls=class extends hn{seenCache;constructor(t,e){super(t,{...e,canRelayMessage:!0,multicodecs:[fs]}),this.log=t.logger.forComponent("libp2p:floodsub"),this.seenCache=new dn({validityMs:e?.seenTTL??3e4})}[ps]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[ms]=["@libp2p/pubsub"];[ys]=["@libp2p/identify"];decodeRpc(t){return Ae.decode(t)}encodeRpc(t){return Ae.encode(t)}decodeMessage(t){return Ae.Message.decode(t)}encodeMessage(t){return Ae.Message.encode(t)}async processMessage(t,e){let n=await super.getMsgId(e),o=G(n,"base64");this.seenCache.has(o)||(this.seenCache.put(o,!0),await super.processMessage(t,e))}async publishMessage(t,e){let n=this.getSubscribers(e.topic),o=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",e.topic),{recipients:o}):(n.forEach(s=>{if(this.components.peerId.equals(s)){this.log("not sending message on topic %s to myself",e.topic);return}if(s.equals(t)){this.log("not sending message on topic %s to sender %p",e.topic,s);return}this.log("publish msgs on topics %s %p",e.topic,s),o.push(s),this.send(s,{messages:[e]})}),{recipients:o})}};function Df(r={}){return t=>new ls(t,r)}return Ha(Pf);})();
|
|
2
|
+
"use strict";var Libp2PFloodsub=(()=>{var Ra=Object.create;var Br=Object.defineProperty;var ka=Object.getOwnPropertyDescriptor;var Ua=Object.getOwnPropertyNames;var Ka=Object.getPrototypeOf,Ma=Object.prototype.hasOwnProperty;var Oa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),xt=(r,t)=>{for(var e in t)Br(r,e,{get:t[e],enumerable:!0})},ds=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ua(t))!Ma.call(r,o)&&o!==e&&Br(r,o,{get:()=>t[o],enumerable:!(n=ka(t,o))||n.enumerable});return r};var qa=(r,t,e)=>(e=r!=null?Ra(Ka(r)):{},ds(t||!r||!r.__esModule?Br(e,"default",{value:r,enumerable:!0}):e,r)),Ha=r=>ds(Br({},"__esModule",{value:!0}),r);var ma=Oa((Am,os)=>{"use strict";var vf=Object.prototype.hasOwnProperty,bt="~";function xr(){}Object.create&&(xr.prototype=Object.create(null),new xr().__proto__||(bt=!1));function Af(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function pa(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new Af(e,n||r,o),i=bt?bt+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function nn(r,t){--r._eventsCount===0?r._events=new xr:delete r._events[t]}function pt(){this._events=new xr,this._eventsCount=0}pt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)vf.call(e,n)&&t.push(bt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};pt.prototype.listeners=function(t){var e=bt?bt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};pt.prototype.listenerCount=function(t){var e=bt?bt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};pt.prototype.emit=function(t,e,n,o,s,i){var a=bt?bt+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,s),!0;case 6:return c.fn.call(c.context,e,n,o,s,i),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var b=c.length,v;for(l=0;l<b;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,e);break;case 3:c[l].fn.call(c[l].context,e,n);break;case 4:c[l].fn.call(c[l].context,e,n,o);break;default:if(!u)for(v=1,u=new Array(f-1);v<f;v++)u[v-1]=arguments[v];c[l].fn.apply(c[l].context,u)}}return!0};pt.prototype.on=function(t,e,n){return pa(this,t,e,n,!1)};pt.prototype.once=function(t,e,n){return pa(this,t,e,n,!0)};pt.prototype.removeListener=function(t,e,n,o){var s=bt?bt+t:t;if(!this._events[s])return this;if(!e)return nn(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&nn(this,s);else{for(var a=0,c=[],f=i.length;a<f;a++)(i[a].fn!==e||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:nn(this,s)}return this};pt.prototype.removeAllListeners=function(t){var e;return t?(e=bt?bt+t:t,this._events[e]&&nn(this,e)):(this._events=new xr,this._eventsCount=0),this};pt.prototype.off=pt.prototype.removeListener;pt.prototype.addListener=pt.prototype.on;pt.prefixed=bt;pt.EventEmitter=pt;typeof os<"u"&&(os.exports=pt)});var Cf={};xt(Cf,{floodsub:()=>Pf,multicodec:()=>fs});var wn=Symbol.for("@libp2p/peer-id");var Ze;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ze||(Ze={}));var ps=Symbol.for("@libp2p/pubsub");var $=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ie=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var _r=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 Lr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ue=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Be=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var ms=Symbol.for("@libp2p/service-capabilities"),ys=Symbol.for("@libp2p/service-dependencies");var In={};xt(In,{base58btc:()=>j,base58flickr:()=>Wa});var il=new Uint8Array(0);function bs(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ot(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function gs(r){return new TextEncoder().encode(r)}function xs(r){return new TextDecoder().decode(r)}function Va(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(I){if(I instanceof Uint8Array||(ArrayBuffer.isView(I)?I=new Uint8Array(I.buffer,I.byteOffset,I.byteLength):Array.isArray(I)&&(I=Uint8Array.from(I))),!(I instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(I.length===0)return"";for(var m=0,A=0,D=0,O=I.length;D!==O&&I[D]===0;)D++,m++;for(var x=(O-D)*u+1>>>0,h=new Uint8Array(x);D!==O;){for(var y=I[D],B=0,_=x-1;(y!==0||B<A)&&_!==-1;_--,B++)y+=256*h[_]>>>0,h[_]=y%a>>>0,y=y/a>>>0;if(y!==0)throw new Error("Non-zero carry");A=B,D++}for(var L=x-A;L!==x&&h[L]===0;)L++;for(var R=c.repeat(m);L<x;++L)R+=r.charAt(h[L]);return R}function b(I){if(typeof I!="string")throw new TypeError("Expected String");if(I.length===0)return new Uint8Array;var m=0;if(I[m]!==" "){for(var A=0,D=0;I[m]===c;)A++,m++;for(var O=(I.length-m)*f+1>>>0,x=new Uint8Array(O);I[m];){var h=e[I.charCodeAt(m)];if(h===255)return;for(var y=0,B=O-1;(h!==0||y<D)&&B!==-1;B--,y++)h+=a*x[B]>>>0,x[B]=h%256>>>0,h=h/256>>>0;if(h!==0)throw new Error("Non-zero carry");D=y,m++}if(I[m]!==" "){for(var _=O-D;_!==O&&x[_]===0;)_++;for(var L=new Uint8Array(A+(O-_)),R=A;_!==O;)L[R++]=x[_++];return L}}}function v(I){var m=b(I);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:b,decode:v}}var za=Va,Fa=za,Es=Fa;var En=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Sn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ss(this,t)}},vn=class{decoders;constructor(t){this.decoders=t}or(t){return Ss(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ss(r,t){return new vn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var An=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new En(t,e,n),this.decoder=new Sn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function _e({name:r,prefix:t,encode:e,decode:n}){return new An(r,t,e,n)}function Jt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Es(e,r);return _e({prefix:t,name:r,encode:n,decode:s=>Ot(o(s))})}function Ga(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Za(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Ya(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function X({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Ya(n);return _e({prefix:t,name:r,encode(s){return Za(s,n,e)},decode(s){return Ga(s,o,e,r)}})}var j=Jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Wa=Jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Bn={};xt(Bn,{base32:()=>Le,base32hex:()=>Ja,base32hexpad:()=>tc,base32hexpadupper:()=>ec,base32hexupper:()=>Qa,base32pad:()=>ja,base32padupper:()=>Xa,base32upper:()=>$a,base32z:()=>rc});var Le=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$a=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ja=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Xa=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ja=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qa=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),tc=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ec=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rc=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _n={};xt(_n,{base36:()=>Ye,base36upper:()=>nc});var Ye=Jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),nc=Jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var oc=Is,vs=128,sc=127,ic=~sc,ac=Math.pow(2,31);function Is(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ac;)t[e++]=r&255|vs,r/=128;for(;r⁣)t[e++]=r&255|vs,r>>>=7;return t[e]=r|0,Is.bytes=e-n+1,t}var cc=Ln,uc=128,As=127;function Ln(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ln.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&As)<<o:(i&As)*Math.pow(2,o),o+=7}while(i>=uc);return Ln.bytes=s-n,e}var fc=Math.pow(2,7),lc=Math.pow(2,14),hc=Math.pow(2,21),dc=Math.pow(2,28),pc=Math.pow(2,35),mc=Math.pow(2,42),yc=Math.pow(2,49),bc=Math.pow(2,56),gc=Math.pow(2,63),xc=function(r){return r<fc?1:r<lc?2:r<hc?3:r<dc?4:r<pc?5:r<mc?6:r<yc?7:r<bc?8:r<gc?9:10},wc={encode:oc,decode:cc,encodingLength:xc},Ec=wc,We=Ec;function $e(r,t=0){return[We.decode(r,t),We.decode.bytes]}function Te(r,t,e=0){return We.encode(r,t,e),t}function De(r){return We.encodingLength(r)}function Dt(r,t){let e=t.byteLength,n=De(r),o=n+De(e),s=new Uint8Array(o+e);return Te(r,s,0),Te(e,s,n),s.set(t,o),new Pe(r,e,t,s)}function Qt(r){let t=Ot(r),[e,n]=$e(t),[o,s]=$e(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Pe(e,o,i,t)}function Bs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&bs(r.bytes,e.bytes)}}var Pe=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function _s(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return vc(e,Tn(r),t??j.encoder);default:return Ac(e,Tn(r),t??Le.encoder)}}var Ls=new WeakMap;function Tn(r){let t=Ls.get(r);if(t==null){let e=new Map;return Ls.set(r,e),e}return t}var ft=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==je)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ic)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Dt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Bs(t.multihash,n.multihash)}toString(t){return _s(this,t)}toJSON(){return{"/":_s(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Ts(n,o,s.bytes))}else if(e[Bc]===!0){let{version:n,multihash:o,code:s}=e,i=Qt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==je)throw new Error(`Version 0 CID must use dag-pb (code: ${je}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ts(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,je,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Ot(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Pe(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,b]=$e(t.subarray(e));return e+=b,l},o=n(),s=je;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,e){let[n,o]=Sc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Tn(s).set(n,t),s}};function Sc(r,t){switch(r[0]){case"Q":{let e=t??j;return[j.prefix,e.decode(`${j.prefix}${r}`)]}case j.prefix:{let e=t??j;return[j.prefix,e.decode(r)]}case Le.prefix:{let e=t??Le;return[Le.prefix,e.decode(r)]}case Ye.prefix:{let e=t??Ye;return[Ye.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function vc(r,t,e){let{prefix:n}=e;if(n!==j.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Ac(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var je=112,Ic=18;function Ts(r,t,e){let n=De(r),o=n+De(t),s=new Uint8Array(o+e.byteLength);return Te(r,s,0),Te(t,s,n),s.set(e,o),s}var Bc=Symbol.for("@ipld/js-cid/CID");var Dn={};xt(Dn,{identity:()=>Pt});var Ds=0,_c="identity",Ps=Ot;function Lc(r){return Dt(Ds,Ps(r))}var Pt={code:Ds,name:_c,encode:Ps,digest:Lc};function wt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function qt(r=0){return new Uint8Array(r)}function lt(r=0){return new Uint8Array(r)}function fe(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=lt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Ns=Symbol.for("@achingbrain/uint8arraylist");function Cs(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Dr(r){return!!r?.[Ns]}var nt=class r{bufs;length;[Ns]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Dr(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Dr(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Cs(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Cs(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Dr(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return fe(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:fe(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=e>a&&e<=c;if(f&&u){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Dr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=e;l<=c;l+=u){u=0;for(let b=f;b>=0;b--){let v=this.get(l+b);if(n[b]!==v){u=Math.max(1,b-a[v]);break}}if(u===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=qt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=qt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=qt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=qt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=qt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=qt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=qt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=qt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!wt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Pn={};xt(Pn,{base10:()=>Tc});var Tc=Jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Cn={};xt(Cn,{base16:()=>Dc,base16upper:()=>Pc});var Dc=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Pc=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Nn={};xt(Nn,{base2:()=>Cc});var Cc=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Rn={};xt(Rn,{base256emoji:()=>Kc});var Rs=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}"),Nc=Rs.reduce((r,t,e)=>(r[e]=t,r),[]),Rc=Rs.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function kc(r){return r.reduce((t,e)=>(t+=Nc[e],t),"")}function Uc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Rc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Kc=_e({prefix:"\u{1F680}",name:"base256emoji",encode:kc,decode:Uc});var kn={};xt(kn,{base64:()=>Mc,base64pad:()=>Oc,base64url:()=>qc,base64urlpad:()=>Hc});var Mc=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Oc=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qc=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Hc=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Un={};xt(Un,{base8:()=>Vc});var Vc=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Kn={};xt(Kn,{identity:()=>zc});var zc=_e({prefix:"\0",name:"identity",encode:r=>xs(r),decode:r=>gs(r)});var zl=new TextEncoder,Fl=new TextDecoder;var qn={};xt(qn,{sha256:()=>le,sha512:()=>Zc});function On({name:r,code:t,encode:e}){return new Mn(r,t,e)}var Mn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Dt(this.code,e):e.then(n=>Dt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Us(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var le=On({name:"sha2-256",code:18,encode:Us("SHA-256")}),Zc=On({name:"sha2-512",code:19,encode:Us("SHA-512")});var Hn={...Kn,...Nn,...Un,...Pn,...Cn,...Bn,..._n,...In,...kn,...Rn},rh={...qn,...Dn};function Ms(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ks=Ms("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Vn=Ms("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=lt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Yc={utf8:Ks,"utf-8":Ks,hex:Hn.base16,latin1:Vn,ascii:Vn,binary:Vn,...Hn},Pr=Yc;function Z(r,t="utf8"){let e=Pr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function G(r,t="utf8"){let e=Pr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Wc=parseInt("11111",2),zn=parseInt("10000000",2),$c=parseInt("01111111",2),Os={0:Xe,1:Xe,2:jc,3:Qc,4:tu,5:Jc,6:Xc,16:Xe,22:Xe,48:Xe};function Ht(r,t={offset:0}){let e=r[t.offset]&Wc;if(t.offset++,Os[e]!=null)return Os[e](r,t);throw new Error("No decoder for tag "+e)}function Je(r,t){let e=0;if((r[t.offset]&zn)===zn){let n=r[t.offset]&$c,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Xe(r,t){Je(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Ht(r,t);if(n===null)break;e.push(n)}return e}function jc(r,t){let e=Je(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Xc(r,t){let e=Je(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function Jc(r,t){return t.offset++,null}function Qc(r,t){let e=Je(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function tu(r,t){let e=Je(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function eu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new nt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Fn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=eu(r.byteLength);return new nt(Uint8Array.from([t.byteLength|zn]),t)}function Et(r){let t=new nt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new nt(Uint8Array.from([2]),Fn(t),t)}function Cr(r){let t=Uint8Array.from([0]),e=new nt(t,r);return new nt(Uint8Array.from([3]),Fn(e),e)}function ee(r,t=48){let e=new nt;for(let n of r)e.append(n);return new nt(Uint8Array.from([t]),Fn(e),e)}async function qs(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var ru=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),nu=Uint8Array.from([6,5,43,129,4,0,34]),ou=Uint8Array.from([6,5,43,129,4,0,35]),su={ext:!0,kty:"EC",crv:"P-256"},iu={ext:!0,kty:"EC",crv:"P-384"},au={ext:!0,kty:"EC",crv:"P-521"},Gn=32,Zn=48,Yn=66;function Wn(r){let t=Ht(r);return Hs(t)}function Hs(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Gn*2+1)return n=G(t.subarray(e,e+Gn),"base64url"),o=G(t.subarray(e+Gn),"base64url"),new Ce({...su,key_ops:["verify"],x:n,y:o});if(t.byteLength===Zn*2+1)return n=G(t.subarray(e,e+Zn),"base64url"),o=G(t.subarray(e+Zn),"base64url"),new Ce({...iu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Yn*2+1)return n=G(t.subarray(e,e+Yn),"base64url"),o=G(t.subarray(e+Yn),"base64url"),new Ce({...au,key_ops:["verify"],x:n,y:o});throw new $(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Vs(r){return ee([Et(Uint8Array.from([1])),ee([cu(r.crv)],160),ee([Cr(new nt(Uint8Array.from([4]),Z(r.x??"","base64url"),Z(r.y??"","base64url")))],161)]).subarray()}function cu(r){if(r==="P-256")return ru;if(r==="P-384")return nu;if(r==="P-521")return ou;throw new $(`Invalid curve ${r}`)}var Ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Vs(this.jwk)),this._raw}toMultihash(){return Pt.digest(Vt(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}async verify(t,e){return qs(this.jwk,e,t)}};var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function uu(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Nr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function de(r,...t){if(!uu(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function zs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Nr(r.outputLen),Nr(r.blockLen)}function Re(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Fs(r,t){de(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function zt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Rr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Ct(r,t){return r<<32-t|r>>>t}function Gs(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Qe(r){return typeof r=="string"&&(r=Gs(r)),de(r),r}function $n(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];de(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Ne=class{};function jn(r){let t=n=>r().update(Qe(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function ke(r=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(r));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function fu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,f=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+f,a,n)}function Zs(r,t,e){return r&t^~r&e}function Ys(r,t,e){return r&t^r&e^t&e}var tr=class extends Ne{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Rr(this.buffer)}update(t){Re(this),t=Qe(t),de(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Rr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),Fs(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,zt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;fu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Rr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ft=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var kr=BigInt(4294967295),Ws=BigInt(32);function lu(r,t=!1){return t?{h:Number(r&kr),l:Number(r>>Ws&kr)}:{h:Number(r>>Ws&kr)|0,l:Number(r&kr)|0}}function $s(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=lu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Xn=(r,t,e)=>r>>>e,Jn=(r,t,e)=>r<<32-e|t>>>e,pe=(r,t,e)=>r>>>e|t<<32-e,me=(r,t,e)=>r<<32-e|t>>>e,er=(r,t,e)=>r<<64-e|t>>>e-32,rr=(r,t,e)=>r>>>e-32|t<<64-e;function kt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var js=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Xs=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Js=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Qs=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,ti=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ei=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var du=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]),re=new Uint32Array(64),Ur=class extends tr{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:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)re[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let b=re[l-15],v=re[l-2],I=Ct(b,7)^Ct(b,18)^b>>>3,m=Ct(v,17)^Ct(v,19)^v>>>10;re[l]=m+re[l-7]+I+re[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let b=Ct(a,6)^Ct(a,11)^Ct(a,25),v=u+b+Zs(a,c,f)+du[l]+re[l]|0,m=(Ct(n,2)^Ct(n,13)^Ct(n,22))+Ys(n,o,s)|0;u=f,f=c,c=a,a=i+v|0,i=s,s=o,o=n,n=v+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){zt(re)}destroy(){this.set(0,0,0,0,0,0,0,0),zt(this.buffer)}};var ri=$s(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),pu=ri[0],mu=ri[1],ne=new Uint32Array(80),oe=new Uint32Array(80),Qn=class extends tr{constructor(t=64){super(128,t,16,!1),this.Ah=ct[0]|0,this.Al=ct[1]|0,this.Bh=ct[2]|0,this.Bl=ct[3]|0,this.Ch=ct[4]|0,this.Cl=ct[5]|0,this.Dh=ct[6]|0,this.Dl=ct[7]|0,this.Eh=ct[8]|0,this.El=ct[9]|0,this.Fh=ct[10]|0,this.Fl=ct[11]|0,this.Gh=ct[12]|0,this.Gl=ct[13]|0,this.Hh=ct[14]|0,this.Hl=ct[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:b,Gh:v,Gl:I,Hh:m,Hl:A}=this;return[t,e,n,o,s,i,a,c,f,u,l,b,v,I,m,A]}set(t,e,n,o,s,i,a,c,f,u,l,b,v,I,m,A){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=b|0,this.Gh=v|0,this.Gl=I|0,this.Hh=m|0,this.Hl=A|0}process(t,e){for(let x=0;x<16;x++,e+=4)ne[x]=t.getUint32(e),oe[x]=t.getUint32(e+=4);for(let x=16;x<80;x++){let h=ne[x-15]|0,y=oe[x-15]|0,B=pe(h,y,1)^pe(h,y,8)^Xn(h,y,7),_=me(h,y,1)^me(h,y,8)^Jn(h,y,7),L=ne[x-2]|0,R=oe[x-2]|0,K=pe(L,R,19)^er(L,R,61)^Xn(L,R,6),P=me(L,R,19)^rr(L,R,61)^Jn(L,R,6),k=Js(_,P,oe[x-7],oe[x-16]),N=Qs(k,B,K,ne[x-7],ne[x-16]);ne[x]=N|0,oe[x]=k|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:b,Fh:v,Fl:I,Gh:m,Gl:A,Hh:D,Hl:O}=this;for(let x=0;x<80;x++){let h=pe(l,b,14)^pe(l,b,18)^er(l,b,41),y=me(l,b,14)^me(l,b,18)^rr(l,b,41),B=l&v^~l&m,_=b&I^~b&A,L=ti(O,y,_,mu[x],oe[x]),R=ei(L,D,h,B,pu[x],ne[x]),K=L|0,P=pe(n,o,28)^er(n,o,34)^er(n,o,39),k=me(n,o,28)^rr(n,o,34)^rr(n,o,39),N=n&s^n&a^s&a,et=o&i^o&c^i&c;D=m|0,O=A|0,m=v|0,A=I|0,v=l|0,I=b|0,{h:l,l:b}=kt(f|0,u|0,R|0,K|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let E=js(K,k,et);n=Xs(E,R,P,N),o=E|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:f,l:u}=kt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:b}=kt(this.Eh|0,this.El|0,l|0,b|0),{h:v,l:I}=kt(this.Fh|0,this.Fl|0,v|0,I|0),{h:m,l:A}=kt(this.Gh|0,this.Gl|0,m|0,A|0),{h:D,l:O}=kt(this.Hh|0,this.Hl|0,D|0,O|0),this.set(n,o,s,i,a,c,f,u,l,b,v,I,m,A,D,O)}roundClean(){zt(ne,oe)}destroy(){zt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Kr=jn(()=>new Ur);var ni=jn(()=>new Qn);var no=BigInt(0),ro=BigInt(1);function Ue(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function oo(r){if(!Ue(r))throw new Error("Uint8Array expected")}function Ut(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function nr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function ii(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?no:BigInt("0x"+r)}var ai=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",yu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function se(r){if(oo(r),ai)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=yu[r[e]];return t}var Gt={_0:48,_9:57,A:65,F:70,a:97,f:102};function oi(r){if(r>=Gt._0&&r<=Gt._9)return r-Gt._0;if(r>=Gt.A&&r<=Gt.F)return r-(Gt.A-10);if(r>=Gt.a&&r<=Gt.f)return r-(Gt.a-10)}function or(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(ai)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=oi(r.charCodeAt(s)),a=oi(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Zt(r){return ii(se(r))}function ye(r){return oo(r),ii(se(Uint8Array.from(r).reverse()))}function be(r,t){return or(r.toString(16).padStart(t*2,"0"))}function Ke(r,t){return be(r,t).reverse()}function Y(r,t,e){let n;if(typeof t=="string")try{n=or(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Ue(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function ie(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];oo(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var to=r=>typeof r=="bigint"&&no<=r;function Mr(r,t,e){return to(r)&&to(t)&&to(e)&&t<=r&&r<e}function Bt(r,t,e,n){if(!Mr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ci(r){let t;for(t=0;r>no;r>>=ro,t+=1);return t}var ge=r=>(ro<<BigInt(r))-ro,eo=r=>new Uint8Array(r),si=r=>Uint8Array.from(r);function ui(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=eo(r),o=eo(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...l)=>e(o,n,...l),c=(l=eo(0))=>{o=a(si([0]),l),n=a(),l.length!==0&&(o=a(si([1]),l),n=a())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,b=[];for(;l<t;){n=a();let v=n.slice();b.push(v),l+=n.length}return ie(...b)};return(l,b)=>{i(),c(l);let v;for(;!(v=b(f()));)c();return i(),v}}var bu={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Ue(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Yt(r,t,e={}){let n=(o,s,i)=>{let a=bu[s];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}function Me(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var mt=BigInt(0),st=BigInt(1),xe=BigInt(2),gu=BigInt(3),li=BigInt(4),hi=BigInt(5),di=BigInt(8);function F(r,t){let e=r%t;return e>=mt?e:t+e}function W(r,t,e){let n=r;for(;t-- >mt;)n*=n,n%=e;return n}function Or(r,t){if(r===mt)throw new Error("invert: expected non-zero number");if(t<=mt)throw new Error("invert: expected positive modulus, got "+t);let e=F(r,t),n=t,o=mt,s=st,i=st,a=mt;for(;e!==mt;){let f=n/e,u=n%e,l=o-i*f,b=s-a*f;n=e,e=u,o=i,s=a,i=l,a=b}if(n!==st)throw new Error("invert: does not exist");return F(o,t)}function pi(r,t){let e=(r.ORDER+st)/li,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function xu(r,t){let e=(r.ORDER-hi)/di,n=r.mul(t,xe),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,xe),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function wu(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-st,e=0;for(;t%xe===mt;)t/=xe,e++;let n=xe,o=Wt(r);for(;fi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return pi;let s=o.pow(n,t),i=(t+st)/xe;return function(c,f){if(c.is0(f))return f;if(fi(c,f)!==1)throw new Error("Cannot find square root");let u=e,l=c.mul(c.ONE,s),b=c.pow(f,t),v=c.pow(f,i);for(;!c.eql(b,c.ONE);){if(c.is0(b))return c.ZERO;let I=1,m=c.sqr(b);for(;!c.eql(m,c.ONE);)if(I++,m=c.sqr(m),I===u)throw new Error("Cannot find square root");let A=st<<BigInt(u-I-1),D=c.pow(l,A);u=I,l=c.sqr(D),b=c.mul(b,l),v=c.mul(v,D)}return v}}function Eu(r){return r%li===gu?pi:r%di===hi?xu:wu(r)}var mi=(r,t)=>(F(r,t)&st)===st,Su=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function so(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Su.reduce((n,o)=>(n[o]="function",n),t);return Yt(r,e)}function vu(r,t,e){if(e<mt)throw new Error("invalid exponent, negatives unsupported");if(e===mt)return r.ONE;if(e===st)return t;let n=r.ONE,o=t;for(;e>mt;)e&st&&(n=r.mul(n,o)),o=r.sqr(o),e>>=st;return n}function Oe(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function fi(r,t){let e=(r.ORDER-st)/xe,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function io(r,t){t!==void 0&&Nr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Wt(r,t,e=!1,n={}){if(r<=mt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=io(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:ge(o),ZERO:mt,ONE:st,create:c=>F(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return mt<=c&&c<r},is0:c=>c===mt,isOdd:c=>(c&st)===st,neg:c=>F(-c,r),eql:(c,f)=>c===f,sqr:c=>F(c*c,r),add:(c,f)=>F(c+f,r),sub:(c,f)=>F(c-f,r),mul:(c,f)=>F(c*f,r),pow:(c,f)=>vu(a,c,f),div:(c,f)=>F(c*Or(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Or(c,r),sqrt:n.sqrt||(c=>(i||(i=Eu(r)),i(a,c))),toBytes:c=>e?Ke(c,s):be(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?ye(c):Zt(c)},invertBatch:c=>Oe(a,c),cmov:(c,f,u)=>u?f:c});return Object.freeze(a)}function yi(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function ao(r){let t=yi(r);return t+Math.ceil(t/2)}function bi(r,t,e=!1){let n=r.length,o=yi(t),s=ao(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ye(r):Zt(r),a=F(i,t-st)+st;return e?Ke(a,o):be(a,o)}var gi=BigInt(0),ho=BigInt(1);function co(r,t){let e=t.negate();return r?e:t}function wi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function uo(r,t){wi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ge(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function xi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ho);let f=t*n,u=f+Math.abs(a)-1,l=a===0,b=a<0,v=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:b,isNegF:v,offsetF:f}}function Au(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Iu(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var fo=new WeakMap,Ei=new WeakMap;function lo(r){return Ei.get(r)||1}function qr(r,t){return{constTimeNegate:co,hasPrecomputes(e){return lo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>gi;)n&ho&&(o=o.add(s)),s=s.double(),n>>=ho;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=uo(n,t),i=[],a=e,c=a;for(let f=0;f<o;f++){c=a,i.push(c);for(let u=1;u<s;u++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=uo(e,t);for(let c=0;c<a.windows;c++){let{nextN:f,offset:u,isZero:l,isNeg:b,isNegF:v,offsetF:I}=xi(o,c,a);o=f,l?i=i.add(co(v,n[I])):s=s.add(co(b,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=uo(e,t);for(let a=0;a<i.windows&&o!==gi;a++){let{nextN:c,offset:f,isZero:u,isNeg:l}=xi(o,a,i);if(o=c,!u){let b=n[f];s=s.add(l?b.negate():b)}}return s},getPrecomputes(e,n,o){let s=fo.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&fo.set(n,o(s))),s},wNAFCached(e,n,o){let s=lo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=lo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){wi(n,t),Ei.set(e,n),fo.delete(e)}}}function Hr(r,t,e,n){Au(e,r),Iu(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=ci(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=ge(c),u=new Array(Number(f)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,b=i;for(let v=l;v>=0;v-=c){u.fill(i);for(let m=0;m<s;m++){let A=n[m],D=Number(A>>BigInt(v)&f);u[D]=u[D].add(e[m])}let I=i;for(let m=u.length-1,A=i;m>0;m--)A=A.add(u[m]),I=I.add(A);if(b=b.add(I),v!==0)for(let m=0;m<c;m++)b=b.double()}return b}function sr(r){return so(r.Fp),Yt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...io(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Kt=BigInt(0),yt=BigInt(1),Si=BigInt(2),Bu=BigInt(8),_u={zip215:!0};function Lu(r){let t=sr(r);return Yt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function vi(r){let t=Lu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,f=Si<<BigInt(a*8)-yt,u=e.create,l=Wt(t.n,t.nBitLength);function b(g,d){let p=e.sqr(g),S=e.sqr(d),C=e.add(e.mul(t.a,p),S),U=e.add(e.ONE,e.mul(t.d,e.mul(p,S)));return e.eql(C,U)}if(!b(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let v=t.uvRatio||((g,d)=>{try{return{isValid:!0,value:e.sqrt(g*e.inv(d))}}catch{return{isValid:!1,value:Kt}}}),I=t.adjustScalarBytes||(g=>g),m=t.domain||((g,d,p)=>{if(Ut("phflag",p),d.length||p)throw new Error("Contexts/pre-hash are not supported");return g});function A(g,d,p=!1){let S=p?yt:Kt;Bt("coordinate "+g,d,S,f)}function D(g){if(!(g instanceof h))throw new Error("ExtendedPoint expected")}let O=Me((g,d)=>{let{ex:p,ey:S,ez:C}=g,U=g.is0();d==null&&(d=U?Bu:e.inv(C));let M=u(p*d),q=u(S*d),H=u(C*d);if(U)return{x:Kt,y:yt};if(H!==yt)throw new Error("invZ was invalid");return{x:M,y:q}}),x=Me(g=>{let{a:d,d:p}=t;if(g.is0())throw new Error("bad point: ZERO");let{ex:S,ey:C,ez:U,et:M}=g,q=u(S*S),H=u(C*C),z=u(U*U),rt=u(z*z),J=u(q*d),at=u(z*u(J+H)),gt=u(rt+u(p*u(q*H)));if(at!==gt)throw new Error("bad point: equation left != right (1)");let ot=u(S*C),ut=u(U*M);if(ot!==ut)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(d,p,S,C){A("x",d),A("y",p),A("z",S,!0),A("t",C),this.ex=d,this.ey=p,this.ez=S,this.et=C,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof h)throw new Error("extended point not allowed");let{x:p,y:S}=d||{};return A("x",p),A("y",S),new h(p,S,yt,u(p*S))}static normalizeZ(d){let p=Oe(e,d.map(S=>S.ez));return d.map((S,C)=>S.toAffine(p[C])).map(h.fromAffine)}static msm(d,p){return Hr(h,l,d,p)}_setWindowSize(d){_.setWindowSize(this,d)}assertValidity(){x(this)}equals(d){D(d);let{ex:p,ey:S,ez:C}=this,{ex:U,ey:M,ez:q}=d,H=u(p*q),z=u(U*C),rt=u(S*q),J=u(M*C);return H===z&&rt===J}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:d}=t,{ex:p,ey:S,ez:C}=this,U=u(p*p),M=u(S*S),q=u(Si*u(C*C)),H=u(d*U),z=p+S,rt=u(u(z*z)-U-M),J=H+M,at=J-q,gt=H-M,ot=u(rt*at),ut=u(J*gt),It=u(rt*gt),Tt=u(at*J);return new h(ot,ut,Tt,It)}add(d){D(d);let{a:p,d:S}=t,{ex:C,ey:U,ez:M,et:q}=this,{ex:H,ey:z,ez:rt,et:J}=d,at=u(C*H),gt=u(U*z),ot=u(q*S*J),ut=u(M*rt),It=u((C+U)*(H+z)-at-gt),Tt=ut-ot,Ge=ut+ot,hs=u(gt-p*at),Da=u(It*Tt),Pa=u(Ge*hs),Ca=u(It*hs),Na=u(Tt*Ge);return new h(Da,Pa,Na,Ca)}subtract(d){return this.add(d.negate())}wNAF(d){return _.wNAFCached(this,d,h.normalizeZ)}multiply(d){let p=d;Bt("scalar",p,yt,n);let{p:S,f:C}=this.wNAF(p);return h.normalizeZ([S,C])[0]}multiplyUnsafe(d,p=h.ZERO){let S=d;return Bt("scalar",S,Kt,n),S===Kt?B:this.is0()||S===yt?this:_.wNAFCachedUnsafe(this,S,h.normalizeZ,p)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return _.unsafeLadder(this,n).is0()}toAffine(d){return O(this,d)}clearCofactor(){let{h:d}=t;return d===yt?this:this.multiplyUnsafe(d)}static fromHex(d,p=!1){let{d:S,a:C}=t,U=e.BYTES;d=Y("pointHex",d,U),Ut("zip215",p);let M=d.slice(),q=d[U-1];M[U-1]=q&-129;let H=ye(M),z=p?f:e.ORDER;Bt("pointHex.y",H,Kt,z);let rt=u(H*H),J=u(rt-yt),at=u(S*rt-C),{isValid:gt,value:ot}=v(J,at);if(!gt)throw new Error("Point.fromHex: invalid y coordinate");let ut=(ot&yt)===yt,It=(q&128)!==0;if(!p&&ot===Kt&&It)throw new Error("Point.fromHex: x=0 and x_0=1");return It!==ut&&(ot=u(-ot)),h.fromAffine({x:ot,y:H})}static fromPrivateKey(d){let{scalar:p}=K(d);return y.multiply(p)}toRawBytes(){let{x:d,y:p}=this.toAffine(),S=Ke(p,e.BYTES);return S[S.length-1]|=d&yt?128:0,S}toHex(){return se(this.toRawBytes())}}h.BASE=new h(t.Gx,t.Gy,yt,u(t.Gx*t.Gy)),h.ZERO=new h(Kt,yt,yt,Kt);let{BASE:y,ZERO:B}=h,_=qr(h,a*8);function L(g){return F(g,n)}function R(g){return L(ye(g))}function K(g){let d=e.BYTES;g=Y("private key",g,d);let p=Y("hashed private key",s(g),2*d),S=I(p.slice(0,d)),C=p.slice(d,2*d),U=R(S);return{head:S,prefix:C,scalar:U}}function P(g){let{head:d,prefix:p,scalar:S}=K(g),C=y.multiply(S),U=C.toRawBytes();return{head:d,prefix:p,scalar:S,point:C,pointBytes:U}}function k(g){return P(g).pointBytes}function N(g=Uint8Array.of(),...d){let p=ie(...d);return R(s(m(p,Y("context",g),!!o)))}function et(g,d,p={}){g=Y("message",g),o&&(g=o(g));let{prefix:S,scalar:C,pointBytes:U}=P(d),M=N(p.context,S,g),q=y.multiply(M).toRawBytes(),H=N(p.context,q,U,g),z=L(M+H*C);Bt("signature.s",z,Kt,n);let rt=ie(q,Ke(z,e.BYTES));return Y("result",rt,e.BYTES*2)}let E=_u;function w(g,d,p,S=E){let{context:C,zip215:U}=S,M=e.BYTES;g=Y("signature",g,2*M),d=Y("message",d),p=Y("publicKey",p,M),U!==void 0&&Ut("zip215",U),o&&(d=o(d));let q=ye(g.slice(M,2*M)),H,z,rt;try{H=h.fromHex(p,U),z=h.fromHex(g.slice(0,M),U),rt=y.multiplyUnsafe(q)}catch{return!1}if(!U&&H.isSmallOrder())return!1;let J=N(C,z.toRawBytes(),H.toRawBytes(),d);return z.add(H.multiplyUnsafe(J)).subtract(rt).clearCofactor().equals(h.ZERO)}return y._setWindowSize(8),{CURVE:t,getPublicKey:k,sign:et,verify:w,ExtendedPoint:h,utils:{getExtendedPublicKey:P,randomPrivateKey:()=>i(e.BYTES),precompute(g=8,d=h.BASE){return d._setWindowSize(g),d.multiply(BigInt(3)),d}}}}var po=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ai=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),sd=BigInt(0),Tu=BigInt(1),Ii=BigInt(2),id=BigInt(3),Du=BigInt(5),Pu=BigInt(8);function Cu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=po,a=r*r%s*r%s,c=W(a,Ii,s)*a%s,f=W(c,Tu,s)*r%s,u=W(f,Du,s)*f%s,l=W(u,t,s)*u%s,b=W(l,e,s)*l%s,v=W(b,n,s)*b%s,I=W(v,o,s)*v%s,m=W(I,o,s)*v%s,A=W(m,t,s)*u%s;return{pow_p_5_8:W(A,Ii,s)*r%s,b2:a}}function Nu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Ru(r,t){let e=po,n=F(t*t*t,e),o=F(n*n*t,e),s=Cu(r*o).pow_p_5_8,i=F(r*n*s,e),a=F(t*i*i,e),c=i,f=F(i*Ai,e),u=a===r,l=a===F(-r,e),b=a===F(-r*Ai,e);return u&&(i=c),(l||b)&&(i=f),mi(i,e)&&(i=F(-i,e)),{isValid:u||l,value:i}}var Bi=Wt(po,void 0,!0),ku={a:Bi.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Bi,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Pu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ni,randomBytes:ke,adjustScalarBytes:Nu,uvRatio:Ru},_i=vi(ku);var Vr=32;function Li(r,t,e){return _i.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var zr=class{type="Ed25519";raw;constructor(t){this.raw=mo(t,Vr)}toMultihash(){return Pt.digest(Vt(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return Li(this.raw,e,t)}};function yo(r){return r=mo(r,Vr),new zr(r)}function mo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new $(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Ku=Math.pow(2,7),Mu=Math.pow(2,14),Ou=Math.pow(2,21),bo=Math.pow(2,28),go=Math.pow(2,35),xo=Math.pow(2,42),wo=Math.pow(2,49),V=128,ht=127;function Nt(r){if(r<Ku)return 1;if(r<Mu)return 2;if(r<Ou)return 3;if(r<bo)return 4;if(r<go)return 5;if(r<xo)return 6;if(r<wo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Eo(r,t,e=0){switch(Nt(r)){case 8:t[e++]=r&255|V,r/=128;case 7:t[e++]=r&255|V,r/=128;case 6:t[e++]=r&255|V,r/=128;case 5:t[e++]=r&255|V,r/=128;case 4:t[e++]=r&255|V,r>>>=7;case 3:t[e++]=r&255|V,r>>>=7;case 2:t[e++]=r&255|V,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function qu(r,t,e=0){switch(Nt(r)){case 8:t.set(e++,r&255|V),r/=128;case 7:t.set(e++,r&255|V),r/=128;case 6:t.set(e++,r&255|V),r/=128;case 5:t.set(e++,r&255|V),r/=128;case 4:t.set(e++,r&255|V),r>>>=7;case 3:t.set(e++,r&255|V),r>>>=7;case 2:t.set(e++,r&255|V),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function So(r,t){let e=r[t],n=0;if(n+=e&ht,e<V||(e=r[t+1],n+=(e&ht)<<7,e<V)||(e=r[t+2],n+=(e&ht)<<14,e<V)||(e=r[t+3],n+=(e&ht)<<21,e<V)||(e=r[t+4],n+=(e&ht)*bo,e<V)||(e=r[t+5],n+=(e&ht)*go,e<V)||(e=r[t+6],n+=(e&ht)*xo,e<V)||(e=r[t+7],n+=(e&ht)*wo,e<V))return n;throw new RangeError("Could not decode varint")}function Hu(r,t){let e=r.get(t),n=0;if(n+=e&ht,e<V||(e=r.get(t+1),n+=(e&ht)<<7,e<V)||(e=r.get(t+2),n+=(e&ht)<<14,e<V)||(e=r.get(t+3),n+=(e&ht)<<21,e<V)||(e=r.get(t+4),n+=(e&ht)*bo,e<V)||(e=r.get(t+5),n+=(e&ht)*go,e<V)||(e=r.get(t+6),n+=(e&ht)*xo,e<V)||(e=r.get(t+7),n+=(e&ht)*wo,e<V))return n;throw new RangeError("Could not decode varint")}function Di(r,t,e=0){return t==null&&(t=lt(Nt(r))),t instanceof Uint8Array?Eo(r,t,e):qu(r,t,e)}function Pi(r,t=0){return r instanceof Uint8Array?So(r,t):Hu(r,t)}var vo=new Float32Array([-0]),ae=new Uint8Array(vo.buffer);function Ni(r,t,e){vo[0]=r,t[e]=ae[0],t[e+1]=ae[1],t[e+2]=ae[2],t[e+3]=ae[3]}function Ri(r,t){return ae[0]=r[t],ae[1]=r[t+1],ae[2]=r[t+2],ae[3]=r[t+3],vo[0]}var Ao=new Float64Array([-0]),dt=new Uint8Array(Ao.buffer);function ki(r,t,e){Ao[0]=r,t[e]=dt[0],t[e+1]=dt[1],t[e+2]=dt[2],t[e+3]=dt[3],t[e+4]=dt[4],t[e+5]=dt[5],t[e+6]=dt[6],t[e+7]=dt[7]}function Ui(r,t){return dt[0]=r[t],dt[1]=r[t+1],dt[2]=r[t+2],dt[3]=r[t+3],dt[4]=r[t+4],dt[5]=r[t+5],dt[6]=r[t+6],dt[7]=r[t+7],Ao[0]}var Vu=BigInt(Number.MAX_SAFE_INTEGER),zu=BigInt(Number.MIN_SAFE_INTEGER),_t=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return we;if(t<Vu&&t>zu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Ki&&(o=0n,++n>Ki&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return we;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):we}},we=new _t(0,0);we.toBigInt=function(){return 0n};we.zzEncode=we.zzDecode=function(){return this};we.length=function(){return 1};var Ki=4294967296n;function Mi(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Oi(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Io(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Rt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Fr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Bo=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,Rt(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 Rt(this,4);return Fr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Rt(this,4);return Fr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Rt(this,4);let t=Ri(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Rt(this,4);let t=Ui(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Rt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Oi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Rt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Rt(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 _t(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Rt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Rt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Rt(this,8);let t=Fr(this.buf,this.pos+=4),e=Fr(this.buf,this.pos+=4);return new _t(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=So(this.buf,this.pos);return this.pos+=Nt(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 _o(r){return new Bo(r instanceof Uint8Array?r:r.subarray())}function St(r,t,e){let n=_o(r);return t.decode(n,void 0,e)}function Lo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return lt(i);o+i>t&&(n=lt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ee=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function To(){}var Po=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Fu=Lo();function Gu(r){return globalThis.Buffer!=null?lt(r):Fu(r)}var ar=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ee(To,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ee(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Co((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(Gr,10,_t.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=_t.fromBigInt(t);return this._push(Gr,e.length(),e)}uint64Number(t){return this._push(Eo,Nt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=_t.fromBigInt(t).zzEncode();return this._push(Gr,e.length(),e)}sint64Number(t){let e=_t.fromNumber(t).zzEncode();return this._push(Gr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Do,1,t?1:0)}fixed32(t){return this._push(ir,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=_t.fromBigInt(t);return this._push(ir,4,e.lo)._push(ir,4,e.hi)}fixed64Number(t){let e=_t.fromNumber(t);return this._push(ir,4,e.lo)._push(ir,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ni,4,t)}double(t){return this._push(ki,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Do,1,0):this.uint32(e)._push(Yu,e,t)}string(t){let e=Mi(t);return e!==0?this.uint32(e)._push(Io,e,t):this._push(Do,1,0)}fork(){return this.states=new Po(this),this.head=this.tail=new Ee(To,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Ee(To,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Gu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Do(r,t,e){t[e]=r&255}function Zu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Co=class extends Ee{next;constructor(t,e){super(Zu,t,e),this.next=void 0}};function Gr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function ir(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Yu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ar.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Wu,t,r),this},ar.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push($u,t,r),this});function Wu(r,t,e){t.set(r,e)}function $u(r,t,e){r.length<40?Io(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Z(r),e)}function No(){return new ar}function vt(r,t){let e=No();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var qe;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(qe||(qe={}));function Zr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ro(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Zr("enum",qe.VARINT,e,n)}function At(r,t){return Zr("message",qe.LENGTH_DELIMITED,r,t)}var Lt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var ko;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ko||(ko={}));(function(r){r.codec=()=>Ro(ko)})(tt||(tt={}));var Mt;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(Mt||(Mt={}));var Uo;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(Uo||(Uo={}));function Yr(r){if(isNaN(r)||r<=0)throw new $("random bytes length must be a Number bigger than 0");return ke(r)}var cr=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 Vi={get(r=globalThis){let t=r.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 ce=Vi;var fr={};xt(fr,{MAX_RSA_KEY_SIZE:()=>Ko,generateRSAKeyPair:()=>Zi,jwkToJWKKeyPair:()=>Yi,jwkToPkcs1:()=>Qu,jwkToPkix:()=>Ho,jwkToRSAPrivateKey:()=>Go,pkcs1MessageToJwk:()=>Oo,pkcs1MessageToRSAPrivateKey:()=>Vo,pkcs1ToJwk:()=>Ju,pkcs1ToRSAPrivateKey:()=>Gi,pkixMessageToJwk:()=>qo,pkixMessageToRSAPublicKey:()=>Fo,pkixToJwk:()=>tf,pkixToRSAPublicKey:()=>zo});var $r=Kr;var He=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=fr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ft.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return Fi(this.jwk,e,t)}},ur=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=fr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}sign(t){return zi(this.jwk,t)}};var Ko=8192,Mo=18,ju=1062,Xu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ju(r){let t=Ht(r);return Oo(t)}function Oo(r){return{n:G(r[1],"base64url"),e:G(r[2],"base64url"),d:G(r[3],"base64url"),p:G(r[4],"base64url"),q:G(r[5],"base64url"),dp:G(r[6],"base64url"),dq:G(r[7],"base64url"),qi:G(r[8],"base64url"),kty:"RSA"}}function Qu(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new $("JWK was missing components");return ee([Et(Uint8Array.from([0])),Et(Z(r.n,"base64url")),Et(Z(r.e,"base64url")),Et(Z(r.d,"base64url")),Et(Z(r.p,"base64url")),Et(Z(r.q,"base64url")),Et(Z(r.dp,"base64url")),Et(Z(r.dq,"base64url")),Et(Z(r.qi,"base64url"))]).subarray()}function tf(r){let t=Ht(r,{offset:0});return qo(t)}function qo(r){let t=Ht(r[1],{offset:0});return{kty:"RSA",n:G(t[0],"base64url"),e:G(t[1],"base64url")}}function Ho(r){if(r.n==null||r.e==null)throw new $("JWK was missing components");return ee([Xu,Cr(ee([Et(Z(r.n,"base64url")),Et(Z(r.e,"base64url"))]))]).subarray()}function Gi(r){let t=Ht(r);return Vo(t)}function Vo(r){let t=Oo(r);return Go(t)}function zo(r,t){if(r.byteLength>=ju)throw new Ie("Key size is too large");let e=Ht(r,{offset:0});return Fo(e,r,t)}function Fo(r,t,e){let n=qo(r);if(e==null){let o=$r(Mt.encode({Type:tt.RSA,Data:t}));e=Dt(Mo,o)}return new He(n,e)}function Go(r){if($i(r)>Ko)throw new $("Key size is too large");let t=Yi(r),e=$r(Mt.encode({Type:tt.RSA,Data:Ho(t.publicKey)})),n=Dt(Mo,e);return new ur(t.privateKey,new He(t.publicKey,n))}async function Zi(r){if(r>Ko)throw new $("Key size is too large");let t=await Wi(r),e=$r(Mt.encode({Type:tt.RSA,Data:Ho(t.publicKey)})),n=Dt(Mo,e);return new ur(t.privateKey,new He(t.publicKey,n))}function Yi(r){if(r==null)throw new $("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Wi(r){let t=await ce.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await ef(t);return{privateKey:e[0],publicKey:e[1]}}async function zi(r,t){let e=await ce.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await ce.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Fi(r,t,e){let n=await ce.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return ce.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function ef(r){if(r.privateKey==null||r.publicKey==null)throw new $("Private and public key are required");return Promise.all([ce.get().subtle.exportKey("jwk",r.privateKey),ce.get().subtle.exportKey("jwk",r.publicKey)])}function $i(r){if(r.kty!=="RSA")throw new $("invalid key type");if(r.n==null)throw new $("invalid key modulus");return Z(r.n,"base64url").length*8}var jr=class extends Ne{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,zs(t);let n=Qe(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),zt(s)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(this),de(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Zo=(r,t,e)=>new jr(r,t).update(e).digest();Zo.create=(r,t)=>new jr(r,t);function ji(r){r.lowS!==void 0&&Ut("lowS",r.lowS),r.prehash!==void 0&&Ut("prehash",r.prehash)}function rf(r){let t=sr(r);Yt(t,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...t})}var $o=class extends Error{constructor(t=""){super(t)}},$t={Err:$o,_tlv:{encode:(r,t)=>{let{Err:e}=$t;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=nr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?nr(o.length/2|128):"";return nr(r)+s+o+t},decode(r,t){let{Err:e}=$t,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=$t;if(r<jt)throw new t("integer: negative integers are not allowed");let e=nr(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=$t;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Zt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=$t,o=Y("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=$t,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};function Yo(r,t){return se(be(r,t))}var jt=BigInt(0),it=BigInt(1),Up=BigInt(2),Wo=BigInt(3),nf=BigInt(4);function of(r){let t=rf(r),{Fp:e}=t,n=Wt(t.n,t.nBitLength),o=t.toBytes||((x,h,y)=>{let B=h.toAffine();return ie(Uint8Array.from([4]),e.toBytes(B.x),e.toBytes(B.y))}),s=t.fromBytes||(x=>{let h=x.subarray(1),y=e.fromBytes(h.subarray(0,e.BYTES)),B=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:y,y:B}});function i(x){let{a:h,b:y}=t,B=e.sqr(x),_=e.mul(B,x);return e.add(e.add(_,e.mul(x,h)),y)}function a(x,h){let y=e.sqr(h),B=i(x);return e.eql(y,B)}if(!a(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let c=e.mul(e.pow(t.a,Wo),nf),f=e.mul(e.sqr(t.b),BigInt(27));if(e.is0(e.add(c,f)))throw new Error("bad curve params: a or b");function u(x){return Mr(x,it,t.n)}function l(x){let{allowedPrivateKeyLengths:h,nByteLength:y,wrapPrivateKey:B,n:_}=t;if(h&&typeof x!="bigint"){if(Ue(x)&&(x=se(x)),typeof x!="string"||!h.includes(x.length))throw new Error("invalid private key");x=x.padStart(y*2,"0")}let L;try{L=typeof x=="bigint"?x:Zt(Y("private key",x,y))}catch{throw new Error("invalid private key, expected hex or "+y+" bytes, got "+typeof x)}return B&&(L=F(L,_)),Bt("private key",L,it,_),L}function b(x){if(!(x instanceof m))throw new Error("ProjectivePoint expected")}let v=Me((x,h)=>{let{px:y,py:B,pz:_}=x;if(e.eql(_,e.ONE))return{x:y,y:B};let L=x.is0();h==null&&(h=L?e.ONE:e.inv(_));let R=e.mul(y,h),K=e.mul(B,h),P=e.mul(_,h);if(L)return{x:e.ZERO,y:e.ZERO};if(!e.eql(P,e.ONE))throw new Error("invZ was invalid");return{x:R,y:K}}),I=Me(x=>{if(x.is0()){if(t.allowInfinityPoint&&!e.is0(x.py))return;throw new Error("bad point: ZERO")}let{x:h,y}=x.toAffine();if(!e.isValid(h)||!e.isValid(y))throw new Error("bad point: x or y not FE");if(!a(h,y))throw new Error("bad point: equation left != right");if(!x.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class m{constructor(h,y,B){if(h==null||!e.isValid(h))throw new Error("x required");if(y==null||!e.isValid(y)||e.is0(y))throw new Error("y required");if(B==null||!e.isValid(B))throw new Error("z required");this.px=h,this.py=y,this.pz=B,Object.freeze(this)}static fromAffine(h){let{x:y,y:B}=h||{};if(!h||!e.isValid(y)||!e.isValid(B))throw new Error("invalid affine point");if(h instanceof m)throw new Error("projective point not allowed");let _=L=>e.eql(L,e.ZERO);return _(y)&&_(B)?m.ZERO:new m(y,B,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let y=Oe(e,h.map(B=>B.pz));return h.map((B,_)=>B.toAffine(y[_])).map(m.fromAffine)}static fromHex(h){let y=m.fromAffine(s(Y("pointHex",h)));return y.assertValidity(),y}static fromPrivateKey(h){return m.BASE.multiply(l(h))}static msm(h,y){return Hr(m,n,h,y)}_setWindowSize(h){O.setWindowSize(this,h)}assertValidity(){I(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){b(h);let{px:y,py:B,pz:_}=this,{px:L,py:R,pz:K}=h,P=e.eql(e.mul(y,K),e.mul(L,_)),k=e.eql(e.mul(B,K),e.mul(R,_));return P&&k}negate(){return new m(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:y}=t,B=e.mul(y,Wo),{px:_,py:L,pz:R}=this,K=e.ZERO,P=e.ZERO,k=e.ZERO,N=e.mul(_,_),et=e.mul(L,L),E=e.mul(R,R),w=e.mul(_,L);return w=e.add(w,w),k=e.mul(_,R),k=e.add(k,k),K=e.mul(h,k),P=e.mul(B,E),P=e.add(K,P),K=e.sub(et,P),P=e.add(et,P),P=e.mul(K,P),K=e.mul(w,K),k=e.mul(B,k),E=e.mul(h,E),w=e.sub(N,E),w=e.mul(h,w),w=e.add(w,k),k=e.add(N,N),N=e.add(k,N),N=e.add(N,E),N=e.mul(N,w),P=e.add(P,N),E=e.mul(L,R),E=e.add(E,E),N=e.mul(E,w),K=e.sub(K,N),k=e.mul(E,et),k=e.add(k,k),k=e.add(k,k),new m(K,P,k)}add(h){b(h);let{px:y,py:B,pz:_}=this,{px:L,py:R,pz:K}=h,P=e.ZERO,k=e.ZERO,N=e.ZERO,et=t.a,E=e.mul(t.b,Wo),w=e.mul(y,L),T=e.mul(B,R),g=e.mul(_,K),d=e.add(y,B),p=e.add(L,R);d=e.mul(d,p),p=e.add(w,T),d=e.sub(d,p),p=e.add(y,_);let S=e.add(L,K);return p=e.mul(p,S),S=e.add(w,g),p=e.sub(p,S),S=e.add(B,_),P=e.add(R,K),S=e.mul(S,P),P=e.add(T,g),S=e.sub(S,P),N=e.mul(et,p),P=e.mul(E,g),N=e.add(P,N),P=e.sub(T,N),N=e.add(T,N),k=e.mul(P,N),T=e.add(w,w),T=e.add(T,w),g=e.mul(et,g),p=e.mul(E,p),T=e.add(T,g),g=e.sub(w,g),g=e.mul(et,g),p=e.add(p,g),w=e.mul(T,p),k=e.add(k,w),w=e.mul(S,p),P=e.mul(d,P),P=e.sub(P,w),w=e.mul(d,T),N=e.mul(S,N),N=e.add(N,w),new m(P,k,N)}subtract(h){return this.add(h.negate())}is0(){return this.equals(m.ZERO)}wNAF(h){return O.wNAFCached(this,h,m.normalizeZ)}multiplyUnsafe(h){let{endo:y,n:B}=t;Bt("scalar",h,jt,B);let _=m.ZERO;if(h===jt)return _;if(this.is0()||h===it)return this;if(!y||O.hasPrecomputes(this))return O.wNAFCachedUnsafe(this,h,m.normalizeZ);let{k1neg:L,k1:R,k2neg:K,k2:P}=y.splitScalar(h),k=_,N=_,et=this;for(;R>jt||P>jt;)R&it&&(k=k.add(et)),P&it&&(N=N.add(et)),et=et.double(),R>>=it,P>>=it;return L&&(k=k.negate()),K&&(N=N.negate()),N=new m(e.mul(N.px,y.beta),N.py,N.pz),k.add(N)}multiply(h){let{endo:y,n:B}=t;Bt("scalar",h,it,B);let _,L;if(y){let{k1neg:R,k1:K,k2neg:P,k2:k}=y.splitScalar(h),{p:N,f:et}=this.wNAF(K),{p:E,f:w}=this.wNAF(k);N=O.constTimeNegate(R,N),E=O.constTimeNegate(P,E),E=new m(e.mul(E.px,y.beta),E.py,E.pz),_=N.add(E),L=et.add(w)}else{let{p:R,f:K}=this.wNAF(h);_=R,L=K}return m.normalizeZ([_,L])[0]}multiplyAndAddUnsafe(h,y,B){let _=m.BASE,L=(K,P)=>P===jt||P===it||!K.equals(_)?K.multiplyUnsafe(P):K.multiply(P),R=L(this,y).add(L(h,B));return R.is0()?void 0:R}toAffine(h){return v(this,h)}isTorsionFree(){let{h,isTorsionFree:y}=t;if(h===it)return!0;if(y)return y(m,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:y}=t;return h===it?this:y?y(m,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Ut("isCompressed",h),this.assertValidity(),o(m,this,h)}toHex(h=!0){return Ut("isCompressed",h),se(this.toRawBytes(h))}}m.BASE=new m(t.Gx,t.Gy,e.ONE),m.ZERO=new m(e.ZERO,e.ONE,e.ZERO);let{endo:A,nBitLength:D}=t,O=qr(m,A?Math.ceil(D/2):D);return{CURVE:t,ProjectivePoint:m,normPrivateKeyToScalar:l,weierstrassEquation:i,isWithinCurveOrder:u}}function sf(r){let t=sr(r);return Yt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Xi(r){let t=sf(r),{Fp:e,n,nByteLength:o,nBitLength:s}=t,i=e.BYTES+1,a=2*e.BYTES+1;function c(E){return F(E,n)}function f(E){return Or(E,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:b,isWithinCurveOrder:v}=of({...t,toBytes(E,w,T){let g=w.toAffine(),d=e.toBytes(g.x),p=ie;return Ut("isCompressed",T),T?p(Uint8Array.from([w.hasEvenY()?2:3]),d):p(Uint8Array.from([4]),d,e.toBytes(g.y))},fromBytes(E){let w=E.length,T=E[0],g=E.subarray(1);if(w===i&&(T===2||T===3)){let d=Zt(g);if(!Mr(d,it,e.ORDER))throw new Error("Point is not on curve");let p=b(d),S;try{S=e.sqrt(p)}catch(M){let q=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+q)}let C=(S&it)===it;return(T&1)===1!==C&&(S=e.neg(S)),{x:d,y:S}}else if(w===a&&T===4){let d=e.fromBytes(g.subarray(0,e.BYTES)),p=e.fromBytes(g.subarray(e.BYTES,2*e.BYTES));return{x:d,y:p}}else{let d=i,p=a;throw new Error("invalid Point, expected length of "+d+", or uncompressed "+p+", got "+w)}}});function I(E){let w=n>>it;return E>w}function m(E){return I(E)?c(-E):E}let A=(E,w,T)=>Zt(E.slice(w,T));class D{constructor(w,T,g){Bt("r",w,it,n),Bt("s",T,it,n),this.r=w,this.s=T,g!=null&&(this.recovery=g),Object.freeze(this)}static fromCompact(w){let T=o;return w=Y("compactSignature",w,T*2),new D(A(w,0,T),A(w,T,2*T))}static fromDER(w){let{r:T,s:g}=$t.toSig(Y("DER",w));return new D(T,g)}assertValidity(){}addRecoveryBit(w){return new D(this.r,this.s,w)}recoverPublicKey(w){let{r:T,s:g,recovery:d}=this,p=_(Y("msgHash",w));if(d==null||![0,1,2,3].includes(d))throw new Error("recovery id invalid");let S=d===2||d===3?T+t.n:T;if(S>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let C=(d&1)===0?"02":"03",U=u.fromHex(C+Yo(S,e.BYTES)),M=f(S),q=c(-p*M),H=c(g*M),z=u.BASE.multiplyAndAddUnsafe(U,q,H);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return I(this.s)}normalizeS(){return this.hasHighS()?new D(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return or(this.toDERHex())}toDERHex(){return $t.hexFromSig(this)}toCompactRawBytes(){return or(this.toCompactHex())}toCompactHex(){let w=o;return Yo(this.r,w)+Yo(this.s,w)}}let O={isValidPrivateKey(E){try{return l(E),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let E=ao(t.n);return bi(t.randomBytes(E),t.n)},precompute(E=8,w=u.BASE){return w._setWindowSize(E),w.multiply(BigInt(3)),w}};function x(E,w=!0){return u.fromPrivateKey(E).toRawBytes(w)}function h(E){if(typeof E=="bigint")return!1;if(E instanceof u)return!0;let T=Y("key",E).length,g=e.BYTES,d=g+1,p=2*g+1;if(!(t.allowedPrivateKeyLengths||o===d))return T===d||T===p}function y(E,w,T=!0){if(h(E)===!0)throw new Error("first arg must be private key");if(h(w)===!1)throw new Error("second arg must be public key");return u.fromHex(w).multiply(l(E)).toRawBytes(T)}let B=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let w=Zt(E),T=E.length*8-s;return T>0?w>>BigInt(T):w},_=t.bits2int_modN||function(E){return c(B(E))},L=ge(s);function R(E){return Bt("num < 2^"+s,E,jt,L),be(E,o)}function K(E,w,T=P){if(["recovered","canonical"].some(J=>J in T))throw new Error("sign() legacy options not supported");let{hash:g,randomBytes:d}=t,{lowS:p,prehash:S,extraEntropy:C}=T;p==null&&(p=!0),E=Y("msgHash",E),ji(T),S&&(E=Y("prehashed msgHash",g(E)));let U=_(E),M=l(w),q=[R(M),R(U)];if(C!=null&&C!==!1){let J=C===!0?d(e.BYTES):C;q.push(Y("extraEntropy",J))}let H=ie(...q),z=U;function rt(J){let at=B(J);if(!v(at))return;let gt=f(at),ot=u.BASE.multiply(at).toAffine(),ut=c(ot.x);if(ut===jt)return;let It=c(gt*c(z+ut*M));if(It===jt)return;let Tt=(ot.x===ut?0:2)|Number(ot.y&it),Ge=It;return p&&I(It)&&(Ge=m(It),Tt^=1),new D(ut,Ge,Tt)}return{seed:H,k2sig:rt}}let P={lowS:t.lowS,prehash:!1},k={lowS:t.lowS,prehash:!1};function N(E,w,T=P){let{seed:g,k2sig:d}=K(E,w,T),p=t;return ui(p.hash.outputLen,p.nByteLength,p.hmac)(g,d)}u.BASE._setWindowSize(8);function et(E,w,T,g=k){let d=E;w=Y("msgHash",w),T=Y("publicKey",T);let{lowS:p,prehash:S,format:C}=g;if(ji(g),"strict"in g)throw new Error("options.strict was renamed to lowS");if(C!==void 0&&C!=="compact"&&C!=="der")throw new Error("format must be compact or der");let U=typeof d=="string"||Ue(d),M=!U&&!C&&typeof d=="object"&&d!==null&&typeof d.r=="bigint"&&typeof d.s=="bigint";if(!U&&!M)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let q,H;try{if(M&&(q=new D(d.r,d.s)),U){try{C!=="compact"&&(q=D.fromDER(d))}catch(Tt){if(!(Tt instanceof $t.Err))throw Tt}!q&&C!=="der"&&(q=D.fromCompact(d))}H=u.fromHex(T)}catch{return!1}if(!q||p&&q.hasHighS())return!1;S&&(w=t.hash(w));let{r:z,s:rt}=q,J=_(w),at=f(rt),gt=c(J*at),ot=c(z*at),ut=u.BASE.multiplyAndAddUnsafe(H,gt,ot)?.toAffine();return ut?c(ut.x)===z:!1}return{CURVE:t,getPublicKey:x,getSharedSecret:y,sign:N,verify:et,ProjectivePoint:u,Signature:D,utils:O}}function af(r){return{hash:r,hmac:(t,...e)=>Zo(r,t,$n(...e)),randomBytes:ke}}function Ji(r,t){let e=n=>Xi({...r,...af(n)});return{...e(t),create:e}}var ea=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Qi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),cf=BigInt(0),uf=BigInt(1),jo=BigInt(2),ta=(r,t)=>(r+t/jo)/t;function ff(r){let t=ea,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,u=f*f*r%t,l=W(u,e,t)*u%t,b=W(l,e,t)*u%t,v=W(b,jo,t)*f%t,I=W(v,o,t)*v%t,m=W(I,s,t)*I%t,A=W(m,a,t)*m%t,D=W(A,c,t)*A%t,O=W(D,a,t)*m%t,x=W(O,e,t)*u%t,h=W(x,i,t)*I%t,y=W(h,n,t)*f%t,B=W(y,jo,t);if(!Xo.eql(Xo.sqr(B),r))throw new Error("Cannot find square root");return B}var Xo=Wt(ea,void 0,void 0,{sqrt:ff}),Ve=Ji({a:cf,b:BigInt(7),Fp:Xo,n:Qi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Qi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-uf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=ta(s*r,t),c=ta(-n*r,t),f=F(r-a*e-c*o,t),u=F(-a*n-c*s,t),l=f>i,b=u>i;if(l&&(f=t-f),b&&(u=t-u),f>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:b,k2:u}}}},Kr);function ra(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function na(r,t,e){let n=le.digest(e instanceof Uint8Array?e:e.subarray());if(ra(n))return n.then(({digest:o})=>Ve.verify(t,o,r)).catch(o=>{throw new cr(String(o))});try{return Ve.verify(t,n.digest,r)}catch(o){throw new cr(String(o))}}var Xr=class{type="secp256k1";raw;_key;constructor(t){this._key=sa(t),this.raw=oa(this._key)}toMultihash(){return Pt.digest(Vt(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return na(this._key,e,t)}};function Jo(r){return new Xr(r)}function oa(r){return Ve.ProjectivePoint.fromHex(r).toRawBytes(!0)}function sa(r){try{return Ve.ProjectivePoint.fromHex(r),r}catch(t){throw new Ie(String(t))}}function Qo(r,t){let{Type:e,Data:n}=Mt.decode(r),o=n??new Uint8Array;switch(e){case tt.RSA:return zo(o,t);case tt.Ed25519:return yo(o);case tt.secp256k1:return Jo(o);case tt.ECDSA:return Wn(o);default:throw new ue}}function ia(r){let{Type:t,Data:e}=Mt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return yo(n);case tt.secp256k1:return Jo(n);case tt.ECDSA:return Wn(n);default:throw new ue}}function Vt(r){return Mt.encode({Type:tt[r.type],Data:r.raw})}var aa=Symbol.for("nodejs.util.inspect.custom"),lf=114,lr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[wn]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ft.createV1(lf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return wt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return wt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[aa](){return`PeerId(${this.toString()})`}},hr=class extends lr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},dr=class extends lr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},pr=class extends lr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},hf=2336,Jr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Pt.digest(Z(this.url))}[aa](){return`PeerId(${this.url})`}[wn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ft.createV1(hf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=G(t)),t.toString()===this.toString())}};function ts(r){if(r.type==="Ed25519")return new dr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new pr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new hr({multihash:r.toCID().multihash,publicKey:r});throw new ue}function ca(r){return ts(r.publicKey)}function mr(r){if(pf(r))return new hr({multihash:r});if(df(r))try{let t=ia(r);if(t.type==="Ed25519")return new dr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new pr({multihash:r,publicKey:t})}catch{let e=G(r.digest);return new Jr(new URL(e))}throw new _r("Supplied PeerID Multihash is invalid")}function df(r){return r.code===Pt.code}function pf(r){return r.code===le.code}function Se(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function Qr(r){let t=Qt(j.decode(`z${r}`));return mr(t)}var yr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return Se(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return Se(this.map.values(),t=>t.key)}values(){return Se(this.map.values(),t=>t.value)}get size(){return this.map.size}};var br=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Se(this.set.entries(),t=>{let e=Qr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Qr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Se(this.set.values(),t=>Qr(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function Xt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var tn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},ze=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new tn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new tn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var es=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function en(r={}){return mf(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function mf(r,t){t=t??{};let e=t.onEnd,n=new ze,o,s,i,a=Xt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((A,D)=>{s=O=>{s=null,n.push(O);try{A(r(n))}catch(x){D(x)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Xt()})}},f=A=>s!=null?s(A):(n.push(A),o),u=A=>(n=new ze,s!=null?s({error:A}):(n.push({error:A}),o)),l=A=>{if(i)return o;if(t?.objectMode!==!0&&A?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:A})},b=A=>i?o:(i=!0,A!=null?u(A):f({done:!0})),v=()=>(n=new ze,b(),{done:!0}),I=A=>(b(A),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:v,throw:I,push:l,end:b,get readableLength(){return n.size},onEmpty:async A=>{let D=A?.signal;if(D?.throwIfAborted(),n.isEmpty())return;let O,x;D!=null&&(O=new Promise((h,y)=>{x=()=>{y(new es)},D.addEventListener("abort",x)}));try{await Promise.race([a.promise,O])}finally{x!=null&&D!=null&&D?.removeEventListener("abort",x)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(A){return m.throw(A),e!=null&&(e(A),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(A){return m.end(A),e!=null&&(e(A),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:A=>m.onEmpty(A)},o}var rn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function ua(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new rn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new rn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var rs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Xt(),this.haveNext=Xt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Xt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Xt(),await ua(this.readNext.promise,e?.signal,e)}};function fa(){return new rs}function yf(r){return r[Symbol.asyncIterator]!=null}async function bf(r,t,e){try{await Promise.all(r.map(async n=>{for await(let o of n)await t.push(o,{signal:e}),e.throwIfAborted()})),await t.end(void 0,{signal:e})}catch(n){await t.end(n,{signal:e}).catch(()=>{})}}async function*gf(r){let t=new AbortController,e=fa();bf(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*xf(r){for(let t of r)yield*t}function wf(...r){let t=[];for(let e of r)yf(e)||t.push(e);return t.length===r.length?xf(t):gf(r)}var la=wf;function gr(r,...t){if(r==null)throw new Error("Empty pipeline");if(ns(r)){let n=r;r=()=>n.source}else if(da(r)||ha(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&ns(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)ns(e[n])&&(e[n]=Sf(e[n]));return Ef(...e)}var Ef=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},ha=r=>r?.[Symbol.asyncIterator]!=null,da=r=>r?.[Symbol.iterator]!=null,ns=r=>r==null?!1:r.sink!=null&&r.source!=null,Sf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=en({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(ha(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 r.source};var ss=qa(ma(),1);var wr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},is=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},ya=r=>globalThis.DOMException===void 0?new is(r):new DOMException(r),ba=r=>{let t=r.reason===void 0?ya("This operation was aborted."):r.reason;return t instanceof Error?t:ya(t)};function as(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,f=new Promise((u,l)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:v}=t;v.aborted&&l(ba(v)),a=()=>{l(ba(v))},v.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,l);return}let b=new wr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(v){l(v)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?l(o):(b.message=o??`Promise timed out after ${e} milliseconds`,l(b))},e),(async()=>{try{u(await r)}catch(v){l(v)}})()}).finally(()=>{f.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}function cs(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var Er=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let o=cs(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var Sr=class extends ss.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#x=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Er,...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#w(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},e)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#w&&this.#E){let e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#I(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#x++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=as(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#I(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof wr&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function ga(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function xa(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function wa(r,t){let e=ga(r).return?.();xa(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var on=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Fe=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},sn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},vr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function an(r){return r[Symbol.asyncIterator]!=null}function Ea(r,t){if(r.byteLength>t)throw new Fe("Message length too long")}var un=r=>{let t=Nt(r),e=lt(t);return Di(r,e),un.bytes=t,e};un.bytes=0;function fn(r,t){t=t??{};let e=t.lengthEncoder??un,n=t?.maxDataLength??4194304;function*o(s){Ea(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return an(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}fn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??un,n=t?.maxDataLength??4194304;return Ea(r,n),new nt(e(r.byteLength),r)};var ve;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ve||(ve={}));var us=r=>{let t=Pi(r);return us.bytes=Nt(t),t};us.bytes=0;function Ar(r,t){let e=new nt,n=ve.LENGTH,o=-1,s=t?.lengthDecoder??us,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===ve.LENGTH)try{if(o=s(e),o<0)throw new on("Invalid message length");if(o>a)throw new Fe("Message length too long");let f=s.bytes;e.consume(f),t?.onLength!=null&&t.onLength(o),n=ve.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>i)throw new sn("Message length length too long");break}throw f}if(n===ve.DATA){if(e.byteLength<o)break;let f=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(f),yield f,n=ve.LENGTH}}}return an(r)?async function*(){for await(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new vr("Unexpected end of input")}():function*(){for(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new vr("Unexpected end of input")}()}Ar.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return Ar(n,{...t??{},onLength:s=>{e=s}})};var ln=class extends Be{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=e.id,this.protocol=e.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let e=this.id.toString();throw new Error("No writable connection to "+e)}this.outboundStream.push(t instanceof Uint8Array?new nt(t):t)}attachInboundStream(t,e){let n=()=>{wa(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=gr(this._rawInboundStream,o=>Ar(o,e)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let e=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=en({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"))}}),gr(this.outboundStream,n=>fn(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),e==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function Sa(){return BigInt(`0x${G(Yr(8),"base16")}`)}var va=(r,t)=>{let e=Z(t.toString(16).padStart(16,"0"),"base16"),n=Vt(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},Aa=r=>le.encode(r);var Ia=function(r){return Array.isArray(r)?r:[r]},_f=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=mr(Qt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return ts(Qo(e)).equals(t)}return!1},Ba=async r=>{if(r.from==null)throw new Q("RPC message was missing from");if(!await _f(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=mr(Qt(r.from)),e=r.key??t.publicKey;if(e==null)throw new Q("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:Tf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?Qo(e):e}},Ir=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:Lf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Vt(r.key):void 0}:{data:r.data,topic:r.topic},Lf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),Z(t,"base16")},Tf=r=>BigInt(`0x${G(r,"base16")}`);var _a=Z("libp2p-pubsub:");async function La(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:ca(r)},o=fe([_a,e(Ir(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function Ta(r,t){if(r.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(r.signature==null)throw new Error("Message must contain a signature to be verified");if(r.from==null)throw new Error("Message must contain a from property to be verified");let e=fe([_a,t({...Ir(r),signature:void 0,key:void 0}).subarray()]);return Df(r).verify(e,r.signature)}function Df(r){if(r.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(r.from==null)throw new Error("Could not get the public key from the originator id");if(r.key!=null)return r.key;if(r.from.publicKey!=null)return r.from.publicKey;throw new Error("Could not get the public key from the originator id")}var hn=class extends Be{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,e){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:a=10,maxInboundStreams:c=1,maxOutboundStreams:f=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=Ia(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new yr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new Sr({concurrency:a}),this.maxInboundStreams=c,this.maxOutboundStreams=f,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let e={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.multicodecs.map(async e=>{await t.unhandle(e)})),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:e,connection:n}=t,o=n.remotePeer;if(e.protocol==null){e.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,e.protocol),i=s.attachInboundStream(e);this.processMessages(o,i,s).catch(a=>{this.log(a)})}_onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await e.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new ln(this.components,{id:t,protocol:e});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return e}}async processMessages(t,e,n){try{await gr(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),a=[];for(let c of i.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,e,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.id,subscriptions:o.map(({topic:i,subscribe:a})=>({topic:`${i??""}`,subscribe:!!a}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let a=await Ba(i);await this.processMessage(t,a)}catch(a){this.log.error(a)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new br,this.topics.set(n,o)),e.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,e){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,e)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new 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 va(t.key,t.sequenceNumber);case"StrictNoSign":return Aa(t.data);default:throw new Q("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,e){let{messages:n,subscriptions:o,subscribe:s}=e;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(Ir)})}sendRpc(t,e){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(e))}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new Q('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new Q("StrictNoSigning: signature should not be present");if(e.key!=null)throw new Q("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new Q("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new Q("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new Q("StrictSigning: Signing required and no sequenceNumber was present");if(!await Ta(e,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(e.topic);if(o!=null){let s=await o(t,e);if(s===Ze.Reject||s===Ze.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return La(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 Lr("not started yet");if(t==null)throw new $("Topic is required");let e=this.topics.get(t.toString());return e==null?[]:Array.from(e.values())}async publish(t,e){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:e??new Uint8Array(0),sequenceNumber:Sa()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let e=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,e),e){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};var dn=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,e){this.entries.set(t,{value:e,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[e,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(e);else break}}has(t){return this.entries.has(t)}get(t){let e=this.entries.get(t);return e!=null&&e.validUntilMs>=Date.now()?e.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var fs="/floodsub/1.0.0";var Ae;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=At((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 f={},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{f.subscribe=i.bool();break}case 2:{f.topic=i.string();break}default:{i.skipType(l&7);break}}}return f})),s),o.encode=i=>vt(i,o.codec()),o.decode=(i,a)=>St(i,o.codec(),a)})(t=r.SubOpts||(r.SubOpts={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=At((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 f={},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{f.from=i.bytes();break}case 2:{f.data=i.bytes();break}case 3:{f.sequenceNumber=i.bytes();break}case 4:{f.topic=i.string();break}case 5:{f.signature=i.bytes();break}case 6:{f.key=i.bytes();break}default:{i.skipType(l&7);break}}}return f})),s),o.encode=i=>vt(i,o.codec()),o.decode=(i,a)=>St(i,o.codec(),a)})(e=r.Message||(r.Message={}));let n;r.codec=()=>(n==null&&(n=At((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.subscriptions!=null)for(let a of o.subscriptions)s.uint32(10),r.SubOpts.codec().encode(a,s);if(o.messages!=null)for(let a of o.messages)s.uint32(18),r.Message.codec().encode(a,s);o.control!=null&&(s.uint32(26),pn.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 f=o.uint32();switch(f>>>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(r.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(r.Message.codec().decode(o,o.uint32(),{limits:i.limits?.messages$}));break}case 3:{a.control=pn.codec().decode(o,o.uint32(),{limits:i.limits?.control});break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>vt(o,r.codec()),r.decode=(o,s)=>St(o,r.codec(),s)})(Ae||(Ae={}));var pn;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.ihave!=null)for(let s of e.ihave)n.uint32(10),mn.codec().encode(s,n);if(e.iwant!=null)for(let s of e.iwant)n.uint32(18),yn.codec().encode(s,n);if(e.graft!=null)for(let s of e.graft)n.uint32(26),bn.codec().encode(s,n);if(e.prune!=null)for(let s of e.prune)n.uint32(34),gn.codec().encode(s,n);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={ihave:[],iwant:[],graft:[],prune:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.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(mn.codec().decode(e,e.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(yn.codec().decode(e,e.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(bn.codec().decode(e,e.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(gn.codec().decode(e,e.uint32(),{limits:o.limits?.prune$}));break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(pn||(pn={}));var mn;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.messageIDs!=null)for(let s of e.messageIDs)n.uint32(18),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={messageIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.topic=e.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(e.bytes());break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(mn||(mn={}));var yn;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.messageIDs!=null)for(let s of e.messageIDs)n.uint32(10),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={messageIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.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(e.bytes());break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(yn||(yn={}));var bn;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.topic=e.string();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(bn||(bn={}));var gn;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.peers!=null)for(let s of e.peers)n.uint32(18),xn.codec().encode(s,n);e.backoff!=null&&(n.uint32(24),n.uint64(e.backoff)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={peers:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.topic=e.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(xn.codec().decode(e,e.uint32(),{limits:o.limits?.peers$}));break}case 3:{s.backoff=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(gn||(gn={}));var xn;(function(r){let t;r.codec=()=>(t==null&&(t=At((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.peerID!=null&&(n.uint32(10),n.bytes(e.peerID)),e.signedPeerRecord!=null&&(n.uint32(18),n.bytes(e.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.peerID=e.bytes();break}case 2:{s.signedPeerRecord=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>vt(e,r.codec()),r.decode=(e,n)=>St(e,r.codec(),n)})(xn||(xn={}));var ls=class extends hn{seenCache;constructor(t,e){super(t,{...e,canRelayMessage:!0,multicodecs:[fs]}),this.log=t.logger.forComponent("libp2p:floodsub"),this.seenCache=new dn({validityMs:e?.seenTTL??3e4})}[ps]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[ms]=["@libp2p/pubsub"];[ys]=["@libp2p/identify"];decodeRpc(t){return Ae.decode(t)}encodeRpc(t){return Ae.encode(t)}decodeMessage(t){return Ae.Message.decode(t)}encodeMessage(t){return Ae.Message.encode(t)}async processMessage(t,e){let n=await super.getMsgId(e),o=G(n,"base64");this.seenCache.has(o)||(this.seenCache.put(o,!0),await super.processMessage(t,e))}async publishMessage(t,e){let n=this.getSubscribers(e.topic),o=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",e.topic),{recipients:o}):(n.forEach(s=>{if(this.components.peerId.equals(s)){this.log("not sending message on topic %s to myself",e.topic);return}if(s.equals(t)){this.log("not sending message on topic %s to sender %p",e.topic,s);return}this.log("publish msgs on topics %s %p",e.topic,s),o.push(s),this.send(s,{messages:[e]})}),{recipients:o})}};function Pf(r={}){return t=>new ls(t,r)}return Ha(Cf);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|