@libp2p/floodsub 10.1.32 → 10.1.33
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/package.json +8 -8
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 Sa=Object.create;var Er=Object.defineProperty;var va=Object.getOwnPropertyDescriptor;var Aa=Object.getOwnPropertyNames;var Ia=Object.getPrototypeOf,Ba=Object.prototype.hasOwnProperty;var La=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),mt=(r,t)=>{for(var e in t)Er(r,e,{get:t[e],enumerable:!0})},ds=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Aa(t))!Ba.call(r,o)&&o!==e&&Er(r,o,{get:()=>t[o],enumerable:!(n=va(t,o))||n.enumerable});return r};var _a=(r,t,e)=>(e=r!=null?Sa(Ia(r)):{},ds(t||!r||!r.__esModule?Er(e,"default",{value:r,enumerable:!0}):e,r)),Ta=r=>ds(Er({},"__esModule",{value:!0}),r);var Qi=La(($m,Jo)=>{"use strict";var Hf=Object.prototype.hasOwnProperty,yt="~";function pr(){}Object.create&&(pr.prototype=Object.create(null),new pr().__proto__||(yt=!1));function Vf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Ji(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=yt?yt+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 Qr(r,t){--r._eventsCount===0?r._events=new pr:delete r._events[t]}function dt(){this._events=new pr,this._eventsCount=0}dt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Hf.call(e,n)&&t.push(yt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};dt.prototype.listeners=function(t){var e=yt?yt+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};dt.prototype.listenerCount=function(t){var e=yt?yt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};dt.prototype.emit=function(t,e,n,o,s,i){var a=yt?yt+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 p=c.length,x;for(l=0;l<p;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(x=1,u=new Array(f-1);x<f;x++)u[x-1]=arguments[x];c[l].fn.apply(c[l].context,u)}}return!0};dt.prototype.on=function(t,e,n){return Ji(this,t,e,n,!1)};dt.prototype.once=function(t,e,n){return Ji(this,t,e,n,!0)};dt.prototype.removeListener=function(t,e,n,o){var s=yt?yt+t:t;if(!this._events[s])return this;if(!e)return Qr(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&Qr(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:Qr(this,s)}return this};dt.prototype.removeAllListeners=function(t){var e;return t?(e=yt?yt+t:t,this._events[e]&&Qr(this,e)):(this._events=new pr,this._eventsCount=0),this};dt.prototype.off=dt.prototype.removeListener;dt.prototype.addListener=dt.prototype.on;dt.prefixed=yt;dt.EventEmitter=dt;typeof Jo<"u"&&(Jo.exports=dt)});var jf={};mt(jf,{floodsub:()=>Wf,multicodec:()=>os});var bn=Symbol.for("@libp2p/peer-id");var Fe;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Fe||(Fe={}));var ps=Symbol.for("@libp2p/pubsub");var W=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ae=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Sr=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 vr=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 Ie=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var ms=Symbol.for("@libp2p/service-capabilities"),ys=Symbol.for("@libp2p/service-dependencies");var Sn={};mt(Sn,{base58btc:()=>j,base58flickr:()=>ka});var Al=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 Mt(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 Da(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(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var b=0,h=0,g=0,S=E.length;g!==S&&E[g]===0;)g++,b++;for(var m=(S-g)*u+1>>>0,I=new Uint8Array(m);g!==S;){for(var D=E[g],P=0,B=m-1;(D!==0||P<h)&&B!==-1;B--,P++)D+=256*I[B]>>>0,I[B]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");h=P,g++}for(var T=m-h;T!==m&&I[T]===0;)T++;for(var L=c.repeat(b);T<m;++T)L+=r.charAt(I[T]);return L}function p(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var b=0;if(E[b]!==" "){for(var h=0,g=0;E[b]===c;)h++,b++;for(var S=(E.length-b)*f+1>>>0,m=new Uint8Array(S);E[b];){var I=e[E.charCodeAt(b)];if(I===255)return;for(var D=0,P=S-1;(I!==0||D<g)&&P!==-1;P--,D++)I+=a*m[P]>>>0,m[P]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");g=D,b++}if(E[b]!==" "){for(var B=S-g;B!==S&&m[B]===0;)B++;for(var T=new Uint8Array(h+(S-B)),L=h;B!==S;)T[L++]=m[B++];return T}}}function x(E){var b=p(E);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:p,decode:x}}var Pa=Da,Ca=Pa,Es=Ca;var gn=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")}},xn=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)}},wn=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 wn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var En=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 gn(t,e,n),this.decoder=new xn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Be({name:r,prefix:t,encode:e,decode:n}){return new En(r,t,e,n)}function Wt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Es(e,r);return Be({prefix:t,name:r,encode:n,decode:s=>Mt(o(s))})}function Ra(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 Na(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 J({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Be({prefix:t,name:r,encode(o){return Na(o,n,e)},decode(o){return Ra(o,n,e,r)}})}var j=Wt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ka=Wt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var vn={};mt(vn,{base32:()=>Le,base32hex:()=>Oa,base32hexpad:()=>Ha,base32hexpadupper:()=>Va,base32hexupper:()=>qa,base32pad:()=>Ua,base32padupper:()=>Ma,base32upper:()=>Ka,base32z:()=>za});var Le=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ka=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ua=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ma=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Oa=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),qa=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ha=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Va=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),za=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var An={};mt(An,{base36:()=>Ge,base36upper:()=>Fa});var Ge=Wt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Fa=Wt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ga=Is,vs=128,Za=127,Ya=~Za,$a=Math.pow(2,31);function Is(r,t,e){t=t||[],e=e||0;for(var n=e;r>=$a;)t[e++]=r&255|vs,r/=128;for(;r&Ya;)t[e++]=r&255|vs,r>>>=7;return t[e]=r|0,Is.bytes=e-n+1,t}var Wa=In,ja=128,As=127;function In(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw In.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>=ja);return In.bytes=s-n,e}var Xa=Math.pow(2,7),Ja=Math.pow(2,14),Qa=Math.pow(2,21),tc=Math.pow(2,28),ec=Math.pow(2,35),rc=Math.pow(2,42),nc=Math.pow(2,49),oc=Math.pow(2,56),sc=Math.pow(2,63),ic=function(r){return r<Xa?1:r<Ja?2:r<Qa?3:r<tc?4:r<ec?5:r<rc?6:r<nc?7:r<oc?8:r<sc?9:10},ac={encode:Ga,decode:Wa,encodingLength:ic},cc=ac,Ze=cc;function Ye(r,t=0){return[Ze.decode(r,t),Ze.decode.bytes]}function _e(r,t,e=0){return Ze.encode(r,t,e),t}function Te(r){return Ze.encodingLength(r)}function Lt(r,t){let e=t.byteLength,n=Te(r),o=n+Te(e),s=new Uint8Array(o+e);return _e(r,s,0),_e(e,s,n),s.set(t,o),new De(r,e,t,s)}function jt(r){let t=Mt(r),[e,n]=Ye(t),[o,s]=Ye(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new De(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 De=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Ls(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return fc(e,Bn(r),t??j.encoder);default:return lc(e,Bn(r),t??Le.encoder)}}var _s=new WeakMap;function Bn(r){let t=_s.get(r);if(t==null){let e=new Map;return _s.set(r,e),e}return t}var ut=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!==$e)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==hc)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=Lt(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 Ls(this,t)}toJSON(){return{"/":Ls(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[dc]===!0){let{version:n,multihash:o,code:s}=e,i=jt(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!==$e)throw new Error(`Version 0 CID must use dag-pb (code: ${$e}) 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,$e,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=Mt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new De(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,p]=Ye(t.subarray(e));return e+=p,l},o=n(),s=$e;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]=uc(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 Bn(s).set(n,t),s}};function uc(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 Ge.prefix:{let e=t??Ge;return[Ge.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 fc(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 lc(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 $e=112,hc=18;function Ts(r,t,e){let n=Te(r),o=n+Te(t),s=new Uint8Array(o+e.byteLength);return _e(r,s,0),_e(t,s,n),s.set(e,o),s}var dc=Symbol.for("@ipld/js-cid/CID");var Ln={};mt(Ln,{identity:()=>_t});var Ds=0,pc="identity",Ps=Mt;function mc(r){return Lt(Ds,Ps(r))}var _t={code:Ds,name:pc,encode:Ps,digest:mc};function gt(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=0){return new Uint8Array(r)}function ft(r=0){return new Uint8Array(r)}function fe(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ft(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Rs=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 Ir(r){return!!r?.[Rs]}var rt=class r{bufs;length;[Rs]=!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(Ir(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(Ir(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(Ir(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(!Ir(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 p=f;p>=0;p--){let x=this.get(l+p);if(n[p]!==x){u=Math.max(1,p-a[x]);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=ft(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=Ot(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=Ot(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=Ot(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=ft(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=Ot(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=Ot(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=Ot(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=Ot(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=Ot(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(!gt(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 _n={};mt(_n,{base10:()=>yc});var yc=Wt({prefix:"9",name:"base10",alphabet:"0123456789"});var Tn={};mt(Tn,{base16:()=>bc,base16upper:()=>gc});var bc=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),gc=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Dn={};mt(Dn,{base2:()=>xc});var xc=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Pn={};mt(Pn,{base256emoji:()=>Ac});var Ns=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}"),wc=Ns.reduce((r,t,e)=>(r[e]=t,r),[]),Ec=Ns.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Sc(r){return r.reduce((t,e)=>(t+=wc[e],t),"")}function vc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Ec[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Ac=Be({prefix:"\u{1F680}",name:"base256emoji",encode:Sc,decode:vc});var Cn={};mt(Cn,{base64:()=>Ic,base64pad:()=>Bc,base64url:()=>Lc,base64urlpad:()=>_c});var Ic=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Bc=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Lc=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),_c=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Rn={};mt(Rn,{base8:()=>Tc});var Tc=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Nn={};mt(Nn,{identity:()=>Dc});var Dc=Be({prefix:"\0",name:"identity",encode:r=>xs(r),decode:r=>gs(r)});var ah=new TextEncoder,ch=new TextDecoder;var Un={};mt(Un,{sha256:()=>le,sha512:()=>Rc});function Kn({name:r,code:t,encode:e}){return new kn(r,t,e)}var kn=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?Lt(this.code,e):e.then(n=>Lt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ks(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var le=Kn({name:"sha2-256",code:18,encode:Ks("SHA-256")}),Rc=Kn({name:"sha2-512",code:19,encode:Ks("SHA-512")});var Mn={...Nn,...Dn,...Rn,..._n,...Tn,...vn,...An,...Sn,...Cn,...Pn},wh={...Un,...Ln};function Ms(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Us=Ms("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),On=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=ft(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Nc={utf8:Us,"utf-8":Us,hex:Mn.base16,latin1:On,ascii:On,binary:On,...Mn},Br=Nc;function G(r,t="utf8"){let e=Br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function z(r,t="utf8"){let e=Br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var kc=parseInt("11111",2),qn=parseInt("10000000",2),Kc=parseInt("01111111",2),Os={0:We,1:We,2:Uc,3:qc,4:Hc,5:Oc,6:Mc,16:We,22:We,48:We};function qt(r,t={offset:0}){let e=r[t.offset]&kc;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]&qn)===qn){let n=r[t.offset]&Kc,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 We(r,t){je(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=qt(r,t);if(n===null)break;e.push(n)}return e}function Uc(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 Mc(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 Oc(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 Hc(r,t){let e=je(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Vc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new rt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Hn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Vc(r.byteLength);return new rt(Uint8Array.from([t.byteLength|qn]),t)}function xt(r){let t=new rt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new rt(Uint8Array.from([2]),Hn(t),t)}function Lr(r){let t=Uint8Array.from([0]),e=new rt(t,r);return new rt(Uint8Array.from([3]),Hn(e),e)}function Jt(r,t=48){let e=new rt;for(let n of r)e.append(n);return new rt(Uint8Array.from([t]),Hn(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 zc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Fc=Uint8Array.from([6,5,43,129,4,0,34]),Gc=Uint8Array.from([6,5,43,129,4,0,35]),Zc={ext:!0,kty:"EC",crv:"P-256"},Yc={ext:!0,kty:"EC",crv:"P-384"},$c={ext:!0,kty:"EC",crv:"P-521"},Vn=32,zn=48,Fn=66;function Gn(r){let t=qt(r);return Hs(t)}function Hs(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Vn*2+1)return n=z(t.subarray(e,e+Vn),"base64url"),o=z(t.subarray(e+Vn),"base64url"),new Pe({...Zc,key_ops:["verify"],x:n,y:o});if(t.byteLength===zn*2+1)return n=z(t.subarray(e,e+zn),"base64url"),o=z(t.subarray(e+zn),"base64url"),new Pe({...Yc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Fn*2+1)return n=z(t.subarray(e,e+Fn),"base64url"),o=z(t.subarray(e+Fn),"base64url"),new Pe({...$c,key_ops:["verify"],x:n,y:o});throw new W(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Vs(r){return Jt([xt(Uint8Array.from([1])),Jt([Wc(r.crv)],160),Jt([Lr(new rt(Uint8Array.from([4]),G(r.x??"","base64url"),G(r.y??"","base64url")))],161)]).subarray()}function Wc(r){if(r==="P-256")return zc;if(r==="P-384")return Fc;if(r==="P-521")return Gc;throw new W(`Invalid curve ${r}`)}var Pe=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 _t.digest(Ht(this))}toCID(){return ut.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}async verify(t,e){return qs(this.jwk,e,t)}};function zs(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function jc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ce(r,...t){if(!jc(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 Fs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");zs(r.outputLen),zs(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 Gs(r,t){Ce(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function _r(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Tt(r,t){return r<<32-t|r>>>t}function Zs(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Xe(r){return typeof r=="string"&&(r=Zs(r)),Ce(r),r}function Zn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ce(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{clone(){return this._cloneInto()}};function Tr(r){let t=n=>r().update(Xe(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 he.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Xc(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 Ys(r,t,e){return r&t^~r&e}function $s(r,t,e){return r&t^r&e^t&e}var Ke=class extends Ne{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=_r(this.buffer)}update(t){Re(this);let{view:e,buffer:n,blockLen:o}=this;t=Xe(t);let s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=_r(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),Gs(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;Xc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=_r(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.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var Dr=BigInt(4294967295),Yn=BigInt(32);function Ws(r,t=!1){return t?{h:Number(r&Dr),l:Number(r>>Yn&Dr)}:{h:Number(r>>Yn&Dr)|0,l:Number(r&Dr)|0}}function Jc(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=Ws(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var Qc=(r,t)=>BigInt(r>>>0)<<Yn|BigInt(t>>>0),tu=(r,t,e)=>r>>>e,eu=(r,t,e)=>r<<32-e|t>>>e,ru=(r,t,e)=>r>>>e|t<<32-e,nu=(r,t,e)=>r<<32-e|t>>>e,ou=(r,t,e)=>r<<64-e|t>>>e-32,su=(r,t,e)=>r>>>e-32|t<<64-e,iu=(r,t)=>t,au=(r,t)=>r,cu=(r,t,e)=>r<<e|t>>>32-e,uu=(r,t,e)=>t<<e|r>>>32-e,fu=(r,t,e)=>t<<e-32|r>>>64-e,lu=(r,t,e)=>r<<e-32|t>>>64-e;function hu(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var du=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),pu=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,mu=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),yu=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,bu=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),gu=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var xu={fromBig:Ws,split:Jc,toBig:Qc,shrSH:tu,shrSL:eu,rotrSH:ru,rotrSL:nu,rotrBH:ou,rotrBL:su,rotr32H:iu,rotr32L:au,rotlSH:cu,rotlSL:uu,rotlBH:fu,rotlBL:lu,add:hu,add3L:du,add3H:pu,add4L:mu,add4H:yu,add5H:gu,add5L:bu},k=xu;var[wu,Eu]=k.split(["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))),Qt=new Uint32Array(80),te=new Uint32Array(80),$n=class extends Ke{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}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:p,Gh:x,Gl:E,Hh:b,Hl:h}=this;return[t,e,n,o,s,i,a,c,f,u,l,p,x,E,b,h]}set(t,e,n,o,s,i,a,c,f,u,l,p,x,E,b,h){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=p|0,this.Gh=x|0,this.Gl=E|0,this.Hh=b|0,this.Hl=h|0}process(t,e){for(let m=0;m<16;m++,e+=4)Qt[m]=t.getUint32(e),te[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let I=Qt[m-15]|0,D=te[m-15]|0,P=k.rotrSH(I,D,1)^k.rotrSH(I,D,8)^k.shrSH(I,D,7),B=k.rotrSL(I,D,1)^k.rotrSL(I,D,8)^k.shrSL(I,D,7),T=Qt[m-2]|0,L=te[m-2]|0,Z=k.rotrSH(T,L,19)^k.rotrBH(T,L,61)^k.shrSH(T,L,6),O=k.rotrSL(T,L,19)^k.rotrBL(T,L,61)^k.shrSL(T,L,6),U=k.add4L(B,O,te[m-7],te[m-16]),et=k.add4H(U,P,Z,Qt[m-7],Qt[m-16]);Qt[m]=et|0,te[m]=U|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:p,Fh:x,Fl:E,Gh:b,Gl:h,Hh:g,Hl:S}=this;for(let m=0;m<80;m++){let I=k.rotrSH(l,p,14)^k.rotrSH(l,p,18)^k.rotrBH(l,p,41),D=k.rotrSL(l,p,14)^k.rotrSL(l,p,18)^k.rotrBL(l,p,41),P=l&x^~l&b,B=p&E^~p&h,T=k.add5L(S,D,B,Eu[m],te[m]),L=k.add5H(T,g,I,P,wu[m],Qt[m]),Z=T|0,O=k.rotrSH(n,o,28)^k.rotrBH(n,o,34)^k.rotrBH(n,o,39),U=k.rotrSL(n,o,28)^k.rotrBL(n,o,34)^k.rotrBL(n,o,39),et=n&s^n&a^s&a,v=o&i^o&c^i&c;g=b|0,S=h|0,b=x|0,h=E|0,x=l|0,E=p|0,{h:l,l:p}=k.add(f|0,u|0,L|0,Z|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let _=k.add3L(Z,U,v);n=k.add3H(_,L,O,et),o=_|0}({h:n,l:o}=k.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=k.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=k.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=k.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:p}=k.add(this.Eh|0,this.El|0,l|0,p|0),{h:x,l:E}=k.add(this.Fh|0,this.Fl|0,x|0,E|0),{h:b,l:h}=k.add(this.Gh|0,this.Gl|0,b|0,h|0),{h:g,l:S}=k.add(this.Hh|0,this.Hl|0,g|0,S|0),this.set(n,o,s,i,a,c,f,u,l,p,x,E,b,h,g,S)}roundClean(){Qt.fill(0),te.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var js=Tr(()=>new $n);var Rr={};mt(Rr,{aInRange:()=>wt,abool:()=>Dt,abytes:()=>Ue,bitGet:()=>Lu,bitLen:()=>Jn,bitMask:()=>Qe,bitSet:()=>_u,bytesToHex:()=>zt,bytesToNumberBE:()=>Ft,bytesToNumberLE:()=>re,concatBytes:()=>Gt,createHmacDrbg:()=>Qn,ensureBytes:()=>X,equalBytes:()=>Iu,hexToBytes:()=>pe,hexToNumber:()=>Xn,inRange:()=>Je,isBytes:()=>ee,memoized:()=>ye,notImplemented:()=>Du,numberToBytesBE:()=>ne,numberToBytesLE:()=>me,numberToHexUnpadded:()=>de,numberToVarBytesBE:()=>Au,utf8ToBytes:()=>Bu,validateObject:()=>kt});var Pr=BigInt(0),Cr=BigInt(1),Su=BigInt(2);function ee(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ue(r){if(!ee(r))throw new Error("Uint8Array expected")}function Dt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var vu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function zt(r){Ue(r);let t="";for(let e=0;e<r.length;e++)t+=vu[r[e]];return t}function de(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Xn(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Pr:BigInt("0x"+r)}var Vt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Xs(r){if(r>=Vt._0&&r<=Vt._9)return r-Vt._0;if(r>=Vt.A&&r<=Vt.F)return r-(Vt.A-10);if(r>=Vt.a&&r<=Vt.f)return r-(Vt.a-10)}function pe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof 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=Xs(r.charCodeAt(s)),a=Xs(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 Ft(r){return Xn(zt(r))}function re(r){return Ue(r),Xn(zt(Uint8Array.from(r).reverse()))}function ne(r,t){return pe(r.toString(16).padStart(t*2,"0"))}function me(r,t){return ne(r,t).reverse()}function Au(r){return pe(de(r))}function X(r,t,e){let n;if(typeof t=="string")try{n=pe(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(ee(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function Gt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ue(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}function Iu(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Bu(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Wn=r=>typeof r=="bigint"&&Pr<=r;function Je(r,t,e){return Wn(r)&&Wn(t)&&Wn(e)&&t<=r&&r<e}function wt(r,t,e,n){if(!Je(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Jn(r){let t;for(t=0;r>Pr;r>>=Cr,t+=1);return t}function Lu(r,t){return r>>BigInt(t)&Cr}function _u(r,t,e){return r|(e?Cr:Pr)<<BigInt(t)}var Qe=r=>(Su<<BigInt(r-1))-Cr,jn=r=>new Uint8Array(r),Js=r=>Uint8Array.from(r);function Qn(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=jn(r),o=jn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...l)=>e(o,n,...l),c=(l=jn())=>{o=a(Js([0]),l),n=a(),l.length!==0&&(o=a(Js([1]),l),n=a())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,p=[];for(;l<t;){n=a();let x=n.slice();p.push(x),l+=n.length}return Gt(...p)};return(l,p)=>{i(),c(l);let x;for(;!(x=p(f()));)c();return i(),x}}var Tu={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"||ee(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 kt(r,t,e={}){let n=(o,s,i)=>{let a=Tu[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}var Du=()=>{throw new Error("not implemented")};function ye(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 nt=BigInt(0),Y=BigInt(1),be=BigInt(2),Pu=BigInt(3),to=BigInt(4),Qs=BigInt(5),ti=BigInt(8),Cu=BigInt(9),Ru=BigInt(16);function V(r,t){let e=r%t;return e>=nt?e:t+e}function Nu(r,t,e){if(t<nt)throw new Error("invalid exponent, negatives unsupported");if(e<=nt)throw new Error("invalid modulus");if(e===Y)return nt;let n=Y;for(;t>nt;)t&Y&&(n=n*r%e),r=r*r%e,t>>=Y;return n}function $(r,t,e){let n=r;for(;t-- >nt;)n*=n,n%=e;return n}function Nr(r,t){if(r===nt)throw new Error("invert: expected non-zero number");if(t<=nt)throw new Error("invert: expected positive modulus, got "+t);let e=V(r,t),n=t,o=nt,s=Y,i=Y,a=nt;for(;e!==nt;){let f=n/e,u=n%e,l=o-i*f,p=s-a*f;n=e,e=u,o=i,s=a,i=l,a=p}if(n!==Y)throw new Error("invert: does not exist");return V(o,t)}function ku(r){let t=(r-Y)/be,e,n,o;for(e=r-Y,n=0;e%be===nt;e/=be,n++);for(o=be;o<r&&Nu(o,t,r)!==r-Y;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+Y)/to;return function(c,f){let u=c.pow(f,i);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let s=(e+Y)/be;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,o),e),l=a.pow(c,s),p=a.pow(c,e);for(;!a.eql(p,a.ONE);){if(a.eql(p,a.ZERO))return a.ZERO;let x=1;for(let b=a.sqr(p);x<f&&!a.eql(b,a.ONE);x++)b=a.sqr(b);let E=a.pow(u,Y<<BigInt(f-x-1));u=a.sqr(E),l=a.mul(l,E),p=a.mul(p,u),f=x}return l}}function Ku(r){if(r%to===Pu){let t=(r+Y)/to;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%ti===Qs){let t=(r-Qs)/ti;return function(n,o){let s=n.mul(o,be),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,be),i),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return r%Ru,ku(r)}var ei=(r,t)=>(V(r,t)&Y)===Y,Uu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function eo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Uu.reduce((n,o)=>(n[o]="function",n),t);return kt(r,e)}function Mu(r,t,e){if(e<nt)throw new Error("invalid exponent, negatives unsupported");if(e===nt)return r.ONE;if(e===Y)return t;let n=r.ONE,o=t;for(;e>nt;)e&Y&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Y;return n}function Ou(r,t){let e=new Array(t.length),n=t.reduce((s,i,a)=>r.is0(i)?s:(e[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,a)=>r.is0(i)?s:(e[a]=r.mul(s,e[a]),r.mul(s,i)),o),e}function ro(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function oe(r,t,e=!1,n={}){if(r<=nt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=ro(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:Qe(o),ZERO:nt,ONE:Y,create:c=>V(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return nt<=c&&c<r},is0:c=>c===nt,isOdd:c=>(c&Y)===Y,neg:c=>V(-c,r),eql:(c,f)=>c===f,sqr:c=>V(c*c,r),add:(c,f)=>V(c+f,r),sub:(c,f)=>V(c-f,r),mul:(c,f)=>V(c*f,r),pow:(c,f)=>Mu(a,c,f),div:(c,f)=>V(c*Nr(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Nr(c,r),sqrt:n.sqrt||(c=>(i||(i=Ku(r)),i(a,c))),invertBatch:c=>Ou(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>e?me(c,s):ne(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?re(c):Ft(c)}});return Object.freeze(a)}function ri(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 no(r){let t=ri(r);return t+Math.ceil(t/2)}function ni(r,t,e=!1){let n=r.length,o=ri(t),s=no(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?re(r):Ft(r),a=V(i,t-Y)+Y;return e?me(a,o):ne(a,o)}var oi=BigInt(0),kr=BigInt(1);function oo(r,t){let e=t.negate();return r?e:t}function si(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function so(r,t){si(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function qu(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 Hu(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 io=new WeakMap,ii=new WeakMap;function ao(r){return ii.get(r)||1}function Kr(r,t){return{constTimeNegate:oo,hasPrecomputes(e){return ao(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>oi;)n&kr&&(o=o.add(s)),s=s.double(),n>>=kr;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=so(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{windows:s,windowSize:i}=so(e,t),a=r.ZERO,c=r.BASE,f=BigInt(2**e-1),u=2**e,l=BigInt(e);for(let p=0;p<s;p++){let x=p*i,E=Number(o&f);o>>=l,E>i&&(E-=u,o+=kr);let b=x,h=x+Math.abs(E)-1,g=p%2!==0,S=E<0;E===0?c=c.add(oo(g,n[b])):a=a.add(oo(S,n[h]))}return{p:a,f:c}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:a}=so(e,t),c=BigInt(2**e-1),f=2**e,u=BigInt(e);for(let l=0;l<i;l++){let p=l*a;if(o===oi)break;let x=Number(o&c);if(o>>=u,x>a&&(x-=f,o+=kr),x===0)continue;let E=n[p+Math.abs(x)-1];x<0&&(E=E.negate()),s=s.add(E)}return s},getPrecomputes(e,n,o){let s=io.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&io.set(n,o(s))),s},wNAFCached(e,n,o){let s=ao(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=ao(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){si(n,t),ii.set(e,n),io.delete(e)}}}function Ur(r,t,e,n){if(qu(e,r),Hu(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=Jn(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=(1<<i)-1,c=new Array(a+1).fill(o),f=Math.floor((t.BITS-1)/i)*i,u=o;for(let l=f;l>=0;l-=i){c.fill(o);for(let x=0;x<n.length;x++){let E=n[x],b=Number(E>>BigInt(l)&BigInt(a));c[b]=c[b].add(e[x])}let p=o;for(let x=c.length-1,E=o;x>0;x--)E=E.add(c[x]),p=p.add(E);if(u=u.add(p),l!==0)for(let x=0;x<i;x++)u=u.double()}return u}function tr(r){return eo(r.Fp),kt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ro(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Pt=BigInt(0),Et=BigInt(1),Mr=BigInt(2),Vu=BigInt(8),zu={zip215:!0};function Fu(r){let t=tr(r);return kt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function ai(r){let t=Fu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,f=Mr<<BigInt(a*8)-Et,u=e.create,l=oe(t.n,t.nBitLength),p=t.uvRatio||((y,d)=>{try{return{isValid:!0,value:e.sqrt(y*e.inv(d))}}catch{return{isValid:!1,value:Pt}}}),x=t.adjustScalarBytes||(y=>y),E=t.domain||((y,d,w)=>{if(Dt("phflag",w),d.length||w)throw new Error("Contexts/pre-hash are not supported");return y});function b(y,d){wt("coordinate "+y,d,Pt,f)}function h(y){if(!(y instanceof m))throw new Error("ExtendedPoint expected")}let g=ye((y,d)=>{let{ex:w,ey:A,ez:C}=y,R=y.is0();d==null&&(d=R?Vu:e.inv(C));let K=u(w*d),M=u(A*d),N=u(C*d);if(R)return{x:Pt,y:Et};if(N!==Et)throw new Error("invZ was invalid");return{x:K,y:M}}),S=ye(y=>{let{a:d,d:w}=t;if(y.is0())throw new Error("bad point: ZERO");let{ex:A,ey:C,ez:R,et:K}=y,M=u(A*A),N=u(C*C),H=u(R*R),F=u(H*H),ot=u(M*d),st=u(H*u(ot+N)),at=u(F+u(w*u(M*N)));if(st!==at)throw new Error("bad point: equation left != right (1)");let ct=u(A*C),bt=u(R*K);if(ct!==bt)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(d,w,A,C){this.ex=d,this.ey=w,this.ez=A,this.et=C,b("x",d),b("y",w),b("z",A),b("t",C),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof m)throw new Error("extended point not allowed");let{x:w,y:A}=d||{};return b("x",w),b("y",A),new m(w,A,Et,u(w*A))}static normalizeZ(d){let w=e.invertBatch(d.map(A=>A.ez));return d.map((A,C)=>A.toAffine(w[C])).map(m.fromAffine)}static msm(d,w){return Ur(m,l,d,w)}_setWindowSize(d){P.setWindowSize(this,d)}assertValidity(){S(this)}equals(d){h(d);let{ex:w,ey:A,ez:C}=this,{ex:R,ey:K,ez:M}=d,N=u(w*M),H=u(R*C),F=u(A*M),ot=u(K*C);return N===H&&F===ot}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:d}=t,{ex:w,ey:A,ez:C}=this,R=u(w*w),K=u(A*A),M=u(Mr*u(C*C)),N=u(d*R),H=w+A,F=u(u(H*H)-R-K),ot=N+K,st=ot-M,at=N-K,ct=u(F*st),bt=u(ot*at),pt=u(F*at),Nt=u(st*ot);return new m(ct,bt,Nt,pt)}add(d){h(d);let{a:w,d:A}=t,{ex:C,ey:R,ez:K,et:M}=this,{ex:N,ey:H,ez:F,et:ot}=d;if(w===BigInt(-1)){let is=u((R-C)*(H+N)),as=u((R+C)*(H-N)),yn=u(as-is);if(yn===Pt)return this.double();let cs=u(K*Mr*ot),us=u(M*Mr*F),fs=us+cs,ls=as+is,hs=us-cs,ga=u(fs*yn),xa=u(ls*hs),wa=u(fs*hs),Ea=u(yn*ls);return new m(ga,xa,Ea,wa)}let st=u(C*N),at=u(R*H),ct=u(M*A*ot),bt=u(K*F),pt=u((C+R)*(N+H)-st-at),Nt=bt-ct,Ut=bt+ct,ze=u(at-w*st),pa=u(pt*Nt),ma=u(Ut*ze),ya=u(pt*ze),ba=u(Nt*Ut);return new m(pa,ma,ba,ya)}subtract(d){return this.add(d.negate())}wNAF(d){return P.wNAFCached(this,d,m.normalizeZ)}multiply(d){let w=d;wt("scalar",w,Et,n);let{p:A,f:C}=this.wNAF(w);return m.normalizeZ([A,C])[0]}multiplyUnsafe(d,w=m.ZERO){let A=d;return wt("scalar",A,Pt,n),A===Pt?D:this.is0()||A===Et?this:P.wNAFCachedUnsafe(this,A,m.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return P.unsafeLadder(this,n).is0()}toAffine(d){return g(this,d)}clearCofactor(){let{h:d}=t;return d===Et?this:this.multiplyUnsafe(d)}static fromHex(d,w=!1){let{d:A,a:C}=t,R=e.BYTES;d=X("pointHex",d,R),Dt("zip215",w);let K=d.slice(),M=d[R-1];K[R-1]=M&-129;let N=re(K),H=w?f:e.ORDER;wt("pointHex.y",N,Pt,H);let F=u(N*N),ot=u(F-Et),st=u(A*F-C),{isValid:at,value:ct}=p(ot,st);if(!at)throw new Error("Point.fromHex: invalid y coordinate");let bt=(ct&Et)===Et,pt=(M&128)!==0;if(!w&&ct===Pt&&pt)throw new Error("Point.fromHex: x=0 and x_0=1");return pt!==bt&&(ct=u(-ct)),m.fromAffine({x:ct,y:N})}static fromPrivateKey(d){return L(d).point}toRawBytes(){let{x:d,y:w}=this.toAffine(),A=me(w,e.BYTES);return A[A.length-1]|=d&Et?128:0,A}toHex(){return zt(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,Et,u(t.Gx*t.Gy)),m.ZERO=new m(Pt,Et,Et,Pt);let{BASE:I,ZERO:D}=m,P=Kr(m,a*8);function B(y){return V(y,n)}function T(y){return B(re(y))}function L(y){let d=e.BYTES;y=X("private key",y,d);let w=X("hashed private key",s(y),2*d),A=x(w.slice(0,d)),C=w.slice(d,2*d),R=T(A),K=I.multiply(R),M=K.toRawBytes();return{head:A,prefix:C,scalar:R,point:K,pointBytes:M}}function Z(y){return L(y).pointBytes}function O(y=new Uint8Array,...d){let w=Gt(...d);return T(s(E(w,X("context",y),!!o)))}function U(y,d,w={}){y=X("message",y),o&&(y=o(y));let{prefix:A,scalar:C,pointBytes:R}=L(d),K=O(w.context,A,y),M=I.multiply(K).toRawBytes(),N=O(w.context,M,R,y),H=B(K+N*C);wt("signature.s",H,Pt,n);let F=Gt(M,me(H,e.BYTES));return X("result",F,e.BYTES*2)}let et=zu;function v(y,d,w,A=et){let{context:C,zip215:R}=A,K=e.BYTES;y=X("signature",y,2*K),d=X("message",d),w=X("publicKey",w,K),R!==void 0&&Dt("zip215",R),o&&(d=o(d));let M=re(y.slice(K,2*K)),N,H,F;try{N=m.fromHex(w,R),H=m.fromHex(y.slice(0,K),R),F=I.multiplyUnsafe(M)}catch{return!1}if(!R&&N.isSmallOrder())return!1;let ot=O(C,H.toRawBytes(),N.toRawBytes(),d);return H.add(N.multiplyUnsafe(ot)).subtract(F).clearCofactor().equals(m.ZERO)}return I._setWindowSize(8),{CURVE:t,getPublicKey:Z,sign:U,verify:v,ExtendedPoint:m,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>i(e.BYTES),precompute(y=8,d=m.BASE){return d._setWindowSize(y),d.multiply(BigInt(3)),d}}}}var co=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ci=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Ad=BigInt(0),Gu=BigInt(1),ui=BigInt(2),Id=BigInt(3),Zu=BigInt(5),Yu=BigInt(8);function $u(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=co,a=r*r%s*r%s,c=$(a,ui,s)*a%s,f=$(c,Gu,s)*r%s,u=$(f,Zu,s)*f%s,l=$(u,t,s)*u%s,p=$(l,e,s)*l%s,x=$(p,n,s)*p%s,E=$(x,o,s)*x%s,b=$(E,o,s)*x%s,h=$(b,t,s)*u%s;return{pow_p_5_8:$(h,ui,s)*r%s,b2:a}}function Wu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function ju(r,t){let e=co,n=V(t*t*t,e),o=V(n*n*t,e),s=$u(r*o).pow_p_5_8,i=V(r*n*s,e),a=V(t*i*i,e),c=i,f=V(i*ci,e),u=a===r,l=a===V(-r,e),p=a===V(-r*ci,e);return u&&(i=c),(l||p)&&(i=f),ei(i,e)&&(i=V(-i,e)),{isValid:u||l,value:i}}var Xu=oe(co,void 0,!0),Ju={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Xu,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Yu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:js,randomBytes:ke,adjustScalarBytes:Wu,uvRatio:ju},fi=ai(Ju);var Or=32;function li(r,t,e){return fi.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var qr=class{type="Ed25519";raw;constructor(t){this.raw=uo(t,Or)}toMultihash(){return _t.digest(Ht(this))}toCID(){return ut.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,e){return li(this.raw,e,t)}};function fo(r){return r=uo(r,Or),new qr(r)}function uo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new W(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var tf=Math.pow(2,7),ef=Math.pow(2,14),rf=Math.pow(2,21),lo=Math.pow(2,28),ho=Math.pow(2,35),po=Math.pow(2,42),mo=Math.pow(2,49),q=128,lt=127;function Ct(r){if(r<tf)return 1;if(r<ef)return 2;if(r<rf)return 3;if(r<lo)return 4;if(r<ho)return 5;if(r<po)return 6;if(r<mo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function yo(r,t,e=0){switch(Ct(r)){case 8:t[e++]=r&255|q,r/=128;case 7:t[e++]=r&255|q,r/=128;case 6:t[e++]=r&255|q,r/=128;case 5:t[e++]=r&255|q,r/=128;case 4:t[e++]=r&255|q,r>>>=7;case 3:t[e++]=r&255|q,r>>>=7;case 2:t[e++]=r&255|q,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function nf(r,t,e=0){switch(Ct(r)){case 8:t.set(e++,r&255|q),r/=128;case 7:t.set(e++,r&255|q),r/=128;case 6:t.set(e++,r&255|q),r/=128;case 5:t.set(e++,r&255|q),r/=128;case 4:t.set(e++,r&255|q),r>>>=7;case 3:t.set(e++,r&255|q),r>>>=7;case 2:t.set(e++,r&255|q),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function bo(r,t){let e=r[t],n=0;if(n+=e<,e<q||(e=r[t+1],n+=(e<)<<7,e<q)||(e=r[t+2],n+=(e<)<<14,e<q)||(e=r[t+3],n+=(e<)<<21,e<q)||(e=r[t+4],n+=(e<)*lo,e<q)||(e=r[t+5],n+=(e<)*ho,e<q)||(e=r[t+6],n+=(e<)*po,e<q)||(e=r[t+7],n+=(e<)*mo,e<q))return n;throw new RangeError("Could not decode varint")}function of(r,t){let e=r.get(t),n=0;if(n+=e<,e<q||(e=r.get(t+1),n+=(e<)<<7,e<q)||(e=r.get(t+2),n+=(e<)<<14,e<q)||(e=r.get(t+3),n+=(e<)<<21,e<q)||(e=r.get(t+4),n+=(e<)*lo,e<q)||(e=r.get(t+5),n+=(e<)*ho,e<q)||(e=r.get(t+6),n+=(e<)*po,e<q)||(e=r.get(t+7),n+=(e<)*mo,e<q))return n;throw new RangeError("Could not decode varint")}function di(r,t,e=0){return t==null&&(t=ft(Ct(r))),t instanceof Uint8Array?yo(r,t,e):nf(r,t,e)}function pi(r,t=0){return r instanceof Uint8Array?bo(r,t):of(r,t)}var go=new Float32Array([-0]),se=new Uint8Array(go.buffer);function yi(r,t,e){go[0]=r,t[e]=se[0],t[e+1]=se[1],t[e+2]=se[2],t[e+3]=se[3]}function bi(r,t){return se[0]=r[t],se[1]=r[t+1],se[2]=r[t+2],se[3]=r[t+3],go[0]}var xo=new Float64Array([-0]),ht=new Uint8Array(xo.buffer);function gi(r,t,e){xo[0]=r,t[e]=ht[0],t[e+1]=ht[1],t[e+2]=ht[2],t[e+3]=ht[3],t[e+4]=ht[4],t[e+5]=ht[5],t[e+6]=ht[6],t[e+7]=ht[7]}function xi(r,t){return ht[0]=r[t],ht[1]=r[t+1],ht[2]=r[t+2],ht[3]=r[t+3],ht[4]=r[t+4],ht[5]=r[t+5],ht[6]=r[t+6],ht[7]=r[t+7],xo[0]}var sf=BigInt(Number.MAX_SAFE_INTEGER),af=BigInt(Number.MIN_SAFE_INTEGER),It=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 ge;if(t<sf&&t>af)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>wi&&(o=0n,++n>wi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;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):ge}},ge=new It(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var wi=4294967296n;function Ei(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 Si(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 wo(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 Hr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Eo=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 Hr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Rt(this,4);return Hr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Rt(this,4);let t=bi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Rt(this,4);let t=xi(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 Si(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 It(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=Hr(this.buf,this.pos+=4),e=Hr(this.buf,this.pos+=4);return new It(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=bo(this.buf,this.pos);return this.pos+=Ct(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function So(r){return new Eo(r instanceof Uint8Array?r:r.subarray())}function St(r,t,e){let n=So(r);return t.decode(n,void 0,e)}function vo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ft(i);o+i>t&&(n=ft(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var xe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Ao(){}var Bo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},cf=vo();function uf(r){return globalThis.Buffer!=null?ft(r):cf(r)}var rr=class{len;head;tail;states;constructor(){this.len=0,this.head=new xe(Ao,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new xe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Lo((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(Vr,10,It.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=It.fromBigInt(t);return this._push(Vr,e.length(),e)}uint64Number(t){return this._push(yo,Ct(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=It.fromBigInt(t).zzEncode();return this._push(Vr,e.length(),e)}sint64Number(t){let e=It.fromNumber(t).zzEncode();return this._push(Vr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Io,1,t?1:0)}fixed32(t){return this._push(er,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=It.fromBigInt(t);return this._push(er,4,e.lo)._push(er,4,e.hi)}fixed64Number(t){let e=It.fromNumber(t);return this._push(er,4,e.lo)._push(er,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(yi,4,t)}double(t){return this._push(gi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Io,1,0):this.uint32(e)._push(lf,e,t)}string(t){let e=Ei(t);return e!==0?this.uint32(e)._push(wo,e,t):this._push(Io,1,0)}fork(){return this.states=new Bo(this),this.head=this.tail=new xe(Ao,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new xe(Ao,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=uf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Io(r,t,e){t[e]=r&255}function ff(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Lo=class extends xe{next;constructor(t,e){super(ff,t,e),this.next=void 0}};function Vr(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 er(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 lf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(rr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(hf,t,r),this},rr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(df,t,r),this});function hf(r,t,e){t.set(r,e)}function df(r,t,e){r.length<40?wo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(G(r),e)}function _o(){return new rr}function vt(r,t){let e=_o();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Me;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Me||(Me={}));function zr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function To(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",Me.VARINT,e,n)}function At(r,t){return zr("message",Me.LENGTH_DELIMITED,r,t)}var Bt=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 Do;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Do||(Do={}));(function(r){r.codec=()=>To(Do)})(tt||(tt={}));var Kt;(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)})(Kt||(Kt={}));var Po;(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)})(Po||(Po={}));function Fr(r){if(isNaN(r)||r<=0)throw new W("random bytes length must be a Number bigger than 0");return ke(r)}var nr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Gr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ii={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Gr("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 ie=Ii;var sr={};mt(sr,{MAX_RSA_KEY_SIZE:()=>Ro,generateRSAKeyPair:()=>Ti,jwkToJWKKeyPair:()=>Di,jwkToPkcs1:()=>gf,jwkToPkix:()=>Uo,jwkToRSAPrivateKey:()=>Ho,pkcs1MessageToJwk:()=>ko,pkcs1MessageToRSAPrivateKey:()=>Mo,pkcs1ToJwk:()=>bf,pkcs1ToRSAPrivateKey:()=>_i,pkixMessageToJwk:()=>Ko,pkixMessageToRSAPublicKey:()=>qo,pkixToJwk:()=>xf,pkixToRSAPublicKey:()=>Oo});var pf=new Uint32Array([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]),ae=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ce=new Uint32Array(64),Co=class extends Ke{constructor(){super(64,32,8,!1),this.A=ae[0]|0,this.B=ae[1]|0,this.C=ae[2]|0,this.D=ae[3]|0,this.E=ae[4]|0,this.F=ae[5]|0,this.G=ae[6]|0,this.H=ae[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)ce[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let p=ce[l-15],x=ce[l-2],E=Tt(p,7)^Tt(p,18)^p>>>3,b=Tt(x,17)^Tt(x,19)^x>>>10;ce[l]=b+ce[l-7]+E+ce[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 p=Tt(a,6)^Tt(a,11)^Tt(a,25),x=u+p+Ys(a,c,f)+pf[l]+ce[l]|0,b=(Tt(n,2)^Tt(n,13)^Tt(n,22))+$s(n,o,s)|0;u=f,f=c,c=a,a=i+x|0,i=s,s=o,o=n,n=x+b|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(){ce.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Oe=Tr(()=>new Co);var qe=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=sr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ut.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,e){return Li(this.jwk,e,t)}},or=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=sr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}sign(t){return Bi(this.jwk,t)}};var Ro=8192,No=18,mf=1062,yf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function bf(r){let t=qt(r);return ko(t)}function ko(r){return{n:z(r[1],"base64url"),e:z(r[2],"base64url"),d:z(r[3],"base64url"),p:z(r[4],"base64url"),q:z(r[5],"base64url"),dp:z(r[6],"base64url"),dq:z(r[7],"base64url"),qi:z(r[8],"base64url"),kty:"RSA"}}function gf(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 W("JWK was missing components");return Jt([xt(Uint8Array.from([0])),xt(G(r.n,"base64url")),xt(G(r.e,"base64url")),xt(G(r.d,"base64url")),xt(G(r.p,"base64url")),xt(G(r.q,"base64url")),xt(G(r.dp,"base64url")),xt(G(r.dq,"base64url")),xt(G(r.qi,"base64url"))]).subarray()}function xf(r){let t=qt(r,{offset:0});return Ko(t)}function Ko(r){let t=qt(r[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function Uo(r){if(r.n==null||r.e==null)throw new W("JWK was missing components");return Jt([yf,Lr(Jt([xt(G(r.n,"base64url")),xt(G(r.e,"base64url"))]))]).subarray()}function _i(r){let t=qt(r);return Mo(t)}function Mo(r){let t=ko(r);return Ho(t)}function Oo(r,t){if(r.byteLength>=mf)throw new Ae("Key size is too large");let e=qt(r,{offset:0});return qo(e,r,t)}function qo(r,t,e){let n=Ko(r);if(e==null){let o=Oe(Kt.encode({Type:tt.RSA,Data:t}));e=Lt(No,o)}return new qe(n,e)}function Ho(r){if(Ci(r)>Ro)throw new W("Key size is too large");let t=Di(r),e=Oe(Kt.encode({Type:tt.RSA,Data:Uo(t.publicKey)})),n=Lt(No,e);return new or(t.privateKey,new qe(t.publicKey,n))}async function Ti(r){if(r>Ro)throw new W("Key size is too large");let t=await Pi(r),e=Oe(Kt.encode({Type:tt.RSA,Data:Uo(t.publicKey)})),n=Lt(No,e);return new or(t.privateKey,new qe(t.publicKey,n))}function Di(r){if(r==null)throw new W("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Pi(r){let t=await ie.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 wf(t);return{privateKey:e[0],publicKey:e[1]}}async function Bi(r,t){let e=await ie.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await ie.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Li(r,t,e){let n=await ie.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return ie.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function wf(r){if(r.privateKey==null||r.publicKey==null)throw new W("Private and public key are required");return Promise.all([ie.get().subtle.exportKey("jwk",r.privateKey),ie.get().subtle.exportKey("jwk",r.publicKey)])}function Ci(r){if(r.kty!=="RSA")throw new W("invalid key type");if(r.n==null)throw new W("invalid key modulus");return G(r.n,"base64url").length*8}var Zr=class extends Ne{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Fs(t);let n=Xe(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),s.fill(0)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(this),Ce(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}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Vo=(r,t,e)=>new Zr(r,t).update(e).digest();Vo.create=(r,t)=>new Zr(r,t);function Ri(r){r.lowS!==void 0&&Dt("lowS",r.lowS),r.prehash!==void 0&&Dt("prehash",r.prehash)}function Ef(r){let t=tr(r);kt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Sf,hexToBytes:vf}=Rr,zo=class extends Error{constructor(t=""){super(t)}},Zt={Err:zo,_tlv:{encode:(r,t)=>{let{Err:e}=Zt;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=de(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?de(o.length/2|128):"";return de(r)+s+o+t},decode(r,t){let{Err:e}=Zt,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}=Zt;if(r<Yt)throw new t("integer: negative integers are not allowed");let e=de(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}=Zt;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 Sf(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Zt,o=typeof r=="string"?vf(r):r;Ue(o);let{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}=Zt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Yt=BigInt(0),it=BigInt(1),n0=BigInt(2),Ni=BigInt(3),o0=BigInt(4);function Af(r){let t=Ef(r),{Fp:e}=t,n=oe(t.n,t.nBitLength),o=t.toBytes||((b,h,g)=>{let S=h.toAffine();return Gt(Uint8Array.from([4]),e.toBytes(S.x),e.toBytes(S.y))}),s=t.fromBytes||(b=>{let h=b.subarray(1),g=e.fromBytes(h.subarray(0,e.BYTES)),S=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:g,y:S}});function i(b){let{a:h,b:g}=t,S=e.sqr(b),m=e.mul(S,b);return e.add(e.add(m,e.mul(b,h)),g)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(b){return Je(b,it,t.n)}function c(b){let{allowedPrivateKeyLengths:h,nByteLength:g,wrapPrivateKey:S,n:m}=t;if(h&&typeof b!="bigint"){if(ee(b)&&(b=zt(b)),typeof b!="string"||!h.includes(b.length))throw new Error("invalid private key");b=b.padStart(g*2,"0")}let I;try{I=typeof b=="bigint"?b:Ft(X("private key",b,g))}catch{throw new Error("invalid private key, expected hex or "+g+" bytes, got "+typeof b)}return S&&(I=V(I,m)),wt("private key",I,it,m),I}function f(b){if(!(b instanceof p))throw new Error("ProjectivePoint expected")}let u=ye((b,h)=>{let{px:g,py:S,pz:m}=b;if(e.eql(m,e.ONE))return{x:g,y:S};let I=b.is0();h==null&&(h=I?e.ONE:e.inv(m));let D=e.mul(g,h),P=e.mul(S,h),B=e.mul(m,h);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(B,e.ONE))throw new Error("invZ was invalid");return{x:D,y:P}}),l=ye(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:h,y:g}=b.toAffine();if(!e.isValid(h)||!e.isValid(g))throw new Error("bad point: x or y not FE");let S=e.sqr(g),m=i(h);if(!e.eql(S,m))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class p{constructor(h,g,S){if(this.px=h,this.py=g,this.pz=S,h==null||!e.isValid(h))throw new Error("x required");if(g==null||!e.isValid(g))throw new Error("y required");if(S==null||!e.isValid(S))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:g,y:S}=h||{};if(!h||!e.isValid(g)||!e.isValid(S))throw new Error("invalid affine point");if(h instanceof p)throw new Error("projective point not allowed");let m=I=>e.eql(I,e.ZERO);return m(g)&&m(S)?p.ZERO:new p(g,S,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let g=e.invertBatch(h.map(S=>S.pz));return h.map((S,m)=>S.toAffine(g[m])).map(p.fromAffine)}static fromHex(h){let g=p.fromAffine(s(X("pointHex",h)));return g.assertValidity(),g}static fromPrivateKey(h){return p.BASE.multiply(c(h))}static msm(h,g){return Ur(p,n,h,g)}_setWindowSize(h){E.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);let{px:g,py:S,pz:m}=this,{px:I,py:D,pz:P}=h,B=e.eql(e.mul(g,P),e.mul(I,m)),T=e.eql(e.mul(S,P),e.mul(D,m));return B&&T}negate(){return new p(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:g}=t,S=e.mul(g,Ni),{px:m,py:I,pz:D}=this,P=e.ZERO,B=e.ZERO,T=e.ZERO,L=e.mul(m,m),Z=e.mul(I,I),O=e.mul(D,D),U=e.mul(m,I);return U=e.add(U,U),T=e.mul(m,D),T=e.add(T,T),P=e.mul(h,T),B=e.mul(S,O),B=e.add(P,B),P=e.sub(Z,B),B=e.add(Z,B),B=e.mul(P,B),P=e.mul(U,P),T=e.mul(S,T),O=e.mul(h,O),U=e.sub(L,O),U=e.mul(h,U),U=e.add(U,T),T=e.add(L,L),L=e.add(T,L),L=e.add(L,O),L=e.mul(L,U),B=e.add(B,L),O=e.mul(I,D),O=e.add(O,O),L=e.mul(O,U),P=e.sub(P,L),T=e.mul(O,Z),T=e.add(T,T),T=e.add(T,T),new p(P,B,T)}add(h){f(h);let{px:g,py:S,pz:m}=this,{px:I,py:D,pz:P}=h,B=e.ZERO,T=e.ZERO,L=e.ZERO,Z=t.a,O=e.mul(t.b,Ni),U=e.mul(g,I),et=e.mul(S,D),v=e.mul(m,P),_=e.add(g,S),y=e.add(I,D);_=e.mul(_,y),y=e.add(U,et),_=e.sub(_,y),y=e.add(g,m);let d=e.add(I,P);return y=e.mul(y,d),d=e.add(U,v),y=e.sub(y,d),d=e.add(S,m),B=e.add(D,P),d=e.mul(d,B),B=e.add(et,v),d=e.sub(d,B),L=e.mul(Z,y),B=e.mul(O,v),L=e.add(B,L),B=e.sub(et,L),L=e.add(et,L),T=e.mul(B,L),et=e.add(U,U),et=e.add(et,U),v=e.mul(Z,v),y=e.mul(O,y),et=e.add(et,v),v=e.sub(U,v),v=e.mul(Z,v),y=e.add(y,v),U=e.mul(et,y),T=e.add(T,U),U=e.mul(d,y),B=e.mul(_,B),B=e.sub(B,U),U=e.mul(_,et),L=e.mul(d,L),L=e.add(L,U),new p(B,T,L)}subtract(h){return this.add(h.negate())}is0(){return this.equals(p.ZERO)}wNAF(h){return E.wNAFCached(this,h,p.normalizeZ)}multiplyUnsafe(h){let{endo:g,n:S}=t;wt("scalar",h,Yt,S);let m=p.ZERO;if(h===Yt)return m;if(this.is0()||h===it)return this;if(!g||E.hasPrecomputes(this))return E.wNAFCachedUnsafe(this,h,p.normalizeZ);let{k1neg:I,k1:D,k2neg:P,k2:B}=g.splitScalar(h),T=m,L=m,Z=this;for(;D>Yt||B>Yt;)D&it&&(T=T.add(Z)),B&it&&(L=L.add(Z)),Z=Z.double(),D>>=it,B>>=it;return I&&(T=T.negate()),P&&(L=L.negate()),L=new p(e.mul(L.px,g.beta),L.py,L.pz),T.add(L)}multiply(h){let{endo:g,n:S}=t;wt("scalar",h,it,S);let m,I;if(g){let{k1neg:D,k1:P,k2neg:B,k2:T}=g.splitScalar(h),{p:L,f:Z}=this.wNAF(P),{p:O,f:U}=this.wNAF(T);L=E.constTimeNegate(D,L),O=E.constTimeNegate(B,O),O=new p(e.mul(O.px,g.beta),O.py,O.pz),m=L.add(O),I=Z.add(U)}else{let{p:D,f:P}=this.wNAF(h);m=D,I=P}return p.normalizeZ([m,I])[0]}multiplyAndAddUnsafe(h,g,S){let m=p.BASE,I=(P,B)=>B===Yt||B===it||!P.equals(m)?P.multiplyUnsafe(B):P.multiply(B),D=I(this,g).add(I(h,S));return D.is0()?void 0:D}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:g}=t;if(h===it)return!0;if(g)return g(p,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:g}=t;return h===it?this:g?g(p,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Dt("isCompressed",h),this.assertValidity(),o(p,this,h)}toHex(h=!0){return Dt("isCompressed",h),zt(this.toRawBytes(h))}}p.BASE=new p(t.Gx,t.Gy,e.ONE),p.ZERO=new p(e.ZERO,e.ONE,e.ZERO);let x=t.nBitLength,E=Kr(p,t.endo?Math.ceil(x/2):x);return{CURVE:t,ProjectivePoint:p,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function If(r){let t=tr(r);return kt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ki(r){let t=If(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(v){return V(v,n)}function a(v){return Nr(v,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=Af({...t,toBytes(v,_,y){let d=_.toAffine(),w=e.toBytes(d.x),A=Gt;return Dt("isCompressed",y),y?A(Uint8Array.from([_.hasEvenY()?2:3]),w):A(Uint8Array.from([4]),w,e.toBytes(d.y))},fromBytes(v){let _=v.length,y=v[0],d=v.subarray(1);if(_===o&&(y===2||y===3)){let w=Ft(d);if(!Je(w,it,e.ORDER))throw new Error("Point is not on curve");let A=u(w),C;try{C=e.sqrt(A)}catch(M){let N=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+N)}let R=(C&it)===it;return(y&1)===1!==R&&(C=e.neg(C)),{x:w,y:C}}else if(_===s&&y===4){let w=e.fromBytes(d.subarray(0,e.BYTES)),A=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:w,y:A}}else{let w=o,A=s;throw new Error("invalid Point, expected length of "+w+", or uncompressed "+A+", got "+_)}}}),p=v=>zt(ne(v,t.nByteLength));function x(v){let _=n>>it;return v>_}function E(v){return x(v)?i(-v):v}let b=(v,_,y)=>Ft(v.slice(_,y));class h{constructor(_,y,d){this.r=_,this.s=y,this.recovery=d,this.assertValidity()}static fromCompact(_){let y=t.nByteLength;return _=X("compactSignature",_,y*2),new h(b(_,0,y),b(_,y,2*y))}static fromDER(_){let{r:y,s:d}=Zt.toSig(X("DER",_));return new h(y,d)}assertValidity(){wt("r",this.r,it,n),wt("s",this.s,it,n)}addRecoveryBit(_){return new h(this.r,this.s,_)}recoverPublicKey(_){let{r:y,s:d,recovery:w}=this,A=P(X("msgHash",_));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let C=w===2||w===3?y+t.n:y;if(C>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let R=(w&1)===0?"02":"03",K=c.fromHex(R+p(C)),M=a(C),N=i(-A*M),H=i(d*M),F=c.BASE.multiplyAndAddUnsafe(K,N,H);if(!F)throw new Error("point at infinify");return F.assertValidity(),F}hasHighS(){return x(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return pe(this.toDERHex())}toDERHex(){return Zt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return pe(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}let g={isValidPrivateKey(v){try{return f(v),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let v=no(t.n);return ni(t.randomBytes(v),t.n)},precompute(v=8,_=c.BASE){return _._setWindowSize(v),_.multiply(BigInt(3)),_}};function S(v,_=!0){return c.fromPrivateKey(v).toRawBytes(_)}function m(v){let _=ee(v),y=typeof v=="string",d=(_||y)&&v.length;return _?d===o||d===s:y?d===2*o||d===2*s:v instanceof c}function I(v,_,y=!0){if(m(v))throw new Error("first arg must be private key");if(!m(_))throw new Error("second arg must be public key");return c.fromHex(_).multiply(f(v)).toRawBytes(y)}let D=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let _=Ft(v),y=v.length*8-t.nBitLength;return y>0?_>>BigInt(y):_},P=t.bits2int_modN||function(v){return i(D(v))},B=Qe(t.nBitLength);function T(v){return wt("num < 2^"+t.nBitLength,v,Yt,B),ne(v,t.nByteLength)}function L(v,_,y=Z){if(["recovered","canonical"].some(st=>st in y))throw new Error("sign() legacy options not supported");let{hash:d,randomBytes:w}=t,{lowS:A,prehash:C,extraEntropy:R}=y;A==null&&(A=!0),v=X("msgHash",v),Ri(y),C&&(v=X("prehashed msgHash",d(v)));let K=P(v),M=f(_),N=[T(M),T(K)];if(R!=null&&R!==!1){let st=R===!0?w(e.BYTES):R;N.push(X("extraEntropy",st))}let H=Gt(...N),F=K;function ot(st){let at=D(st);if(!l(at))return;let ct=a(at),bt=c.BASE.multiply(at).toAffine(),pt=i(bt.x);if(pt===Yt)return;let Nt=i(ct*i(F+pt*M));if(Nt===Yt)return;let Ut=(bt.x===pt?0:2)|Number(bt.y&it),ze=Nt;return A&&x(Nt)&&(ze=E(Nt),Ut^=1),new h(pt,ze,Ut)}return{seed:H,k2sig:ot}}let Z={lowS:t.lowS,prehash:!1},O={lowS:t.lowS,prehash:!1};function U(v,_,y=Z){let{seed:d,k2sig:w}=L(v,_,y),A=t;return Qn(A.hash.outputLen,A.nByteLength,A.hmac)(d,w)}c.BASE._setWindowSize(8);function et(v,_,y,d=O){let w=v;_=X("msgHash",_),y=X("publicKey",y);let{lowS:A,prehash:C,format:R}=d;if(Ri(d),"strict"in d)throw new Error("options.strict was renamed to lowS");if(R!==void 0&&R!=="compact"&&R!=="der")throw new Error("format must be compact or der");let K=typeof w=="string"||ee(w),M=!K&&!R&&typeof w=="object"&&w!==null&&typeof w.r=="bigint"&&typeof w.s=="bigint";if(!K&&!M)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let N,H;try{if(M&&(N=new h(w.r,w.s)),K){try{R!=="compact"&&(N=h.fromDER(w))}catch(Ut){if(!(Ut instanceof Zt.Err))throw Ut}!N&&R!=="der"&&(N=h.fromCompact(w))}H=c.fromHex(y)}catch{return!1}if(!N||A&&N.hasHighS())return!1;C&&(_=t.hash(_));let{r:F,s:ot}=N,st=P(_),at=a(ot),ct=i(st*at),bt=i(F*at),pt=c.BASE.multiplyAndAddUnsafe(H,ct,bt)?.toAffine();return pt?i(pt.x)===F:!1}return{CURVE:t,getPublicKey:S,getSharedSecret:I,sign:U,verify:et,ProjectivePoint:c,Signature:h,utils:g}}function Bf(r){return{hash:r,hmac:(t,...e)=>Vo(r,t,Zn(...e)),randomBytes:ke}}function Ki(r,t){let e=n=>ki({...r,...Bf(n)});return{...e(t),create:e}}var Oi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ui=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Lf=BigInt(1),Fo=BigInt(2),Mi=(r,t)=>(r+t/Fo)/t;function _f(r){let t=Oi,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=$(u,e,t)*u%t,p=$(l,e,t)*u%t,x=$(p,Fo,t)*f%t,E=$(x,o,t)*x%t,b=$(E,s,t)*E%t,h=$(b,a,t)*b%t,g=$(h,c,t)*h%t,S=$(g,a,t)*b%t,m=$(S,e,t)*u%t,I=$(m,i,t)*E%t,D=$(I,n,t)*f%t,P=$(D,Fo,t);if(!Go.eql(Go.sqr(P),r))throw new Error("Cannot find square root");return P}var Go=oe(Oi,void 0,void 0,{sqrt:_f}),we=Ki({a:BigInt(0),b:BigInt(7),Fp:Go,n:Ui,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ui,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Lf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=Mi(s*r,t),c=Mi(-n*r,t),f=V(r-a*e-c*o,t),u=V(-a*n-c*s,t),l=f>i,p=u>i;if(l&&(f=t-f),p&&(u=t-u),f>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:p,k2:u}}}},Oe),d0=BigInt(0);var p0=we.ProjectivePoint;function qi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Hi(r,t,e){let n=le.digest(e instanceof Uint8Array?e:e.subarray());if(qi(n))return n.then(({digest:o})=>we.verify(t,o,r)).catch(o=>{throw new nr(String(o))});try{return we.verify(t,n.digest,r)}catch(o){throw new nr(String(o))}}var Yr=class{type="secp256k1";raw;_key;constructor(t){this._key=zi(t),this.raw=Vi(this._key)}toMultihash(){return _t.digest(Ht(this))}toCID(){return ut.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,e){return Hi(this._key,e,t)}};function Zo(r){return new Yr(r)}function Vi(r){return we.ProjectivePoint.fromHex(r).toRawBytes(!0)}function zi(r){try{return we.ProjectivePoint.fromHex(r),r}catch(t){throw new Ae(String(t))}}function Yo(r,t){let{Type:e,Data:n}=Kt.decode(r),o=n??new Uint8Array;switch(e){case tt.RSA:return Oo(o,t);case tt.Ed25519:return fo(o);case tt.secp256k1:return Zo(o);case tt.ECDSA:return Gn(o);default:throw new ue}}function Fi(r){let{Type:t,Data:e}=Kt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return fo(n);case tt.secp256k1:return Zo(n);case tt.ECDSA:return Gn(n);default:throw new ue}}function Ht(r){return Kt.encode({Type:tt[r.type],Data:r.raw})}var Gi=Symbol.for("nodejs.util.inspect.custom"),Tf=114,ir=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()})`}[bn]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ut.createV1(Tf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return gt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return gt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Gi](){return`PeerId(${this.toString()})`}},ar=class extends ir{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},cr=class extends ir{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},ur=class extends ir{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Df=2336,$r=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest(G(this.url))}[Gi](){return`PeerId(${this.url})`}[bn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ut.createV1(Df,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function $o(r){if(r.type==="Ed25519")return new cr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new ur({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new ar({multihash:r.toCID().multihash,publicKey:r});throw new ue}function Zi(r){return $o(r.publicKey)}function fr(r){if(Cf(r))return new ar({multihash:r});if(Pf(r))try{let t=Fi(r);if(t.type==="Ed25519")return new cr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new ur({multihash:r,publicKey:t})}catch{let e=z(r.digest);return new $r(new URL(e))}throw new Sr("Supplied PeerID Multihash is invalid")}function Pf(r){return r.code===_t.code}function Cf(r){return r.code===le.code}function Ee(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 Wr(r){let t=jt(j.decode(`z${r}`));return fr(t)}var lr=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 Ee(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 Ee(this.map.values(),t=>t.key)}values(){return Ee(this.map.values(),t=>t.value)}get size(){return this.map.size}};var hr=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 Ee(this.set.entries(),t=>{let e=Wr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Wr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ee(this.set.values(),t=>Wr(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 $t(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var jr=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},He=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new jr(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new jr(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Wo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Xr(r={}){return Rf(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 Rf(r,t){t=t??{};let e=t.onEnd,n=new He,o,s,i,a=$t(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,g)=>{s=S=>{s=null,n.push(S);try{h(r(n))}catch(m){g(m)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=$t()})}},f=h=>s!=null?s(h):(n.push(h),o),u=h=>(n=new He,s!=null?s({error:h}):(n.push({error:h}),o)),l=h=>{if(i)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:h})},p=h=>i?o:(i=!0,h!=null?u(h):f({done:!0})),x=()=>(n=new He,p(),{done:!0}),E=h=>(p(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:x,throw:E,push:l,end:p,get readableLength(){return n.size},onEmpty:async h=>{let g=h?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let S,m;g!=null&&(S=new Promise((I,D)=>{m=()=>{D(new Wo)},g.addEventListener("abort",m)}));try{await Promise.race([a.promise,S])}finally{m!=null&&g!=null&&g?.removeEventListener("abort",m)}}},e==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(h){return b.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return b.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(h){return b.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return b.readableLength},onEmpty:h=>b.onEmpty(h)},o}var Jr=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 Yi(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Jr(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Jr(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 jo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=$t(),this.haveNext=$t()}[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=$t(),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=$t(),await Yi(this.readNext.promise,e?.signal,e)}};function $i(){return new jo}function Nf(r){return r[Symbol.asyncIterator]!=null}async function kf(r,t){try{await Promise.all(r.map(async e=>{for await(let n of e)await t.push(n)})),await t.end()}catch(e){await t.end(e).catch(()=>{})}}async function*Kf(r){let t=$i();kf(r,t).catch(()=>{}),yield*t}function*Uf(r){for(let t of r)yield*t}function Mf(...r){let t=[];for(let e of r)Nf(e)||t.push(e);return t.length===r.length?Uf(t):Kf(r)}var Wi=Mf;function dr(r,...t){if(r==null)throw new Error("Empty pipeline");if(Xo(r)){let n=r;r=()=>n.source}else if(Xi(r)||ji(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Xo(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++)Xo(e[n])&&(e[n]=qf(e[n]));return Of(...e)}var Of=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},ji=r=>r?.[Symbol.asyncIterator]!=null,Xi=r=>r?.[Symbol.iterator]!=null,Xo=r=>r==null?!1:r.sink!=null&&r.source!=null,qf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Xr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(ji(s))o=async function*(){yield*s,n.end()};else if(Xi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Wi(n,o())}return r.source};var Qo=_a(Qi(),1);var mr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},ts=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},ta=r=>globalThis.DOMException===void 0?new ts(r):new DOMException(r),ea=r=>{let t=r.reason===void 0?ta("This operation was aborted."):r.reason;return t instanceof Error?t:ta(t)};function es(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:x}=t;x.aborted&&l(ea(x)),a=()=>{l(ea(x))},x.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,l);return}let p=new mr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(x){l(x)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?l(o):(p.message=o??`Promise timed out after ${e} milliseconds`,l(p))},e),(async()=>{try{u(await r)}catch(x){l(x)}})()}).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 rs(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 yr=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=rs(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var br=class extends Qo.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:yr,...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=es(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 mr&&!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 ra(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 na(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function oa(r,t){let e=ra(r).return?.();na(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var tn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ve=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},en=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},gr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function rn(r){return r[Symbol.asyncIterator]!=null}function sa(r,t){if(r.byteLength>t)throw new Ve("Message length too long")}var on=r=>{let t=Ct(r),e=ft(t);return di(r,e),on.bytes=t,e};on.bytes=0;function sn(r,t){t=t??{};let e=t.lengthEncoder??on,n=t?.maxDataLength??4194304;function*o(s){sa(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return rn(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}sn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??on,n=t?.maxDataLength??4194304;return sa(r,n),new rt(e(r.byteLength),r)};var Se;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Se||(Se={}));var ns=r=>{let t=pi(r);return ns.bytes=Ct(t),t};ns.bytes=0;function xr(r,t){let e=new rt,n=Se.LENGTH,o=-1,s=t?.lengthDecoder??ns,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===Se.LENGTH)try{if(o=s(e),o<0)throw new tn("Invalid message length");if(o>a)throw new Ve("Message length too long");let f=s.bytes;e.consume(f),t?.onLength!=null&&t.onLength(o),n=Se.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>i)throw new en("Message length length too long");break}throw f}if(n===Se.DATA){if(e.byteLength<o)break;let f=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(f),yield f,n=Se.LENGTH}}}return rn(r)?async function*(){for await(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new gr("Unexpected end of input")}():function*(){for(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new gr("Unexpected end of input")}()}xr.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 xr(n,{...t??{},onLength:s=>{e=s}})};var an=class extends Ie{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=e.id,this.protocol=e.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let e=this.id.toString();throw new Error("No writable connection to "+e)}this.outboundStream.push(t instanceof Uint8Array?new rt(t):t)}attachInboundStream(t,e){let n=()=>{oa(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=dr(this._rawInboundStream,o=>xr(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=Xr({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"))}}),dr(this.outboundStream,n=>sn(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 ia(){return BigInt(`0x${z(Fr(8),"base16")}`)}var aa=(r,t)=>{let e=G(t.toString(16).padStart(16,"0"),"base16"),n=Ht(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},ca=r=>le.encode(r);var ua=function(r){return Array.isArray(r)?r:[r]},Gf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=fr(jt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return $o(Yo(e)).equals(t)}return!1},fa=async r=>{if(r.from==null)throw new Q("RPC message was missing from");if(!await Gf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=fr(jt(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:Yf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?Yo(e):e}},wr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:Zf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Ht(r.key):void 0}:{data:r.data,topic:r.topic},Zf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),G(t,"base16")},Yf=r=>BigInt(`0x${z(r,"base16")}`);var la=G("libp2p-pubsub:");async function ha(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Zi(r)},o=fe([la,e(wr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function da(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([la,t({...wr(r),signature:void 0,key:void 0}).subarray()]);return $f(r).verify(e,r.signature)}function $f(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 cn=class extends Ie{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,e){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:a=10,maxInboundStreams:c=1,maxOutboundStreams:f=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=ua(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new lr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new br({concurrency:a}),this.maxInboundStreams=c,this.maxOutboundStreams=f,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let e={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.multicodecs.map(async e=>{await t.unhandle(e)})),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:e,connection:n}=t,o=n.remotePeer;if(e.protocol==null){e.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,e.protocol),i=s.attachInboundStream(e);this.processMessages(o,i,s).catch(a=>{this.log(a)})}_onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await e.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new an(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 dr(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 fa(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 hr,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 aa(t.key,t.sequenceNumber);case"StrictNoSign":return ca(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(wr)})}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 da(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===Fe.Reject||s===Fe.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return ha(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 vr("not started yet");if(t==null)throw new W("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:ia()};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 un=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 os="/floodsub/1.0.0";var ve;(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),fn.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 Bt('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 Bt('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=fn.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)})(ve||(ve={}));var fn;(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),ln.codec().encode(s,n);if(e.iwant!=null)for(let s of e.iwant)n.uint32(18),hn.codec().encode(s,n);if(e.graft!=null)for(let s of e.graft)n.uint32(26),dn.codec().encode(s,n);if(e.prune!=null)for(let s of e.prune)n.uint32(34),pn.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 Bt('Decode error - map field "ihave" had too many elements');s.ihave.push(ln.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 Bt('Decode error - map field "iwant" had too many elements');s.iwant.push(hn.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 Bt('Decode error - map field "graft" had too many elements');s.graft.push(dn.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 Bt('Decode error - map field "prune" had too many elements');s.prune.push(pn.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)})(fn||(fn={}));var ln;(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 Bt('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)})(ln||(ln={}));var hn;(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 Bt('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)})(hn||(hn={}));var dn;(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)})(dn||(dn={}));var pn;(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),mn.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 Bt('Decode error - map field "peers" had too many elements');s.peers.push(mn.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)})(pn||(pn={}));var mn;(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)})(mn||(mn={}));var ss=class extends cn{seenCache;constructor(t,e){super(t,{...e,canRelayMessage:!0,multicodecs:[os]}),this.log=t.logger.forComponent("libp2p:floodsub"),this.seenCache=new un({validityMs:e?.seenTTL??3e4})}[ps]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[ms]=["@libp2p/pubsub"];[ys]=["@libp2p/identify"];decodeRpc(t){return ve.decode(t)}encodeRpc(t){return ve.encode(t)}decodeMessage(t){return ve.Message.decode(t)}encodeMessage(t){return ve.Message.encode(t)}async processMessage(t,e){let n=await super.getMsgId(e),o=z(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 Wf(r={}){return t=>new ss(t,r)}return Ta(jf);})();
|
|
2
|
+
"use strict";var Libp2PFloodsub=(()=>{var da=Object.create;var xr=Object.defineProperty;var pa=Object.getOwnPropertyDescriptor;var ma=Object.getOwnPropertyNames;var ya=Object.getPrototypeOf,ba=Object.prototype.hasOwnProperty;var ga=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),gt=(r,t)=>{for(var e in t)xr(r,e,{get:t[e],enumerable:!0})},rs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ma(t))!ba.call(r,o)&&o!==e&&xr(r,o,{get:()=>t[o],enumerable:!(n=pa(t,o))||n.enumerable});return r};var xa=(r,t,e)=>(e=r!=null?da(ya(r)):{},rs(t||!r||!r.__esModule?xr(e,"default",{value:r,enumerable:!0}):e,r)),wa=r=>rs(xr({},"__esModule",{value:!0}),r);var Wi=ga((Mm,Yo)=>{"use strict";var Sf=Object.prototype.hasOwnProperty,yt="~";function hr(){}Object.create&&(hr.prototype=Object.create(null),new hr().__proto__||(yt=!1));function vf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Yi(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=yt?yt+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 Yr(r,t){--r._eventsCount===0?r._events=new hr:delete r._events[t]}function pt(){this._events=new hr,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(yt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};pt.prototype.listeners=function(t){var e=yt?yt+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=yt?yt+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=yt?yt+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 d=c.length,x;for(l=0;l<d;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(x=1,u=new Array(f-1);x<f;x++)u[x-1]=arguments[x];c[l].fn.apply(c[l].context,u)}}return!0};pt.prototype.on=function(t,e,n){return Yi(this,t,e,n,!1)};pt.prototype.once=function(t,e,n){return Yi(this,t,e,n,!0)};pt.prototype.removeListener=function(t,e,n,o){var s=yt?yt+t:t;if(!this._events[s])return this;if(!e)return Yr(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&Yr(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:Yr(this,s)}return this};pt.prototype.removeAllListeners=function(t){var e;return t?(e=yt?yt+t:t,this._events[e]&&Yr(this,e)):(this._events=new hr,this._eventsCount=0),this};pt.prototype.off=pt.prototype.removeListener;pt.prototype.addListener=pt.prototype.on;pt.prefixed=yt;pt.EventEmitter=pt;typeof Yo<"u"&&(Yo.exports=pt)});var Pf={};gt(Pf,{floodsub:()=>Df,multicodec:()=>Qo});var fn=Symbol.for("@libp2p/peer-id");var Ve;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ve||(Ve={}));var ns=Symbol.for("@libp2p/pubsub");var $=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Se=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var wr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var tt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Er=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ie=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ve=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let 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 os=Symbol.for("@libp2p/service-capabilities"),ss=Symbol.for("@libp2p/service-dependencies");var mn={};gt(mn,{base58btc:()=>j,base58flickr:()=>Ba});var sl=new Uint8Array(0);function is(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 Kt(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 as(r){return new TextEncoder().encode(r)}function cs(r){return new TextDecoder().decode(r)}function Ea(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(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var y=0,h=0,b=0,v=E.length;b!==v&&E[b]===0;)b++,y++;for(var p=(v-b)*u+1>>>0,I=new Uint8Array(p);b!==v;){for(var P=E[b],C=0,_=p-1;(P!==0||C<h)&&_!==-1;_--,C++)P+=256*I[_]>>>0,I[_]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");h=C,b++}for(var L=p-h;L!==p&&I[L]===0;)L++;for(var T=c.repeat(y);L<p;++L)T+=r.charAt(I[L]);return T}function d(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var y=0;if(E[y]!==" "){for(var h=0,b=0;E[y]===c;)h++,y++;for(var v=(E.length-y)*f+1>>>0,p=new Uint8Array(v);E[y];){var I=e[E.charCodeAt(y)];if(I===255)return;for(var P=0,C=v-1;(I!==0||P<b)&&C!==-1;C--,P++)I+=a*p[C]>>>0,p[C]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");b=P,y++}if(E[y]!==" "){for(var _=v-b;_!==v&&p[_]===0;)_++;for(var L=new Uint8Array(h+(v-_)),T=h;_!==v;)L[T++]=p[_++];return L}}}function x(E){var y=d(E);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:x}}var Sa=Ea,va=Sa,fs=va;var ln=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")}},hn=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 ls(this,t)}},dn=class{decoders;constructor(t){this.decoders=t}or(t){return ls(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 ls(r,t){return new dn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var pn=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 ln(t,e,n),this.decoder=new hn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ae({name:r,prefix:t,encode:e,decode:n}){return new pn(r,t,e,n)}function Yt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=fs(e,r);return Ae({prefix:t,name:r,encode:n,decode:s=>Kt(o(s))})}function Aa(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 Ia(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 J({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ae({prefix:t,name:r,encode(o){return Ia(o,n,e)},decode(o){return Aa(o,n,e,r)}})}var j=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ba=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var yn={};gt(yn,{base32:()=>Ie,base32hex:()=>Da,base32hexpad:()=>Ca,base32hexpadupper:()=>Na,base32hexupper:()=>Pa,base32pad:()=>La,base32padupper:()=>Ta,base32upper:()=>_a,base32z:()=>ka});var Ie=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),_a=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),La=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ta=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Da=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pa=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ca=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Na=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ka=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var bn={};gt(bn,{base36:()=>ze,base36upper:()=>Ra});var ze=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ra=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ua=ps,hs=128,Ka=127,Ma=~Ka,Oa=Math.pow(2,31);function ps(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Oa;)t[e++]=r&255|hs,r/=128;for(;r&Ma;)t[e++]=r&255|hs,r>>>=7;return t[e]=r|0,ps.bytes=e-n+1,t}var qa=gn,Ha=128,ds=127;function gn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw gn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ds)<<o:(i&ds)*Math.pow(2,o),o+=7}while(i>=Ha);return gn.bytes=s-n,e}var Va=Math.pow(2,7),za=Math.pow(2,14),Fa=Math.pow(2,21),Ga=Math.pow(2,28),Za=Math.pow(2,35),Ya=Math.pow(2,42),Wa=Math.pow(2,49),$a=Math.pow(2,56),ja=Math.pow(2,63),Xa=function(r){return r<Va?1:r<za?2:r<Fa?3:r<Ga?4:r<Za?5:r<Ya?6:r<Wa?7:r<$a?8:r<ja?9:10},Ja={encode:Ua,decode:qa,encodingLength:Xa},Qa=Ja,Fe=Qa;function Ge(r,t=0){return[Fe.decode(r,t),Fe.decode.bytes]}function Be(r,t,e=0){return Fe.encode(r,t,e),t}function _e(r){return Fe.encodingLength(r)}function Tt(r,t){let e=t.byteLength,n=_e(r),o=n+_e(e),s=new Uint8Array(o+e);return Be(r,s,0),Be(e,s,n),s.set(t,o),new Le(r,e,t,s)}function Wt(r){let t=Kt(r),[e,n]=Ge(t),[o,s]=Ge(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Le(e,o,i,t)}function ms(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&is(r.bytes,e.bytes)}}var Le=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ys(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return ec(e,xn(r),t??j.encoder);default:return rc(e,xn(r),t??Ie.encoder)}}var bs=new WeakMap;function xn(r){let t=bs.get(r);if(t==null){let e=new Map;return bs.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!==Ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==nc)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=Tt(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&&ms(t.multihash,n.multihash)}toString(t){return ys(this,t)}toJSON(){return{"/":ys(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??gs(n,o,s.bytes))}else if(e[oc]===!0){let{version:n,multihash:o,code:s}=e,i=Wt(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!==Ze)throw new Error(`Version 0 CID must use dag-pb (code: ${Ze}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=gs(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ze,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=Kt(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 Le(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,d]=Ge(t.subarray(e));return e+=d,l},o=n(),s=Ze;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]=tc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return xn(s).set(n,t),s}};function tc(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 Ie.prefix:{let e=t??Ie;return[Ie.prefix,e.decode(r)]}case ze.prefix:{let e=t??ze;return[ze.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 ec(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 rc(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 Ze=112,nc=18;function gs(r,t,e){let n=_e(r),o=n+_e(t),s=new Uint8Array(o+e.byteLength);return Be(r,s,0),Be(t,s,n),s.set(e,o),s}var oc=Symbol.for("@ipld/js-cid/CID");var wn={};gt(wn,{identity:()=>Dt});var xs=0,sc="identity",ws=Kt;function ic(r){return Tt(xs,ws(r))}var Dt={code:xs,name:sc,encode:ws,digest:ic};function xt(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 Mt(r=0){return new Uint8Array(r)}function lt(r=0){return new Uint8Array(r)}function ae(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 Ss=Symbol.for("@achingbrain/uint8arraylist");function Es(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 vr(r){return!!r?.[Ss]}var ot=class r{bufs;length;[Ss]=!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(vr(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(vr(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=Es(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Es(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(vr(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 ae(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ae(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(!vr(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 d=f;d>=0;d--){let x=this.get(l+d);if(n[d]!==x){u=Math.max(1,d-a[x]);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=Mt(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=Mt(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=Mt(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=Mt(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=Mt(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=Mt(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=Mt(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=Mt(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(!xt(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 En={};gt(En,{base10:()=>ac});var ac=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var Sn={};gt(Sn,{base16:()=>cc,base16upper:()=>uc});var cc=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),uc=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var vn={};gt(vn,{base2:()=>fc});var fc=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var An={};gt(An,{base256emoji:()=>mc});var vs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),lc=vs.reduce((r,t,e)=>(r[e]=t,r),[]),hc=vs.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function dc(r){return r.reduce((t,e)=>(t+=lc[e],t),"")}function pc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=hc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var mc=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:dc,decode:pc});var In={};gt(In,{base64:()=>yc,base64pad:()=>bc,base64url:()=>gc,base64urlpad:()=>xc});var yc=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),bc=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),gc=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),xc=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Bn={};gt(Bn,{base8:()=>wc});var wc=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var _n={};gt(_n,{identity:()=>Ec});var Ec=Ae({prefix:"\0",name:"identity",encode:r=>cs(r),decode:r=>as(r)});var Vl=new TextEncoder,zl=new TextDecoder;var Dn={};gt(Dn,{sha256:()=>ce,sha512:()=>Ac});function Tn({name:r,code:t,encode:e}){return new Ln(r,t,e)}var Ln=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?Tt(this.code,e):e.then(n=>Tt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Is(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ce=Tn({name:"sha2-256",code:18,encode:Is("SHA-256")}),Ac=Tn({name:"sha2-512",code:19,encode:Is("SHA-512")});var Pn={..._n,...vn,...Bn,...En,...Sn,...yn,...bn,...mn,...In,...An},eh={...Dn,...wn};function _s(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Bs=_s("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Cn=_s("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}),Ic={utf8:Bs,"utf-8":Bs,hex:Pn.base16,latin1:Cn,ascii:Cn,binary:Cn,...Pn},Ar=Ic;function Z(r,t="utf8"){let e=Ar[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function F(r,t="utf8"){let e=Ar[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Bc=parseInt("11111",2),Nn=parseInt("10000000",2),_c=parseInt("01111111",2),Ls={0:Ye,1:Ye,2:Lc,3:Pc,4:Cc,5:Dc,6:Tc,16:Ye,22:Ye,48:Ye};function Ot(r,t={offset:0}){let e=r[t.offset]&Bc;if(t.offset++,Ls[e]!=null)return Ls[e](r,t);throw new Error("No decoder for tag "+e)}function We(r,t){let e=0;if((r[t.offset]&Nn)===Nn){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 Ye(r,t){We(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Ot(r,t);if(n===null)break;e.push(n)}return e}function Lc(r,t){let e=We(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 Tc(r,t){let e=We(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 Dc(r,t){return t.offset++,null}function Pc(r,t){let e=We(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 Cc(r,t){let e=We(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Nc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ot;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function kn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Nc(r.byteLength);return new ot(Uint8Array.from([t.byteLength|Nn]),t)}function wt(r){let t=new ot,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ot(Uint8Array.from([2]),kn(t),t)}function Ir(r){let t=Uint8Array.from([0]),e=new ot(t,r);return new ot(Uint8Array.from([3]),kn(e),e)}function jt(r,t=48){let e=new ot;for(let n of r)e.append(n);return new ot(Uint8Array.from([t]),kn(e),e)}async function Ts(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 kc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Rc=Uint8Array.from([6,5,43,129,4,0,34]),Uc=Uint8Array.from([6,5,43,129,4,0,35]),Kc={ext:!0,kty:"EC",crv:"P-256"},Mc={ext:!0,kty:"EC",crv:"P-384"},Oc={ext:!0,kty:"EC",crv:"P-521"},Rn=32,Un=48,Kn=66;function Mn(r){let t=Ot(r);return Ds(t)}function Ds(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Rn*2+1)return n=F(t.subarray(e,e+Rn),"base64url"),o=F(t.subarray(e+Rn),"base64url"),new Te({...Kc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Un*2+1)return n=F(t.subarray(e,e+Un),"base64url"),o=F(t.subarray(e+Un),"base64url"),new Te({...Mc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Kn*2+1)return n=F(t.subarray(e,e+Kn),"base64url"),o=F(t.subarray(e+Kn),"base64url"),new Te({...Oc,key_ops:["verify"],x:n,y:o});throw new $(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ps(r){return jt([wt(Uint8Array.from([1])),jt([qc(r.crv)],160),jt([Ir(new ot(Uint8Array.from([4]),Z(r.x??"","base64url"),Z(r.y??"","base64url")))],161)]).subarray()}function qc(r){if(r==="P-256")return kc;if(r==="P-384")return Rc;if(r==="P-521")return Uc;throw new $(`Invalid curve ${r}`)}var Te=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ps(this.jwk)),this._raw}toMultihash(){return Dt.digest(qt(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:xt(this.raw,t.raw)}async verify(t,e){return Ts(this.jwk,e,t)}};function Cs(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Hc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function De(r,...t){if(!Hc(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 Ns(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Cs(r.outputLen),Cs(r.blockLen)}function Pe(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 ks(r,t){De(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ue=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Br(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Pt(r,t){return r<<32-t|r>>>t}var Uh=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function";function Rs(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function $e(r){return typeof r=="string"&&(r=Rs(r)),De(r),r}function On(...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 Ce=class{clone(){return this._cloneInto()}};function _r(r){let t=n=>r().update($e(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Ne(r=32){if(ue&&typeof ue.getRandomValues=="function")return ue.getRandomValues(new Uint8Array(r));if(ue&&typeof ue.randomBytes=="function")return Uint8Array.from(ue.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Vc(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 Us(r,t,e){return r&t^~r&e}function Ks(r,t,e){return r&t^r&e^t&e}var ke=class extends Ce{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Br(this.buffer)}update(t){Pe(this);let{view:e,buffer:n,blockLen:o}=this;t=$e(t);let s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Br(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){Pe(this),ks(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;Vc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Br(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.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var zc=new Uint32Array([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]),Xt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Jt=new Uint32Array(64),qn=class extends ke{constructor(t=32){super(64,t,8,!1),this.A=Xt[0]|0,this.B=Xt[1]|0,this.C=Xt[2]|0,this.D=Xt[3]|0,this.E=Xt[4]|0,this.F=Xt[5]|0,this.G=Xt[6]|0,this.H=Xt[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)Jt[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let d=Jt[l-15],x=Jt[l-2],E=Pt(d,7)^Pt(d,18)^d>>>3,y=Pt(x,17)^Pt(x,19)^x>>>10;Jt[l]=y+Jt[l-7]+E+Jt[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 d=Pt(a,6)^Pt(a,11)^Pt(a,25),x=u+d+Us(a,c,f)+zc[l]+Jt[l]|0,y=(Pt(n,2)^Pt(n,13)^Pt(n,22))+Ks(n,o,s)|0;u=f,f=c,c=a,a=i+x|0,i=s,s=o,o=n,n=x+y|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(){Jt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var fe=_r(()=>new qn);var Lr=BigInt(4294967295),Hn=BigInt(32);function Ms(r,t=!1){return t?{h:Number(r&Lr),l:Number(r>>Hn&Lr)}:{h:Number(r>>Hn&Lr)|0,l:Number(r&Lr)|0}}function Fc(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=Ms(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var Gc=(r,t)=>BigInt(r>>>0)<<Hn|BigInt(t>>>0),Zc=(r,t,e)=>r>>>e,Yc=(r,t,e)=>r<<32-e|t>>>e,Wc=(r,t,e)=>r>>>e|t<<32-e,$c=(r,t,e)=>r<<32-e|t>>>e,jc=(r,t,e)=>r<<64-e|t>>>e-32,Xc=(r,t,e)=>r>>>e-32|t<<64-e,Jc=(r,t)=>t,Qc=(r,t)=>r,tu=(r,t,e)=>r<<e|t>>>32-e,eu=(r,t,e)=>t<<e|r>>>32-e,ru=(r,t,e)=>t<<e-32|r>>>64-e,nu=(r,t,e)=>r<<e-32|t>>>64-e;function ou(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var su=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),iu=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,au=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),cu=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,uu=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),fu=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var lu={fromBig:Ms,split:Fc,toBig:Gc,shrSH:Zc,shrSL:Yc,rotrSH:Wc,rotrSL:$c,rotrBH:jc,rotrBL:Xc,rotr32H:Jc,rotr32L:Qc,rotlSH:tu,rotlSL:eu,rotlBH:ru,rotlBL:nu,add:ou,add3L:su,add3H:iu,add4L:au,add4H:cu,add5H:fu,add5L:uu},k=lu;var[hu,du]=k.split(["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))),Qt=new Uint32Array(80),te=new Uint32Array(80),Vn=class extends ke{constructor(t=64){super(128,t,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}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:d,Gh:x,Gl:E,Hh:y,Hl:h}=this;return[t,e,n,o,s,i,a,c,f,u,l,d,x,E,y,h]}set(t,e,n,o,s,i,a,c,f,u,l,d,x,E,y,h){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=d|0,this.Gh=x|0,this.Gl=E|0,this.Hh=y|0,this.Hl=h|0}process(t,e){for(let p=0;p<16;p++,e+=4)Qt[p]=t.getUint32(e),te[p]=t.getUint32(e+=4);for(let p=16;p<80;p++){let I=Qt[p-15]|0,P=te[p-15]|0,C=k.rotrSH(I,P,1)^k.rotrSH(I,P,8)^k.shrSH(I,P,7),_=k.rotrSL(I,P,1)^k.rotrSL(I,P,8)^k.shrSL(I,P,7),L=Qt[p-2]|0,T=te[p-2]|0,G=k.rotrSH(L,T,19)^k.rotrBH(L,T,61)^k.shrSH(L,T,6),q=k.rotrSL(L,T,19)^k.rotrBL(L,T,61)^k.shrSL(L,T,6),U=k.add4L(_,q,te[p-7],te[p-16]),nt=k.add4H(U,C,G,Qt[p-7],Qt[p-16]);Qt[p]=nt|0,te[p]=U|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:d,Fh:x,Fl:E,Gh:y,Gl:h,Hh:b,Hl:v}=this;for(let p=0;p<80;p++){let I=k.rotrSH(l,d,14)^k.rotrSH(l,d,18)^k.rotrBH(l,d,41),P=k.rotrSL(l,d,14)^k.rotrSL(l,d,18)^k.rotrBL(l,d,41),C=l&x^~l&y,_=d&E^~d&h,L=k.add5L(v,P,_,du[p],te[p]),T=k.add5H(L,b,I,C,hu[p],Qt[p]),G=L|0,q=k.rotrSH(n,o,28)^k.rotrBH(n,o,34)^k.rotrBH(n,o,39),U=k.rotrSL(n,o,28)^k.rotrBL(n,o,34)^k.rotrBL(n,o,39),nt=n&s^n&a^s&a,S=o&i^o&c^i&c;b=y|0,v=h|0,y=x|0,h=E|0,x=l|0,E=d|0,{h:l,l:d}=k.add(f|0,u|0,T|0,G|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let B=k.add3L(G,U,S);n=k.add3H(B,T,q,nt),o=B|0}({h:n,l:o}=k.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=k.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=k.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=k.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:d}=k.add(this.Eh|0,this.El|0,l|0,d|0),{h:x,l:E}=k.add(this.Fh|0,this.Fl|0,x|0,E|0),{h:y,l:h}=k.add(this.Gh|0,this.Gl|0,y|0,h|0),{h:b,l:v}=k.add(this.Hh|0,this.Hl|0,b|0,v|0),this.set(n,o,s,i,a,c,f,u,l,d,x,E,y,h,b,v)}roundClean(){Qt.fill(0),te.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var zn=_r(()=>new Vn);var Yn=BigInt(0),Zn=BigInt(1);function le(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Wn(r){if(!le(r))throw new Error("Uint8Array expected")}function kt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function je(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Hs(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Yn:BigInt("0x"+r)}var Vs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",pu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ee(r){if(Wn(r),Vs)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=pu[r[e]];return t}var Ht={_0:48,_9:57,A:65,F:70,a:97,f:102};function Os(r){if(r>=Ht._0&&r<=Ht._9)return r-Ht._0;if(r>=Ht.A&&r<=Ht.F)return r-(Ht.A-10);if(r>=Ht.a&&r<=Ht.f)return r-(Ht.a-10)}function Xe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Vs)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=Os(r.charCodeAt(s)),a=Os(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 Vt(r){return Hs(ee(r))}function he(r){return Wn(r),Hs(ee(Uint8Array.from(r).reverse()))}function de(r,t){return Xe(r.toString(16).padStart(t*2,"0"))}function Re(r,t){return de(r,t).reverse()}function X(r,t,e){let n;if(typeof t=="string")try{n=Xe(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(le(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 re(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Wn(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 Fn=r=>typeof r=="bigint"&&Yn<=r;function Tr(r,t,e){return Fn(r)&&Fn(t)&&Fn(e)&&t<=r&&r<e}function It(r,t,e,n){if(!Tr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function zs(r){let t;for(t=0;r>Yn;r>>=Zn,t+=1);return t}var pe=r=>(Zn<<BigInt(r))-Zn,Gn=r=>new Uint8Array(r),qs=r=>Uint8Array.from(r);function Fs(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=Gn(r),o=Gn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...l)=>e(o,n,...l),c=(l=Gn(0))=>{o=a(qs([0]),l),n=a(),l.length!==0&&(o=a(qs([1]),l),n=a())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<t;){n=a();let x=n.slice();d.push(x),l+=n.length}return re(...d)};return(l,d)=>{i(),c(l);let x;for(;!(x=d(f()));)c();return i(),x}}var mu={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"||le(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 zt(r,t,e={}){let n=(o,s,i)=>{let a=mu[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 Ue(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 st=BigInt(0),Y=BigInt(1),me=BigInt(2),yu=BigInt(3),$n=BigInt(4),Gs=BigInt(5),Zs=BigInt(8),bu=BigInt(9),gu=BigInt(16);function z(r,t){let e=r%t;return e>=st?e:t+e}function xu(r,t,e){if(t<st)throw new Error("invalid exponent, negatives unsupported");if(e<=st)throw new Error("invalid modulus");if(e===Y)return st;let n=Y;for(;t>st;)t&Y&&(n=n*r%e),r=r*r%e,t>>=Y;return n}function W(r,t,e){let n=r;for(;t-- >st;)n*=n,n%=e;return n}function Dr(r,t){if(r===st)throw new Error("invert: expected non-zero number");if(t<=st)throw new Error("invert: expected positive modulus, got "+t);let e=z(r,t),n=t,o=st,s=Y,i=Y,a=st;for(;e!==st;){let f=n/e,u=n%e,l=o-i*f,d=s-a*f;n=e,e=u,o=i,s=a,i=l,a=d}if(n!==Y)throw new Error("invert: does not exist");return z(o,t)}function wu(r){let t=(r-Y)/me,e,n,o;for(e=r-Y,n=0;e%me===st;e/=me,n++);for(o=me;o<r&&xu(o,t,r)!==r-Y;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+Y)/$n;return function(c,f){let u=c.pow(f,i);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let s=(e+Y)/me;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,o),e),l=a.pow(c,s),d=a.pow(c,e);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let x=1;for(let y=a.sqr(d);x<f&&!a.eql(y,a.ONE);x++)y=a.sqr(y);let E=a.pow(u,Y<<BigInt(f-x-1));u=a.sqr(E),l=a.mul(l,E),d=a.mul(d,u),f=x}return l}}function Eu(r){if(r%$n===yu){let t=(r+Y)/$n;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%Zs===Gs){let t=(r-Gs)/Zs;return function(n,o){let s=n.mul(o,me),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,me),i),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return r%gu,wu(r)}var Ys=(r,t)=>(z(r,t)&Y)===Y,Su=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function jn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Su.reduce((n,o)=>(n[o]="function",n),t);return zt(r,e)}function vu(r,t,e){if(e<st)throw new Error("invalid exponent, negatives unsupported");if(e===st)return r.ONE;if(e===Y)return t;let n=r.ONE,o=t;for(;e>st;)e&Y&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Y;return n}function Au(r,t){let e=new Array(t.length),n=t.reduce((s,i,a)=>r.is0(i)?s:(e[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,a)=>r.is0(i)?s:(e[a]=r.mul(s,e[a]),r.mul(s,i)),o),e}function Xn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function ne(r,t,e=!1,n={}){if(r<=st)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=Xn(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:pe(o),ZERO:st,ONE:Y,create:c=>z(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return st<=c&&c<r},is0:c=>c===st,isOdd:c=>(c&Y)===Y,neg:c=>z(-c,r),eql:(c,f)=>c===f,sqr:c=>z(c*c,r),add:(c,f)=>z(c+f,r),sub:(c,f)=>z(c-f,r),mul:(c,f)=>z(c*f,r),pow:(c,f)=>vu(a,c,f),div:(c,f)=>z(c*Dr(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Dr(c,r),sqrt:n.sqrt||(c=>(i||(i=Eu(r)),i(a,c))),invertBatch:c=>Au(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>e?Re(c,s):de(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?he(c):Vt(c)}});return Object.freeze(a)}function Ws(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 Jn(r){let t=Ws(r);return t+Math.ceil(t/2)}function $s(r,t,e=!1){let n=r.length,o=Ws(t),s=Jn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?he(r):Vt(r),a=z(i,t-Y)+Y;return e?Re(a,o):de(a,o)}var js=BigInt(0),no=BigInt(1);function Qn(r,t){let e=t.negate();return r?e:t}function Js(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function to(r,t){Js(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=pe(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Xs(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+=no);let f=t*n,u=f+Math.abs(a)-1,l=a===0,d=a<0,x=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:d,isNegF:x,offsetF:f}}function Iu(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 Bu(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 eo=new WeakMap,Qs=new WeakMap;function ro(r){return Qs.get(r)||1}function Pr(r,t){return{constTimeNegate:Qn,hasPrecomputes(e){return ro(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>js;)n&no&&(o=o.add(s)),s=s.double(),n>>=no;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=to(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=to(e,t);for(let c=0;c<a.windows;c++){let{nextN:f,offset:u,isZero:l,isNeg:d,isNegF:x,offsetF:E}=Xs(o,c,a);o=f,l?i=i.add(Qn(x,n[E])):s=s.add(Qn(d,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=to(e,t);for(let a=0;a<i.windows&&o!==js;a++){let{nextN:c,offset:f,isZero:u,isNeg:l}=Xs(o,a,i);if(o=c,!u){let d=n[f];s=s.add(l?d.negate():d)}}return s},getPrecomputes(e,n,o){let s=eo.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&eo.set(n,o(s))),s},wNAFCached(e,n,o){let s=ro(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=ro(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Js(n,t),Qs.set(e,n),eo.delete(e)}}}function Cr(r,t,e,n){if(Iu(e,r),Bu(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=zs(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=pe(i),c=new Array(Number(a)+1).fill(o),f=Math.floor((t.BITS-1)/i)*i,u=o;for(let l=f;l>=0;l-=i){c.fill(o);for(let x=0;x<n.length;x++){let E=n[x],y=Number(E>>BigInt(l)&a);c[y]=c[y].add(e[x])}let d=o;for(let x=c.length-1,E=o;x>0;x--)E=E.add(c[x]),d=d.add(E);if(u=u.add(d),l!==0)for(let x=0;x<i;x++)u=u.double()}return u}function Je(r){return jn(r.Fp),zt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Xn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Rt=BigInt(0),mt=BigInt(1),ti=BigInt(2),_u=BigInt(8),Lu={zip215:!0};function Tu(r){let t=Je(r);return zt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function ei(r){let t=Tu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,f=ti<<BigInt(a*8)-mt,u=e.create,l=ne(t.n,t.nBitLength),d=t.uvRatio||((g,m)=>{try{return{isValid:!0,value:e.sqrt(g*e.inv(m))}}catch{return{isValid:!1,value:Rt}}}),x=t.adjustScalarBytes||(g=>g),E=t.domain||((g,m,w)=>{if(kt("phflag",w),m.length||w)throw new Error("Contexts/pre-hash are not supported");return g});function y(g,m,w=!1){let A=w?mt:Rt;It("coordinate "+g,m,A,f)}function h(g){if(!(g instanceof p))throw new Error("ExtendedPoint expected")}let b=Ue((g,m)=>{let{ex:w,ey:A,ez:N}=g,R=g.is0();m==null&&(m=R?_u:e.inv(N));let K=u(w*m),M=u(A*m),O=u(N*m);if(R)return{x:Rt,y:mt};if(O!==mt)throw new Error("invZ was invalid");return{x:K,y:M}}),v=Ue(g=>{let{a:m,d:w}=t;if(g.is0())throw new Error("bad point: ZERO");let{ex:A,ey:N,ez:R,et:K}=g,M=u(A*A),O=u(N*N),V=u(R*R),rt=u(V*V),Q=u(M*m),ct=u(V*u(Q+O)),bt=u(rt+u(w*u(M*O)));if(ct!==bt)throw new Error("bad point: equation left != right (1)");let it=u(A*N),ut=u(R*K);if(it!==ut)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(m,w,A,N){y("x",m),y("y",w),y("z",A,!0),y("t",N),this.ex=m,this.ey=w,this.ez=A,this.et=N,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x:w,y:A}=m||{};return y("x",w),y("y",A),new p(w,A,mt,u(w*A))}static normalizeZ(m){let w=e.invertBatch(m.map(A=>A.ez));return m.map((A,N)=>A.toAffine(w[N])).map(p.fromAffine)}static msm(m,w){return Cr(p,l,m,w)}_setWindowSize(m){C.setWindowSize(this,m)}assertValidity(){v(this)}equals(m){h(m);let{ex:w,ey:A,ez:N}=this,{ex:R,ey:K,ez:M}=m,O=u(w*M),V=u(R*N),rt=u(A*M),Q=u(K*N);return O===V&&rt===Q}is0(){return this.equals(p.ZERO)}negate(){return new p(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:m}=t,{ex:w,ey:A,ez:N}=this,R=u(w*w),K=u(A*A),M=u(ti*u(N*N)),O=u(m*R),V=w+A,rt=u(u(V*V)-R-K),Q=O+K,ct=Q-M,bt=O-K,it=u(rt*ct),ut=u(Q*bt),At=u(rt*bt),Lt=u(ct*Q);return new p(it,ut,Lt,At)}add(m){h(m);let{a:w,d:A}=t,{ex:N,ey:R,ez:K,et:M}=this,{ex:O,ey:V,ez:rt,et:Q}=m,ct=u(N*O),bt=u(R*V),it=u(M*A*Q),ut=u(K*rt),At=u((N+R)*(O+V)-ct-bt),Lt=ut-it,He=ut+it,es=u(bt-w*ct),ua=u(At*Lt),fa=u(He*es),la=u(At*es),ha=u(Lt*He);return new p(ua,fa,ha,la)}subtract(m){return this.add(m.negate())}wNAF(m){return C.wNAFCached(this,m,p.normalizeZ)}multiply(m){let w=m;It("scalar",w,mt,n);let{p:A,f:N}=this.wNAF(w);return p.normalizeZ([A,N])[0]}multiplyUnsafe(m,w=p.ZERO){let A=m;return It("scalar",A,Rt,n),A===Rt?P:this.is0()||A===mt?this:C.wNAFCachedUnsafe(this,A,p.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return C.unsafeLadder(this,n).is0()}toAffine(m){return b(this,m)}clearCofactor(){let{h:m}=t;return m===mt?this:this.multiplyUnsafe(m)}static fromHex(m,w=!1){let{d:A,a:N}=t,R=e.BYTES;m=X("pointHex",m,R),kt("zip215",w);let K=m.slice(),M=m[R-1];K[R-1]=M&-129;let O=he(K),V=w?f:e.ORDER;It("pointHex.y",O,Rt,V);let rt=u(O*O),Q=u(rt-mt),ct=u(A*rt-N),{isValid:bt,value:it}=d(Q,ct);if(!bt)throw new Error("Point.fromHex: invalid y coordinate");let ut=(it&mt)===mt,At=(M&128)!==0;if(!w&&it===Rt&&At)throw new Error("Point.fromHex: x=0 and x_0=1");return At!==ut&&(it=u(-it)),p.fromAffine({x:it,y:O})}static fromPrivateKey(m){let{scalar:w}=T(m);return I.multiply(w)}toRawBytes(){let{x:m,y:w}=this.toAffine(),A=Re(w,e.BYTES);return A[A.length-1]|=m&mt?128:0,A}toHex(){return ee(this.toRawBytes())}}p.BASE=new p(t.Gx,t.Gy,mt,u(t.Gx*t.Gy)),p.ZERO=new p(Rt,mt,mt,Rt);let{BASE:I,ZERO:P}=p,C=Pr(p,a*8);function _(g){return z(g,n)}function L(g){return _(he(g))}function T(g){let m=e.BYTES;g=X("private key",g,m);let w=X("hashed private key",s(g),2*m),A=x(w.slice(0,m)),N=w.slice(m,2*m),R=L(A);return{head:A,prefix:N,scalar:R}}function G(g){let{head:m,prefix:w,scalar:A}=T(g),N=I.multiply(A),R=N.toRawBytes();return{head:m,prefix:w,scalar:A,point:N,pointBytes:R}}function q(g){return G(g).pointBytes}function U(g=new Uint8Array,...m){let w=re(...m);return L(s(E(w,X("context",g),!!o)))}function nt(g,m,w={}){g=X("message",g),o&&(g=o(g));let{prefix:A,scalar:N,pointBytes:R}=G(m),K=U(w.context,A,g),M=I.multiply(K).toRawBytes(),O=U(w.context,M,R,g),V=_(K+O*N);It("signature.s",V,Rt,n);let rt=re(M,Re(V,e.BYTES));return X("result",rt,e.BYTES*2)}let S=Lu;function B(g,m,w,A=S){let{context:N,zip215:R}=A,K=e.BYTES;g=X("signature",g,2*K),m=X("message",m),w=X("publicKey",w,K),R!==void 0&&kt("zip215",R),o&&(m=o(m));let M=he(g.slice(K,2*K)),O,V,rt;try{O=p.fromHex(w,R),V=p.fromHex(g.slice(0,K),R),rt=I.multiplyUnsafe(M)}catch{return!1}if(!R&&O.isSmallOrder())return!1;let Q=U(N,V.toRawBytes(),O.toRawBytes(),m);return V.add(O.multiplyUnsafe(Q)).subtract(rt).clearCofactor().equals(p.ZERO)}return I._setWindowSize(8),{CURVE:t,getPublicKey:q,sign:nt,verify:B,ExtendedPoint:p,utils:{getExtendedPublicKey:G,randomPrivateKey:()=>i(e.BYTES),precompute(g=8,m=p.BASE){return m._setWindowSize(g),m.multiply(BigInt(3)),m}}}}var oo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ri=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),bd=BigInt(0),Du=BigInt(1),ni=BigInt(2),gd=BigInt(3),Pu=BigInt(5),Cu=BigInt(8);function Nu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=oo,a=r*r%s*r%s,c=W(a,ni,s)*a%s,f=W(c,Du,s)*r%s,u=W(f,Pu,s)*f%s,l=W(u,t,s)*u%s,d=W(l,e,s)*l%s,x=W(d,n,s)*d%s,E=W(x,o,s)*x%s,y=W(E,o,s)*x%s,h=W(y,t,s)*u%s;return{pow_p_5_8:W(h,ni,s)*r%s,b2:a}}function ku(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Ru(r,t){let e=oo,n=z(t*t*t,e),o=z(n*n*t,e),s=Nu(r*o).pow_p_5_8,i=z(r*n*s,e),a=z(t*i*i,e),c=i,f=z(i*ri,e),u=a===r,l=a===z(-r,e),d=a===z(-r*ri,e);return u&&(i=c),(l||d)&&(i=f),Ys(i,e)&&(i=z(-i,e)),{isValid:u||l,value:i}}var oi=ne(oo,void 0,!0),Uu={a:oi.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:oi,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Cu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:zn,randomBytes:Ne,adjustScalarBytes:ku,uvRatio:Ru},si=ei(Uu);var Nr=32;function ii(r,t,e){return si.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var kr=class{type="Ed25519";raw;constructor(t){this.raw=so(t,Nr)}toMultihash(){return Dt.digest(qt(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:xt(this.raw,t.raw)}verify(t,e){return ii(this.raw,e,t)}};function io(r){return r=so(r,Nr),new kr(r)}function so(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 Mu=Math.pow(2,7),Ou=Math.pow(2,14),qu=Math.pow(2,21),ao=Math.pow(2,28),co=Math.pow(2,35),uo=Math.pow(2,42),fo=Math.pow(2,49),H=128,ht=127;function Ct(r){if(r<Mu)return 1;if(r<Ou)return 2;if(r<qu)return 3;if(r<ao)return 4;if(r<co)return 5;if(r<uo)return 6;if(r<fo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function lo(r,t,e=0){switch(Ct(r)){case 8:t[e++]=r&255|H,r/=128;case 7:t[e++]=r&255|H,r/=128;case 6:t[e++]=r&255|H,r/=128;case 5:t[e++]=r&255|H,r/=128;case 4:t[e++]=r&255|H,r>>>=7;case 3:t[e++]=r&255|H,r>>>=7;case 2:t[e++]=r&255|H,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Hu(r,t,e=0){switch(Ct(r)){case 8:t.set(e++,r&255|H),r/=128;case 7:t.set(e++,r&255|H),r/=128;case 6:t.set(e++,r&255|H),r/=128;case 5:t.set(e++,r&255|H),r/=128;case 4:t.set(e++,r&255|H),r>>>=7;case 3:t.set(e++,r&255|H),r>>>=7;case 2:t.set(e++,r&255|H),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ho(r,t){let e=r[t],n=0;if(n+=e&ht,e<H||(e=r[t+1],n+=(e&ht)<<7,e<H)||(e=r[t+2],n+=(e&ht)<<14,e<H)||(e=r[t+3],n+=(e&ht)<<21,e<H)||(e=r[t+4],n+=(e&ht)*ao,e<H)||(e=r[t+5],n+=(e&ht)*co,e<H)||(e=r[t+6],n+=(e&ht)*uo,e<H)||(e=r[t+7],n+=(e&ht)*fo,e<H))return n;throw new RangeError("Could not decode varint")}function Vu(r,t){let e=r.get(t),n=0;if(n+=e&ht,e<H||(e=r.get(t+1),n+=(e&ht)<<7,e<H)||(e=r.get(t+2),n+=(e&ht)<<14,e<H)||(e=r.get(t+3),n+=(e&ht)<<21,e<H)||(e=r.get(t+4),n+=(e&ht)*ao,e<H)||(e=r.get(t+5),n+=(e&ht)*co,e<H)||(e=r.get(t+6),n+=(e&ht)*uo,e<H)||(e=r.get(t+7),n+=(e&ht)*fo,e<H))return n;throw new RangeError("Could not decode varint")}function ci(r,t,e=0){return t==null&&(t=lt(Ct(r))),t instanceof Uint8Array?lo(r,t,e):Hu(r,t,e)}function ui(r,t=0){return r instanceof Uint8Array?ho(r,t):Vu(r,t)}var po=new Float32Array([-0]),oe=new Uint8Array(po.buffer);function li(r,t,e){po[0]=r,t[e]=oe[0],t[e+1]=oe[1],t[e+2]=oe[2],t[e+3]=oe[3]}function hi(r,t){return oe[0]=r[t],oe[1]=r[t+1],oe[2]=r[t+2],oe[3]=r[t+3],po[0]}var mo=new Float64Array([-0]),dt=new Uint8Array(mo.buffer);function di(r,t,e){mo[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 pi(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],mo[0]}var zu=BigInt(Number.MAX_SAFE_INTEGER),Fu=BigInt(Number.MIN_SAFE_INTEGER),Bt=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 ye;if(t<zu&&t>Fu)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>mi&&(o=0n,++n>mi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ye;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):ye}},ye=new Bt(0,0);ye.toBigInt=function(){return 0n};ye.zzEncode=ye.zzDecode=function(){return this};ye.length=function(){return 1};var mi=4294967296n;function yi(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 bi(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 yo(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 Nt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Rr(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,Nt(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 Nt(this,4);return Rr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Nt(this,4);return Rr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Nt(this,4);let t=hi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Nt(this,4);let t=pi(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 Nt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return bi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Nt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Nt(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 Bt(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 Nt(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 Nt(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 Nt(this,8);let t=Rr(this.buf,this.pos+=4),e=Rr(this.buf,this.pos+=4);return new Bt(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=ho(this.buf,this.pos);return this.pos+=Ct(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function go(r){return new bo(r instanceof Uint8Array?r:r.subarray())}function Et(r,t,e){let n=go(r);return t.decode(n,void 0,e)}function xo(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 be=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function wo(){}var So=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Gu=xo();function Zu(r){return globalThis.Buffer!=null?lt(r):Gu(r)}var tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new be(wo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new be(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new vo((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(Ur,10,Bt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Bt.fromBigInt(t);return this._push(Ur,e.length(),e)}uint64Number(t){return this._push(lo,Ct(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Bt.fromBigInt(t).zzEncode();return this._push(Ur,e.length(),e)}sint64Number(t){let e=Bt.fromNumber(t).zzEncode();return this._push(Ur,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Eo,1,t?1:0)}fixed32(t){return this._push(Qe,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Bt.fromBigInt(t);return this._push(Qe,4,e.lo)._push(Qe,4,e.hi)}fixed64Number(t){let e=Bt.fromNumber(t);return this._push(Qe,4,e.lo)._push(Qe,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(li,4,t)}double(t){return this._push(di,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Eo,1,0):this.uint32(e)._push(Wu,e,t)}string(t){let e=yi(t);return e!==0?this.uint32(e)._push(yo,e,t):this._push(Eo,1,0)}fork(){return this.states=new So(this),this.head=this.tail=new be(wo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new be(wo,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=Zu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Eo(r,t,e){t[e]=r&255}function Yu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var vo=class extends be{next;constructor(t,e){super(Yu,t,e),this.next=void 0}};function Ur(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 Qe(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 Wu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(tr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push($u,t,r),this},tr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ju,t,r),this});function $u(r,t,e){t.set(r,e)}function ju(r,t,e){r.length<40?yo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Z(r),e)}function Ao(){return new tr}function St(r,t){let e=Ao();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ke;(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"})(Ke||(Ke={}));function Kr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Io(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 Kr("enum",Ke.VARINT,e,n)}function vt(r,t){return Kr("message",Ke.LENGTH_DELIMITED,r,t)}var _t=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var et;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(et||(et={}));var Bo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Bo||(Bo={}));(function(r){r.codec=()=>Io(Bo)})(et||(et={}));var Ut;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),et.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=et.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(Ut||(Ut={}));var _o;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),et.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=et.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(_o||(_o={}));function Mr(r){if(isNaN(r)||r<=0)throw new $("random bytes length must be a Number bigger than 0");return Ne(r)}var er=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Or=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var wi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Or("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 se=wi;var nr={};gt(nr,{MAX_RSA_KEY_SIZE:()=>Lo,generateRSAKeyPair:()=>Ai,jwkToJWKKeyPair:()=>Ii,jwkToPkcs1:()=>tf,jwkToPkix:()=>Co,jwkToRSAPrivateKey:()=>Uo,pkcs1MessageToJwk:()=>Do,pkcs1MessageToRSAPrivateKey:()=>No,pkcs1ToJwk:()=>Qu,pkcs1ToRSAPrivateKey:()=>vi,pkixMessageToJwk:()=>Po,pkixMessageToRSAPublicKey:()=>Ro,pkixToJwk:()=>ef,pkixToRSAPublicKey:()=>ko});var Me=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=nr.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:xt(this.raw,t.raw)}verify(t,e){return Si(this.jwk,e,t)}},rr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=nr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}sign(t){return Ei(this.jwk,t)}};var Lo=8192,To=18,Xu=1062,Ju=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Qu(r){let t=Ot(r);return Do(t)}function Do(r){return{n:F(r[1],"base64url"),e:F(r[2],"base64url"),d:F(r[3],"base64url"),p:F(r[4],"base64url"),q:F(r[5],"base64url"),dp:F(r[6],"base64url"),dq:F(r[7],"base64url"),qi:F(r[8],"base64url"),kty:"RSA"}}function tf(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 jt([wt(Uint8Array.from([0])),wt(Z(r.n,"base64url")),wt(Z(r.e,"base64url")),wt(Z(r.d,"base64url")),wt(Z(r.p,"base64url")),wt(Z(r.q,"base64url")),wt(Z(r.dp,"base64url")),wt(Z(r.dq,"base64url")),wt(Z(r.qi,"base64url"))]).subarray()}function ef(r){let t=Ot(r,{offset:0});return Po(t)}function Po(r){let t=Ot(r[1],{offset:0});return{kty:"RSA",n:F(t[0],"base64url"),e:F(t[1],"base64url")}}function Co(r){if(r.n==null||r.e==null)throw new $("JWK was missing components");return jt([Ju,Ir(jt([wt(Z(r.n,"base64url")),wt(Z(r.e,"base64url"))]))]).subarray()}function vi(r){let t=Ot(r);return No(t)}function No(r){let t=Do(r);return Uo(t)}function ko(r,t){if(r.byteLength>=Xu)throw new Se("Key size is too large");let e=Ot(r,{offset:0});return Ro(e,r,t)}function Ro(r,t,e){let n=Po(r);if(e==null){let o=fe(Ut.encode({Type:et.RSA,Data:t}));e=Tt(To,o)}return new Me(n,e)}function Uo(r){if(_i(r)>Lo)throw new $("Key size is too large");let t=Ii(r),e=fe(Ut.encode({Type:et.RSA,Data:Co(t.publicKey)})),n=Tt(To,e);return new rr(t.privateKey,new Me(t.publicKey,n))}async function Ai(r){if(r>Lo)throw new $("Key size is too large");let t=await Bi(r),e=fe(Ut.encode({Type:et.RSA,Data:Co(t.publicKey)})),n=Tt(To,e);return new rr(t.privateKey,new Me(t.publicKey,n))}function Ii(r){if(r==null)throw new $("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Bi(r){let t=await se.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 rf(t);return{privateKey:e[0],publicKey:e[1]}}async function Ei(r,t){let e=await se.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await se.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Si(r,t,e){let n=await se.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return se.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function rf(r){if(r.privateKey==null||r.publicKey==null)throw new $("Private and public key are required");return Promise.all([se.get().subtle.exportKey("jwk",r.privateKey),se.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 qr=class extends Ce{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ns(t);let n=$e(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),s.fill(0)}update(t){return Pe(this),this.iHash.update(t),this}digestInto(t){Pe(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}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ko=(r,t,e)=>new qr(r,t).update(e).digest();Ko.create=(r,t)=>new qr(r,t);function Li(r){r.lowS!==void 0&&kt("lowS",r.lowS),r.prehash!==void 0&&kt("prehash",r.prehash)}function nf(r){let t=Je(r);zt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var Mo=class extends Error{constructor(t=""){super(t)}},Ft={Err:Mo,_tlv:{encode:(r,t)=>{let{Err:e}=Ft;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=je(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?je(o.length/2|128):"";return je(r)+s+o+t},decode(r,t){let{Err:e}=Ft,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}=Ft;if(r<Gt)throw new t("integer: negative integers are not allowed");let e=je(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}=Ft;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 Vt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Ft,o=X("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}=Ft,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Gt=BigInt(0),at=BigInt(1),Yp=BigInt(2),Ti=BigInt(3),Wp=BigInt(4);function of(r){let t=nf(r),{Fp:e}=t,n=ne(t.n,t.nBitLength),o=t.toBytes||((y,h,b)=>{let v=h.toAffine();return re(Uint8Array.from([4]),e.toBytes(v.x),e.toBytes(v.y))}),s=t.fromBytes||(y=>{let h=y.subarray(1),b=e.fromBytes(h.subarray(0,e.BYTES)),v=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:b,y:v}});function i(y){let{a:h,b}=t,v=e.sqr(y),p=e.mul(v,y);return e.add(e.add(p,e.mul(y,h)),b)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(y){return Tr(y,at,t.n)}function c(y){let{allowedPrivateKeyLengths:h,nByteLength:b,wrapPrivateKey:v,n:p}=t;if(h&&typeof y!="bigint"){if(le(y)&&(y=ee(y)),typeof y!="string"||!h.includes(y.length))throw new Error("invalid private key");y=y.padStart(b*2,"0")}let I;try{I=typeof y=="bigint"?y:Vt(X("private key",y,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof y)}return v&&(I=z(I,p)),It("private key",I,at,p),I}function f(y){if(!(y instanceof d))throw new Error("ProjectivePoint expected")}let u=Ue((y,h)=>{let{px:b,py:v,pz:p}=y;if(e.eql(p,e.ONE))return{x:b,y:v};let I=y.is0();h==null&&(h=I?e.ONE:e.inv(p));let P=e.mul(b,h),C=e.mul(v,h),_=e.mul(p,h);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(_,e.ONE))throw new Error("invZ was invalid");return{x:P,y:C}}),l=Ue(y=>{if(y.is0()){if(t.allowInfinityPoint&&!e.is0(y.py))return;throw new Error("bad point: ZERO")}let{x:h,y:b}=y.toAffine();if(!e.isValid(h)||!e.isValid(b))throw new Error("bad point: x or y not FE");let v=e.sqr(b),p=i(h);if(!e.eql(v,p))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,b,v){if(h==null||!e.isValid(h))throw new Error("x required");if(b==null||!e.isValid(b))throw new Error("y required");if(v==null||!e.isValid(v))throw new Error("z required");this.px=h,this.py=b,this.pz=v,Object.freeze(this)}static fromAffine(h){let{x:b,y:v}=h||{};if(!h||!e.isValid(b)||!e.isValid(v))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let p=I=>e.eql(I,e.ZERO);return p(b)&&p(v)?d.ZERO:new d(b,v,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let b=e.invertBatch(h.map(v=>v.pz));return h.map((v,p)=>v.toAffine(b[p])).map(d.fromAffine)}static fromHex(h){let b=d.fromAffine(s(X("pointHex",h)));return b.assertValidity(),b}static fromPrivateKey(h){return d.BASE.multiply(c(h))}static msm(h,b){return Cr(d,n,h,b)}_setWindowSize(h){E.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);let{px:b,py:v,pz:p}=this,{px:I,py:P,pz:C}=h,_=e.eql(e.mul(b,C),e.mul(I,p)),L=e.eql(e.mul(v,C),e.mul(P,p));return _&&L}negate(){return new d(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b}=t,v=e.mul(b,Ti),{px:p,py:I,pz:P}=this,C=e.ZERO,_=e.ZERO,L=e.ZERO,T=e.mul(p,p),G=e.mul(I,I),q=e.mul(P,P),U=e.mul(p,I);return U=e.add(U,U),L=e.mul(p,P),L=e.add(L,L),C=e.mul(h,L),_=e.mul(v,q),_=e.add(C,_),C=e.sub(G,_),_=e.add(G,_),_=e.mul(C,_),C=e.mul(U,C),L=e.mul(v,L),q=e.mul(h,q),U=e.sub(T,q),U=e.mul(h,U),U=e.add(U,L),L=e.add(T,T),T=e.add(L,T),T=e.add(T,q),T=e.mul(T,U),_=e.add(_,T),q=e.mul(I,P),q=e.add(q,q),T=e.mul(q,U),C=e.sub(C,T),L=e.mul(q,G),L=e.add(L,L),L=e.add(L,L),new d(C,_,L)}add(h){f(h);let{px:b,py:v,pz:p}=this,{px:I,py:P,pz:C}=h,_=e.ZERO,L=e.ZERO,T=e.ZERO,G=t.a,q=e.mul(t.b,Ti),U=e.mul(b,I),nt=e.mul(v,P),S=e.mul(p,C),B=e.add(b,v),D=e.add(I,P);B=e.mul(B,D),D=e.add(U,nt),B=e.sub(B,D),D=e.add(b,p);let g=e.add(I,C);return D=e.mul(D,g),g=e.add(U,S),D=e.sub(D,g),g=e.add(v,p),_=e.add(P,C),g=e.mul(g,_),_=e.add(nt,S),g=e.sub(g,_),T=e.mul(G,D),_=e.mul(q,S),T=e.add(_,T),_=e.sub(nt,T),T=e.add(nt,T),L=e.mul(_,T),nt=e.add(U,U),nt=e.add(nt,U),S=e.mul(G,S),D=e.mul(q,D),nt=e.add(nt,S),S=e.sub(U,S),S=e.mul(G,S),D=e.add(D,S),U=e.mul(nt,D),L=e.add(L,U),U=e.mul(g,D),_=e.mul(B,_),_=e.sub(_,U),U=e.mul(B,nt),T=e.mul(g,T),T=e.add(T,U),new d(_,L,T)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return E.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:b,n:v}=t;It("scalar",h,Gt,v);let p=d.ZERO;if(h===Gt)return p;if(this.is0()||h===at)return this;if(!b||E.hasPrecomputes(this))return E.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:I,k1:P,k2neg:C,k2:_}=b.splitScalar(h),L=p,T=p,G=this;for(;P>Gt||_>Gt;)P&at&&(L=L.add(G)),_&at&&(T=T.add(G)),G=G.double(),P>>=at,_>>=at;return I&&(L=L.negate()),C&&(T=T.negate()),T=new d(e.mul(T.px,b.beta),T.py,T.pz),L.add(T)}multiply(h){let{endo:b,n:v}=t;It("scalar",h,at,v);let p,I;if(b){let{k1neg:P,k1:C,k2neg:_,k2:L}=b.splitScalar(h),{p:T,f:G}=this.wNAF(C),{p:q,f:U}=this.wNAF(L);T=E.constTimeNegate(P,T),q=E.constTimeNegate(_,q),q=new d(e.mul(q.px,b.beta),q.py,q.pz),p=T.add(q),I=G.add(U)}else{let{p:P,f:C}=this.wNAF(h);p=P,I=C}return d.normalizeZ([p,I])[0]}multiplyAndAddUnsafe(h,b,v){let p=d.BASE,I=(C,_)=>_===Gt||_===at||!C.equals(p)?C.multiplyUnsafe(_):C.multiply(_),P=I(this,b).add(I(h,v));return P.is0()?void 0:P}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:b}=t;if(h===at)return!0;if(b)return b(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:b}=t;return h===at?this:b?b(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return kt("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return kt("isCompressed",h),ee(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,e.ONE),d.ZERO=new d(e.ZERO,e.ONE,e.ZERO);let x=t.nBitLength,E=Pr(d,t.endo?Math.ceil(x/2):x);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function sf(r){let t=Je(r);return zt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Di(r){let t=sf(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(S){return z(S,n)}function a(S){return Dr(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=of({...t,toBytes(S,B,D){let g=B.toAffine(),m=e.toBytes(g.x),w=re;return kt("isCompressed",D),D?w(Uint8Array.from([B.hasEvenY()?2:3]),m):w(Uint8Array.from([4]),m,e.toBytes(g.y))},fromBytes(S){let B=S.length,D=S[0],g=S.subarray(1);if(B===o&&(D===2||D===3)){let m=Vt(g);if(!Tr(m,at,e.ORDER))throw new Error("Point is not on curve");let w=u(m),A;try{A=e.sqrt(w)}catch(K){let M=K instanceof Error?": "+K.message:"";throw new Error("Point is not on curve"+M)}let N=(A&at)===at;return(D&1)===1!==N&&(A=e.neg(A)),{x:m,y:A}}else if(B===s&&D===4){let m=e.fromBytes(g.subarray(0,e.BYTES)),w=e.fromBytes(g.subarray(e.BYTES,2*e.BYTES));return{x:m,y:w}}else{let m=o,w=s;throw new Error("invalid Point, expected length of "+m+", or uncompressed "+w+", got "+B)}}}),d=S=>ee(de(S,t.nByteLength));function x(S){let B=n>>at;return S>B}function E(S){return x(S)?i(-S):S}let y=(S,B,D)=>Vt(S.slice(B,D));class h{constructor(B,D,g){It("r",B,at,n),It("s",D,at,n),this.r=B,this.s=D,g!=null&&(this.recovery=g),Object.freeze(this)}static fromCompact(B){let D=t.nByteLength;return B=X("compactSignature",B,D*2),new h(y(B,0,D),y(B,D,2*D))}static fromDER(B){let{r:D,s:g}=Ft.toSig(X("DER",B));return new h(D,g)}assertValidity(){}addRecoveryBit(B){return new h(this.r,this.s,B)}recoverPublicKey(B){let{r:D,s:g,recovery:m}=this,w=C(X("msgHash",B));if(m==null||![0,1,2,3].includes(m))throw new Error("recovery id invalid");let A=m===2||m===3?D+t.n:D;if(A>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let N=(m&1)===0?"02":"03",R=c.fromHex(N+d(A)),K=a(A),M=i(-w*K),O=i(g*K),V=c.BASE.multiplyAndAddUnsafe(R,M,O);if(!V)throw new Error("point at infinify");return V.assertValidity(),V}hasHighS(){return x(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return Xe(this.toDERHex())}toDERHex(){return Ft.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Xe(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let b={isValidPrivateKey(S){try{return f(S),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let S=Jn(t.n);return $s(t.randomBytes(S),t.n)},precompute(S=8,B=c.BASE){return B._setWindowSize(S),B.multiply(BigInt(3)),B}};function v(S,B=!0){return c.fromPrivateKey(S).toRawBytes(B)}function p(S){let B=le(S),D=typeof S=="string",g=(B||D)&&S.length;return B?g===o||g===s:D?g===2*o||g===2*s:S instanceof c}function I(S,B,D=!0){if(p(S))throw new Error("first arg must be private key");if(!p(B))throw new Error("second arg must be public key");return c.fromHex(B).multiply(f(S)).toRawBytes(D)}let P=t.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let B=Vt(S),D=S.length*8-t.nBitLength;return D>0?B>>BigInt(D):B},C=t.bits2int_modN||function(S){return i(P(S))},_=pe(t.nBitLength);function L(S){return It("num < 2^"+t.nBitLength,S,Gt,_),de(S,t.nByteLength)}function T(S,B,D=G){if(["recovered","canonical"].some(Q=>Q in D))throw new Error("sign() legacy options not supported");let{hash:g,randomBytes:m}=t,{lowS:w,prehash:A,extraEntropy:N}=D;w==null&&(w=!0),S=X("msgHash",S),Li(D),A&&(S=X("prehashed msgHash",g(S)));let R=C(S),K=f(B),M=[L(K),L(R)];if(N!=null&&N!==!1){let Q=N===!0?m(e.BYTES):N;M.push(X("extraEntropy",Q))}let O=re(...M),V=R;function rt(Q){let ct=P(Q);if(!l(ct))return;let bt=a(ct),it=c.BASE.multiply(ct).toAffine(),ut=i(it.x);if(ut===Gt)return;let At=i(bt*i(V+ut*K));if(At===Gt)return;let Lt=(it.x===ut?0:2)|Number(it.y&at),He=At;return w&&x(At)&&(He=E(At),Lt^=1),new h(ut,He,Lt)}return{seed:O,k2sig:rt}}let G={lowS:t.lowS,prehash:!1},q={lowS:t.lowS,prehash:!1};function U(S,B,D=G){let{seed:g,k2sig:m}=T(S,B,D),w=t;return Fs(w.hash.outputLen,w.nByteLength,w.hmac)(g,m)}c.BASE._setWindowSize(8);function nt(S,B,D,g=q){let m=S;B=X("msgHash",B),D=X("publicKey",D);let{lowS:w,prehash:A,format:N}=g;if(Li(g),"strict"in g)throw new Error("options.strict was renamed to lowS");if(N!==void 0&&N!=="compact"&&N!=="der")throw new Error("format must be compact or der");let R=typeof m=="string"||le(m),K=!R&&!N&&typeof m=="object"&&m!==null&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!R&&!K)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let M,O;try{if(K&&(M=new h(m.r,m.s)),R){try{N!=="compact"&&(M=h.fromDER(m))}catch(Lt){if(!(Lt instanceof Ft.Err))throw Lt}!M&&N!=="der"&&(M=h.fromCompact(m))}O=c.fromHex(D)}catch{return!1}if(!M||w&&M.hasHighS())return!1;A&&(B=t.hash(B));let{r:V,s:rt}=M,Q=C(B),ct=a(rt),bt=i(Q*ct),it=i(V*ct),ut=c.BASE.multiplyAndAddUnsafe(O,bt,it)?.toAffine();return ut?i(ut.x)===V:!1}return{CURVE:t,getPublicKey:v,getSharedSecret:I,sign:U,verify:nt,ProjectivePoint:c,Signature:h,utils:b}}function af(r){return{hash:r,hmac:(t,...e)=>Ko(r,t,On(...e)),randomBytes:Ne}}function Pi(r,t){let e=n=>Di({...r,...af(n)});return{...e(t),create:e}}var ki=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ci=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),cf=BigInt(1),Oo=BigInt(2),Ni=(r,t)=>(r+t/Oo)/t;function uf(r){let t=ki,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,d=W(l,e,t)*u%t,x=W(d,Oo,t)*f%t,E=W(x,o,t)*x%t,y=W(E,s,t)*E%t,h=W(y,a,t)*y%t,b=W(h,c,t)*h%t,v=W(b,a,t)*y%t,p=W(v,e,t)*u%t,I=W(p,i,t)*E%t,P=W(I,n,t)*f%t,C=W(P,Oo,t);if(!qo.eql(qo.sqr(C),r))throw new Error("Cannot find square root");return C}var qo=ne(ki,void 0,void 0,{sqrt:uf}),ge=Pi({a:BigInt(0),b:BigInt(7),Fp:qo,n:Ci,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ci,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-cf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=Ni(s*r,t),c=Ni(-n*r,t),f=z(r-a*e-c*o,t),u=z(-a*n-c*s,t),l=f>i,d=u>i;if(l&&(f=t-f),d&&(u=t-u),f>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:d,k2:u}}}},fe),n0=BigInt(0);var o0=ge.ProjectivePoint;function Ri(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Ui(r,t,e){let n=ce.digest(e instanceof Uint8Array?e:e.subarray());if(Ri(n))return n.then(({digest:o})=>ge.verify(t,o,r)).catch(o=>{throw new er(String(o))});try{return ge.verify(t,n.digest,r)}catch(o){throw new er(String(o))}}var Hr=class{type="secp256k1";raw;_key;constructor(t){this._key=Mi(t),this.raw=Ki(this._key)}toMultihash(){return Dt.digest(qt(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:xt(this.raw,t.raw)}verify(t,e){return Ui(this._key,e,t)}};function Ho(r){return new Hr(r)}function Ki(r){return ge.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Mi(r){try{return ge.ProjectivePoint.fromHex(r),r}catch(t){throw new Se(String(t))}}function Vo(r,t){let{Type:e,Data:n}=Ut.decode(r),o=n??new Uint8Array;switch(e){case et.RSA:return ko(o,t);case et.Ed25519:return io(o);case et.secp256k1:return Ho(o);case et.ECDSA:return Mn(o);default:throw new ie}}function Oi(r){let{Type:t,Data:e}=Ut.decode(r.digest),n=e??new Uint8Array;switch(t){case et.Ed25519:return io(n);case et.secp256k1:return Ho(n);case et.ECDSA:return Mn(n);default:throw new ie}}function qt(r){return Ut.encode({Type:et[r.type],Data:r.raw})}var qi=Symbol.for("nodejs.util.inspect.custom"),ff=114,or=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()})`}[fn]=!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 xt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return xt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[qi](){return`PeerId(${this.toString()})`}},sr=class extends or{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},ir=class extends or{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},ar=class extends or{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},lf=2336,Vr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Dt.digest(Z(this.url))}[qi](){return`PeerId(${this.url})`}[fn]=!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=F(t)),t.toString()===this.toString())}};function zo(r){if(r.type==="Ed25519")return new ir({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new ar({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new sr({multihash:r.toCID().multihash,publicKey:r});throw new ie}function Hi(r){return zo(r.publicKey)}function cr(r){if(df(r))return new sr({multihash:r});if(hf(r))try{let t=Oi(r);if(t.type==="Ed25519")return new ir({multihash:r,publicKey:t});if(t.type==="secp256k1")return new ar({multihash:r,publicKey:t})}catch{let e=F(r.digest);return new Vr(new URL(e))}throw new wr("Supplied PeerID Multihash is invalid")}function hf(r){return r.code===Dt.code}function df(r){return r.code===ce.code}function xe(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 zr(r){let t=Wt(j.decode(`z${r}`));return cr(t)}var ur=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 xe(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 xe(this.map.values(),t=>t.key)}values(){return xe(this.map.values(),t=>t.value)}get size(){return this.map.size}};var fr=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 xe(this.set.entries(),t=>{let e=zr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=zr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return xe(this.set.values(),t=>zr(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 Zt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Fr=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}},Oe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Fr(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 Fr(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 Fo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Gr(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 Oe,o,s,i,a=Zt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,b)=>{s=v=>{s=null,n.push(v);try{h(r(n))}catch(p){b(p)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Zt()})}},f=h=>s!=null?s(h):(n.push(h),o),u=h=>(n=new Oe,s!=null?s({error:h}):(n.push({error:h}),o)),l=h=>{if(i)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:h})},d=h=>i?o:(i=!0,h!=null?u(h):f({done:!0})),x=()=>(n=new Oe,d(),{done:!0}),E=h=>(d(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:x,throw:E,push:l,end:d,get readableLength(){return n.size},onEmpty:async h=>{let b=h?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let v,p;b!=null&&(v=new Promise((I,P)=>{p=()=>{P(new Fo)},b.addEventListener("abort",p)}));try{await Promise.race([a.promise,v])}finally{p!=null&&b!=null&&b?.removeEventListener("abort",p)}}},e==null)return o;let y=o;return o={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(h){return y.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return y.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(h){return y.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return y.readableLength},onEmpty:h=>y.onEmpty(h)},o}var Zr=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Vi(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Zr(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Zr(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 Go=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Zt(),this.haveNext=Zt()}[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=Zt(),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=Zt(),await Vi(this.readNext.promise,e?.signal,e)}};function zi(){return new Go}function mf(r){return r[Symbol.asyncIterator]!=null}async function yf(r,t){try{await Promise.all(r.map(async e=>{for await(let n of e)await t.push(n)})),await t.end()}catch(e){await t.end(e).catch(()=>{})}}async function*bf(r){let t=zi();yf(r,t).catch(()=>{}),yield*t}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 Fi=xf;function lr(r,...t){if(r==null)throw new Error("Empty pipeline");if(Zo(r)){let n=r;r=()=>n.source}else if(Zi(r)||Gi(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Zo(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++)Zo(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},Gi=r=>r?.[Symbol.asyncIterator]!=null,Zi=r=>r?.[Symbol.iterator]!=null,Zo=r=>r==null?!1:r.sink!=null&&r.source!=null,Ef=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Gr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Gi(s))o=async function*(){yield*s,n.end()};else if(Zi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Fi(n,o())}return r.source};var Wo=xa(Wi(),1);var dr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},$o=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},$i=r=>globalThis.DOMException===void 0?new $o(r):new DOMException(r),ji=r=>{let t=r.reason===void 0?$i("This operation was aborted."):r.reason;return t instanceof Error?t:$i(t)};function jo(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:x}=t;x.aborted&&l(ji(x)),a=()=>{l(ji(x))},x.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,l);return}let d=new dr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(x){l(x)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?l(o):(d.message=o??`Promise timed out after ${e} milliseconds`,l(d))},e),(async()=>{try{u(await r)}catch(x){l(x)}})()}).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 Xo(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 pr=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=Xo(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 mr=class extends Wo.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:pr,...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=jo(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 dr&&!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 Xi(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 Ji(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Qi(r,t){let e=Xi(r).return?.();Ji(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var Wr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},qe=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},$r=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},yr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function jr(r){return r[Symbol.asyncIterator]!=null}function ta(r,t){if(r.byteLength>t)throw new qe("Message length too long")}var Jr=r=>{let t=Ct(r),e=lt(t);return ci(r,e),Jr.bytes=t,e};Jr.bytes=0;function Qr(r,t){t=t??{};let e=t.lengthEncoder??Jr,n=t?.maxDataLength??4194304;function*o(s){ta(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return jr(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}Qr.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Jr,n=t?.maxDataLength??4194304;return ta(r,n),new ot(e(r.byteLength),r)};var we;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(we||(we={}));var Jo=r=>{let t=ui(r);return Jo.bytes=Ct(t),t};Jo.bytes=0;function br(r,t){let e=new ot,n=we.LENGTH,o=-1,s=t?.lengthDecoder??Jo,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===we.LENGTH)try{if(o=s(e),o<0)throw new Wr("Invalid message length");if(o>a)throw new qe("Message length too long");let f=s.bytes;e.consume(f),t?.onLength!=null&&t.onLength(o),n=we.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>i)throw new $r("Message length length too long");break}throw f}if(n===we.DATA){if(e.byteLength<o)break;let f=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(f),yield f,n=we.LENGTH}}}return jr(r)?async function*(){for await(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new yr("Unexpected end of input")}():function*(){for(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new yr("Unexpected end of input")}()}br.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 br(n,{...t??{},onLength:s=>{e=s}})};var tn=class extends ve{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 ot(t):t)}attachInboundStream(t,e){let n=()=>{Qi(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=lr(this._rawInboundStream,o=>br(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=Gr({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"))}}),lr(this.outboundStream,n=>Qr(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),e==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function ea(){return BigInt(`0x${F(Mr(8),"base16")}`)}var ra=(r,t)=>{let e=Z(t.toString(16).padStart(16,"0"),"base16"),n=qt(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},na=r=>ce.encode(r);var oa=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=cr(Wt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return zo(Vo(e)).equals(t)}return!1},sa=async r=>{if(r.from==null)throw new tt("RPC message was missing from");if(!await Bf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=cr(Wt(r.from)),e=r.key??t.publicKey;if(e==null)throw new tt("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?Vo(e):e}},gr=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?qt(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${F(r,"base16")}`);var ia=Z("libp2p-pubsub:");async function aa(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Hi(r)},o=ae([ia,e(gr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function ca(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=ae([ia,t({...gr(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 en=class extends ve{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=oa(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new ur,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new mr({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 tn(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 lr(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 sa(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 fr,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 tt('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new tt("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new tt("Need key when signature policy is StrictSign but it was missing");return ra(t.key,t.sequenceNumber);case"StrictNoSign":return na(t.data);default:throw new tt("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(gr)})}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 tt('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new tt("StrictNoSigning: signature should not be present");if(e.key!=null)throw new tt("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new tt("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new tt('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new tt("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new tt("StrictSigning: Signing required and no sequenceNumber was present");if(!await ca(e,this.encodeMessage.bind(this)))throw new tt("StrictSigning: Invalid message signature");break;default:throw new tt("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===Ve.Reject||s===Ve.Ignore)throw new tt("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return aa(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new tt("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Er("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:ea()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let e=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,e),e){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};var rn=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 Qo="/floodsub/1.0.0";var Ee;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=vt((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=>St(i,o.codec()),o.decode=(i,a)=>Et(i,o.codec(),a)})(t=r.SubOpts||(r.SubOpts={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=vt((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=>St(i,o.codec()),o.decode=(i,a)=>Et(i,o.codec(),a)})(e=r.Message||(r.Message={}));let n;r.codec=()=>(n==null&&(n=vt((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),nn.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 _t('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 _t('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=nn.codec().decode(o,o.uint32(),{limits:i.limits?.control});break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>St(o,r.codec()),r.decode=(o,s)=>Et(o,r.codec(),s)})(Ee||(Ee={}));var nn;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.ihave!=null)for(let s of e.ihave)n.uint32(10),on.codec().encode(s,n);if(e.iwant!=null)for(let s of e.iwant)n.uint32(18),sn.codec().encode(s,n);if(e.graft!=null)for(let s of e.graft)n.uint32(26),an.codec().encode(s,n);if(e.prune!=null)for(let s of e.prune)n.uint32(34),cn.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 _t('Decode error - map field "ihave" had too many elements');s.ihave.push(on.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 _t('Decode error - map field "iwant" had too many elements');s.iwant.push(sn.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 _t('Decode error - map field "graft" had too many elements');s.graft.push(an.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 _t('Decode error - map field "prune" had too many elements');s.prune.push(cn.codec().decode(e,e.uint32(),{limits:o.limits?.prune$}));break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(nn||(nn={}));var on;(function(r){let t;r.codec=()=>(t==null&&(t=vt((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 _t('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=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(on||(on={}));var sn;(function(r){let t;r.codec=()=>(t==null&&(t=vt((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 _t('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=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(sn||(sn={}));var an;(function(r){let t;r.codec=()=>(t==null&&(t=vt((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=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(an||(an={}));var cn;(function(r){let t;r.codec=()=>(t==null&&(t=vt((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),un.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 _t('Decode error - map field "peers" had too many elements');s.peers.push(un.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=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(cn||(cn={}));var un;(function(r){let t;r.codec=()=>(t==null&&(t=vt((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=>St(e,r.codec()),r.decode=(e,n)=>Et(e,r.codec(),n)})(un||(un={}));var ts=class extends en{seenCache;constructor(t,e){super(t,{...e,canRelayMessage:!0,multicodecs:[Qo]}),this.log=t.logger.forComponent("libp2p:floodsub"),this.seenCache=new rn({validityMs:e?.seenTTL??3e4})}[ns]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[os]=["@libp2p/pubsub"];[ss]=["@libp2p/identify"];decodeRpc(t){return Ee.decode(t)}encodeRpc(t){return Ee.encode(t)}decodeMessage(t){return Ee.Message.decode(t)}encodeMessage(t){return Ee.Message.encode(t)}async processMessage(t,e){let n=await super.getMsgId(e),o=F(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 ts(t,r)}return wa(Pf);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/floodsub",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.33",
|
|
4
4
|
"description": "libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/pubsub-floodsub#readme",
|
|
@@ -60,18 +60,18 @@
|
|
|
60
60
|
"test:electron-main": "aegir test -t electron-main"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@libp2p/interface": "^2.
|
|
64
|
-
"@libp2p/pubsub": "^10.1.
|
|
63
|
+
"@libp2p/interface": "^2.9.0",
|
|
64
|
+
"@libp2p/pubsub": "^10.1.10",
|
|
65
65
|
"protons-runtime": "^5.5.0",
|
|
66
66
|
"uint8arraylist": "^2.4.8",
|
|
67
67
|
"uint8arrays": "^5.1.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@libp2p/crypto": "^5.1.
|
|
71
|
-
"@libp2p/interface-compliance-tests": "^6.4.
|
|
72
|
-
"@libp2p/logger": "^5.1.
|
|
73
|
-
"@libp2p/peer-collections": "^6.0.
|
|
74
|
-
"@libp2p/peer-id": "^5.1.
|
|
70
|
+
"@libp2p/crypto": "^5.1.1",
|
|
71
|
+
"@libp2p/interface-compliance-tests": "^6.4.4",
|
|
72
|
+
"@libp2p/logger": "^5.1.15",
|
|
73
|
+
"@libp2p/peer-collections": "^6.0.27",
|
|
74
|
+
"@libp2p/peer-id": "^5.1.2",
|
|
75
75
|
"@multiformats/multiaddr": "^12.3.3",
|
|
76
76
|
"@types/sinon": "^17.0.3",
|
|
77
77
|
"aegir": "^45.1.1",
|