@libp2p/floodsub 10.1.30 → 10.1.31-71267286
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/typedoc-urls.json +0 -9
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 ac=Object.create;var gr=Object.defineProperty;var uc=Object.getOwnPropertyDescriptor;var fc=Object.getOwnPropertyNames;var lc=Object.getPrototypeOf,hc=Object.prototype.hasOwnProperty;var dc=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),pt=(r,t)=>{for(var e in t)gr(r,e,{get:t[e],enumerable:!0})},ts=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of fc(t))!hc.call(r,o)&&o!==e&&gr(r,o,{get:()=>t[o],enumerable:!(n=uc(t,o))||n.enumerable});return r};var pc=(r,t,e)=>(e=r!=null?ac(lc(r)):{},ts(t||!r||!r.__esModule?gr(e,"default",{value:r,enumerable:!0}):e,r)),mc=r=>ts(gr({},"__esModule",{value:!0}),r);var Ki=dc(($0,Ko)=>{"use strict";var gf=Object.prototype.hasOwnProperty,mt="~";function fr(){}Object.create&&(fr.prototype=Object.create(null),new fr().__proto__||(mt=!1));function yf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Oi(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new yf(e,n||r,o),i=mt?mt+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 Xr(r,t){--r._eventsCount===0?r._events=new fr:delete r._events[t]}function ht(){this._events=new fr,this._eventsCount=0}ht.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)gf.call(e,n)&&t.push(mt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};ht.prototype.listeners=function(t){var e=mt?mt+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};ht.prototype.listenerCount=function(t){var e=mt?mt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};ht.prototype.emit=function(t,e,n,o,s,i){var c=mt?mt+t:t;if(!this._events[c])return!1;var a=this._events[c],f=arguments.length,u,l;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),f){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,e),!0;case 3:return a.fn.call(a.context,e,n),!0;case 4:return a.fn.call(a.context,e,n,o),!0;case 5:return a.fn.call(a.context,e,n,o,s),!0;case 6:return a.fn.call(a.context,e,n,o,s,i),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];a.fn.apply(a.context,u)}else{var p=a.length,x;for(l=0;l<p;l++)switch(a[l].once&&this.removeListener(t,a[l].fn,void 0,!0),f){case 1:a[l].fn.call(a[l].context);break;case 2:a[l].fn.call(a[l].context,e);break;case 3:a[l].fn.call(a[l].context,e,n);break;case 4:a[l].fn.call(a[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];a[l].fn.apply(a[l].context,u)}}return!0};ht.prototype.on=function(t,e,n){return Oi(this,t,e,n,!1)};ht.prototype.once=function(t,e,n){return Oi(this,t,e,n,!0)};ht.prototype.removeListener=function(t,e,n,o){var s=mt?mt+t:t;if(!this._events[s])return this;if(!e)return Xr(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&Xr(this,s);else{for(var c=0,a=[],f=i.length;c<f;c++)(i[c].fn!==e||o&&!i[c].once||n&&i[c].context!==n)&&a.push(i[c]);a.length?this._events[s]=a.length===1?a[0]:a:Xr(this,s)}return this};ht.prototype.removeAllListeners=function(t){var e;return t?(e=mt?mt+t:t,this._events[e]&&Xr(this,e)):(this._events=new fr,this._eventsCount=0),this};ht.prototype.off=ht.prototype.removeListener;ht.prototype.addListener=ht.prototype.on;ht.prefixed=mt;ht.EventEmitter=ht;typeof Ko<"u"&&(Ko.exports=ht)});var If={};pt(If,{floodsub:()=>Bf,multicodec:()=>Go});var dn=Symbol.for("@libp2p/peer-id");var He;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(He||(He={}));var es=Symbol.for("@libp2p/pubsub");var tt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ee=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var yr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var $=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var xr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var se=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Se=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 rs=Symbol.for("@libp2p/service-capabilities"),ns=Symbol.for("@libp2p/service-dependencies");var yn={};pt(yn,{base58btc:()=>j,base58flickr:()=>Ec});var tl=new Uint8Array(0);function os(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 ss(r){return new TextEncoder().encode(r)}function is(r){return new TextDecoder().decode(r)}function bc(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 c=r.length,a=r.charAt(0),f=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);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 g=0,h=0,y=0,S=E.length;y!==S&&E[y]===0;)y++,g++;for(var m=(S-y)*u+1>>>0,B=new Uint8Array(m);y!==S;){for(var D=E[y],N=0,I=m-1;(D!==0||N<h)&&I!==-1;I--,N++)D+=256*B[I]>>>0,B[I]=D%c>>>0,D=D/c>>>0;if(D!==0)throw new Error("Non-zero carry");h=N,y++}for(var _=m-h;_!==m&&B[_]===0;)_++;for(var L=a.repeat(g);_<m;++_)L+=r.charAt(B[_]);return L}function p(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var g=0;if(E[g]!==" "){for(var h=0,y=0;E[g]===a;)h++,g++;for(var S=(E.length-g)*f+1>>>0,m=new Uint8Array(S);E[g];){var B=e[E.charCodeAt(g)];if(B===255)return;for(var D=0,N=S-1;(B!==0||D<y)&&N!==-1;N--,D++)B+=c*m[N]>>>0,m[N]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");y=D,g++}if(E[g]!==" "){for(var I=S-y;I!==S&&m[I]===0;)I++;for(var _=new Uint8Array(h+(S-I)),L=h;I!==S;)_[L++]=m[I++];return _}}}function x(E){var g=p(E);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:p,decode:x}}var gc=bc,yc=gc,as=yc;var pn=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")}},mn=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 us(this,t)}},bn=class{decoders;constructor(t){this.decoders=t}or(t){return us(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 us(r,t){return new bn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var gn=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 pn(t,e,n),this.decoder=new mn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ve({name:r,prefix:t,encode:e,decode:n}){return new gn(r,t,e,n)}function Zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=as(e,r);return ve({prefix:t,name:r,encode:n,decode:s=>Mt(o(s))})}function xc(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),c=0,a=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`);a=a<<e|l,c+=e,c>=8&&(c-=8,i[f++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function wc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function X({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ve({prefix:t,name:r,encode(o){return wc(o,n,e)},decode(o){return xc(o,n,e,r)}})}var j=Zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ec=Zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xn={};pt(xn,{base32:()=>Ae,base32hex:()=>Bc,base32hexpad:()=>Lc,base32hexpadupper:()=>Tc,base32hexupper:()=>Ic,base32pad:()=>vc,base32padupper:()=>Ac,base32upper:()=>Sc,base32z:()=>_c});var Ae=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Sc=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vc=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ac=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Bc=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ic=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Lc=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Tc=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),_c=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var wn={};pt(wn,{base36:()=>ze,base36upper:()=>Dc});var ze=Zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Dc=Zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Nc=hs,fs=128,Rc=127,Uc=~Rc,Pc=Math.pow(2,31);function hs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Pc;)t[e++]=r&255|fs,r/=128;for(;r&Uc;)t[e++]=r&255|fs,r>>>=7;return t[e]=r|0,hs.bytes=e-n+1,t}var kc=En,Cc=128,ls=127;function En(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw En.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ls)<<o:(i&ls)*Math.pow(2,o),o+=7}while(i>=Cc);return En.bytes=s-n,e}var Mc=Math.pow(2,7),Oc=Math.pow(2,14),Kc=Math.pow(2,21),qc=Math.pow(2,28),Hc=Math.pow(2,35),zc=Math.pow(2,42),Vc=Math.pow(2,49),Fc=Math.pow(2,56),Gc=Math.pow(2,63),Zc=function(r){return r<Mc?1:r<Oc?2:r<Kc?3:r<qc?4:r<Hc?5:r<zc?6:r<Vc?7:r<Fc?8:r<Gc?9:10},Yc={encode:Nc,decode:kc,encodingLength:Zc},Wc=Yc,Ve=Wc;function Fe(r,t=0){return[Ve.decode(r,t),Ve.decode.bytes]}function Be(r,t,e=0){return Ve.encode(r,t,e),t}function Ie(r){return Ve.encodingLength(r)}function Lt(r,t){let e=t.byteLength,n=Ie(r),o=n+Ie(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 Yt(r){let t=Mt(r),[e,n]=Fe(t),[o,s]=Fe(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 ds(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&os(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 ps(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return $c(e,Sn(r),t??j.encoder);default:return jc(e,Sn(r),t??Ae.encoder)}}var ms=new WeakMap;function Sn(r){let t=ms.get(r);if(t==null){let e=new Map;return ms.set(r,e),e}return t}var gt=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!==Ge)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Jc)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&&ds(t.multihash,n.multihash)}toString(t){return ps(this,t)}toJSON(){return{"/":ps(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??bs(n,o,s.bytes))}else if(e[Qc]===!0){let{version:n,multihash:o,code:s}=e,i=Yt(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!==Ge)throw new Error(`Version 0 CID must use dag-pb (code: ${Ge}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=bs(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ge,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 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,p]=Fe(t.subarray(e));return e+=p,l},o=n(),s=Ge;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),a=n(),f=e+a,u=f-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:u,size:f}}static parse(t,e){let[n,o]=Xc(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 Sn(s).set(n,t),s}};function Xc(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 Ae.prefix:{let e=t??Ae;return[Ae.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 $c(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 jc(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 Ge=112,Jc=18;function bs(r,t,e){let n=Ie(r),o=n+Ie(t),s=new Uint8Array(o+e.byteLength);return Be(r,s,0),Be(t,s,n),s.set(e,o),s}var Qc=Symbol.for("@ipld/js-cid/CID");var vn={};pt(vn,{identity:()=>Ot});var gs=0,ta="identity",ys=Mt;function ea(r){return Lt(gs,ys(r))}var Ot={code:gs,name:ta,encode:ys,digest:ea};function At(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 xs(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ra(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Te(r,...t){if(!ra(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 ws(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");xs(r.outputLen),xs(r.blockLen)}function _e(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 Es(r,t){Te(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ie=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Er(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Tt(r,t){return r<<32-t|r>>>t}function Ss(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Ze(r){return typeof r=="string"&&(r=Ss(r)),Te(r),r}function An(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Te(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 De=class{clone(){return this._cloneInto()}};function Sr(r){let t=n=>r().update(Ze(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Ne(r=32){if(ie&&typeof ie.getRandomValues=="function")return ie.getRandomValues(new Uint8Array(r));if(ie&&typeof ie.randomBytes=="function")return ie.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function na(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),c=Number(e&s),a=n?4:0,f=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+f,c,n)}function vs(r,t,e){return r&t^~r&e}function As(r,t,e){return r&t^r&e^t&e}var Re=class extends De{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=Er(this.buffer)}update(t){_e(this);let{view:e,buffer:n,blockLen:o}=this;t=Ze(t);let s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Er(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){_e(this),Es(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;na(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Er(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)c.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:c}=this;return t.length=o,t.pos=c,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var vr=BigInt(4294967295),Bn=BigInt(32);function Bs(r,t=!1){return t?{h:Number(r&vr),l:Number(r>>Bn&vr)}:{h:Number(r>>Bn&vr)|0,l:Number(r&vr)|0}}function oa(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}=Bs(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var sa=(r,t)=>BigInt(r>>>0)<<Bn|BigInt(t>>>0),ia=(r,t,e)=>r>>>e,ca=(r,t,e)=>r<<32-e|t>>>e,aa=(r,t,e)=>r>>>e|t<<32-e,ua=(r,t,e)=>r<<32-e|t>>>e,fa=(r,t,e)=>r<<64-e|t>>>e-32,la=(r,t,e)=>r>>>e-32|t<<64-e,ha=(r,t)=>t,da=(r,t)=>r,pa=(r,t,e)=>r<<e|t>>>32-e,ma=(r,t,e)=>t<<e|r>>>32-e,ba=(r,t,e)=>t<<e-32|r>>>64-e,ga=(r,t,e)=>r<<e-32|t>>>64-e;function ya(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var xa=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),wa=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ea=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Sa=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,va=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Aa=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Ba={fromBig:Bs,split:oa,toBig:sa,shrSH:ia,shrSL:ca,rotrSH:aa,rotrSL:ua,rotrBH:fa,rotrBL:la,rotr32H:ha,rotr32L:da,rotlSH:pa,rotlSL:ma,rotlBH:ba,rotlBL:ga,add:ya,add3L:xa,add3H:wa,add4L:Ea,add4H:Sa,add5H:Aa,add5L:va},k=Ba;var[Ia,La]=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))),Xt=new Uint32Array(80),$t=new Uint32Array(80),In=class extends Re{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:c,Dl:a,Eh:f,El:u,Fh:l,Fl:p,Gh:x,Gl:E,Hh:g,Hl:h}=this;return[t,e,n,o,s,i,c,a,f,u,l,p,x,E,g,h]}set(t,e,n,o,s,i,c,a,f,u,l,p,x,E,g,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=c|0,this.Dl=a|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=g|0,this.Hl=h|0}process(t,e){for(let m=0;m<16;m++,e+=4)Xt[m]=t.getUint32(e),$t[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let B=Xt[m-15]|0,D=$t[m-15]|0,N=k.rotrSH(B,D,1)^k.rotrSH(B,D,8)^k.shrSH(B,D,7),I=k.rotrSL(B,D,1)^k.rotrSL(B,D,8)^k.shrSL(B,D,7),_=Xt[m-2]|0,L=$t[m-2]|0,F=k.rotrSH(_,L,19)^k.rotrBH(_,L,61)^k.shrSH(_,L,6),K=k.rotrSL(_,L,19)^k.rotrBL(_,L,61)^k.shrSL(_,L,6),M=k.add4L(I,K,$t[m-7],$t[m-16]),Q=k.add4H(M,N,F,Xt[m-7],Xt[m-16]);Xt[m]=Q|0,$t[m]=M|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:f,Dl:u,Eh:l,El:p,Fh:x,Fl:E,Gh:g,Gl:h,Hh:y,Hl:S}=this;for(let m=0;m<80;m++){let B=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),N=l&x^~l&g,I=p&E^~p&h,_=k.add5L(S,D,I,La[m],$t[m]),L=k.add5H(_,y,B,N,Ia[m],Xt[m]),F=_|0,K=k.rotrSH(n,o,28)^k.rotrBH(n,o,34)^k.rotrBH(n,o,39),M=k.rotrSL(n,o,28)^k.rotrBL(n,o,34)^k.rotrBL(n,o,39),Q=n&s^n&c^s&c,v=o&i^o&a^i&a;y=g|0,S=h|0,g=x|0,h=E|0,x=l|0,E=p|0,{h:l,l:p}=k.add(f|0,u|0,L|0,F|0),f=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let T=k.add3L(F,M,v);n=k.add3H(T,L,K,Q),o=T|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:c,l:a}=k.add(this.Ch|0,this.Cl|0,c|0,a|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:g,l:h}=k.add(this.Gh|0,this.Gl|0,g|0,h|0),{h:y,l:S}=k.add(this.Hh|0,this.Hl|0,y|0,S|0),this.set(n,o,s,i,c,a,f,u,l,p,x,E,g,h,y,S)}roundClean(){Xt.fill(0),$t.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 Is=Sr(()=>new In);var Ir={};pt(Ir,{aInRange:()=>yt,abool:()=>_t,abytes:()=>Ue,bitGet:()=>Ua,bitLen:()=>Dn,bitMask:()=>We,bitSet:()=>Pa,bytesToHex:()=>qt,bytesToNumberBE:()=>Ht,bytesToNumberLE:()=>Jt,concatBytes:()=>zt,createHmacDrbg:()=>Nn,ensureBytes:()=>Y,equalBytes:()=>Na,hexToBytes:()=>ae,hexToNumber:()=>_n,inRange:()=>Ye,isBytes:()=>jt,memoized:()=>fe,notImplemented:()=>Ca,numberToBytesBE:()=>Qt,numberToBytesLE:()=>ue,numberToHexUnpadded:()=>ce,numberToVarBytesBE:()=>Da,utf8ToBytes:()=>Ra,validateObject:()=>Pt});var Ar=BigInt(0),Br=BigInt(1),Ta=BigInt(2);function jt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ue(r){if(!jt(r))throw new Error("Uint8Array expected")}function _t(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var _a=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function qt(r){Ue(r);let t="";for(let e=0;e<r.length;e++)t+=_a[r[e]];return t}function ce(r){let t=r.toString(16);return t.length&1?"0"+t:t}function _n(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Ar:BigInt("0x"+r)}var Kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ls(r){if(r>=Kt._0&&r<=Kt._9)return r-Kt._0;if(r>=Kt.A&&r<=Kt.F)return r-(Kt.A-10);if(r>=Kt.a&&r<=Kt.f)return r-(Kt.a-10)}function ae(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=Ls(r.charCodeAt(s)),c=Ls(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Ht(r){return _n(qt(r))}function Jt(r){return Ue(r),_n(qt(Uint8Array.from(r).reverse()))}function Qt(r,t){return ae(r.toString(16).padStart(t*2,"0"))}function ue(r,t){return Qt(r,t).reverse()}function Da(r){return ae(ce(r))}function Y(r,t,e){let n;if(typeof t=="string")try{n=ae(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(jt(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 zt(...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 Na(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 Ra(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Ln=r=>typeof r=="bigint"&&Ar<=r;function Ye(r,t,e){return Ln(r)&&Ln(t)&&Ln(e)&&t<=r&&r<e}function yt(r,t,e,n){if(!Ye(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Dn(r){let t;for(t=0;r>Ar;r>>=Br,t+=1);return t}function Ua(r,t){return r>>BigInt(t)&Br}function Pa(r,t,e){return r|(e?Br:Ar)<<BigInt(t)}var We=r=>(Ta<<BigInt(r-1))-Br,Tn=r=>new Uint8Array(r),Ts=r=>Uint8Array.from(r);function Nn(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=Tn(r),o=Tn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...l)=>e(o,n,...l),a=(l=Tn())=>{o=c(Ts([0]),l),n=c(),l.length!==0&&(o=c(Ts([1]),l),n=c())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,p=[];for(;l<t;){n=c();let x=n.slice();p.push(x),l+=n.length}return zt(...p)};return(l,p)=>{i(),a(l);let x;for(;!(x=p(f()));)a();return i(),x}}var ka={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"||jt(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 Pt(r,t,e={}){let n=(o,s,i)=>{let c=ka[s];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(i&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};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 Ca=()=>{throw new Error("not implemented")};function fe(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 et=BigInt(0),G=BigInt(1),le=BigInt(2),Ma=BigInt(3),Rn=BigInt(4),_s=BigInt(5),Ds=BigInt(8),Oa=BigInt(9),Ka=BigInt(16);function z(r,t){let e=r%t;return e>=et?e:t+e}function qa(r,t,e){if(t<et)throw new Error("invalid exponent, negatives unsupported");if(e<=et)throw new Error("invalid modulus");if(e===G)return et;let n=G;for(;t>et;)t&G&&(n=n*r%e),r=r*r%e,t>>=G;return n}function Z(r,t,e){let n=r;for(;t-- >et;)n*=n,n%=e;return n}function Lr(r,t){if(r===et)throw new Error("invert: expected non-zero number");if(t<=et)throw new Error("invert: expected positive modulus, got "+t);let e=z(r,t),n=t,o=et,s=G,i=G,c=et;for(;e!==et;){let f=n/e,u=n%e,l=o-i*f,p=s-c*f;n=e,e=u,o=i,s=c,i=l,c=p}if(n!==G)throw new Error("invert: does not exist");return z(o,t)}function Ha(r){let t=(r-G)/le,e,n,o;for(e=r-G,n=0;e%le===et;e/=le,n++);for(o=le;o<r&&qa(o,t,r)!==r-G;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+G)/Rn;return function(a,f){let u=a.pow(f,i);if(!a.eql(a.sqr(u),f))throw new Error("Cannot find square root");return u}}let s=(e+G)/le;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let f=n,u=c.pow(c.mul(c.ONE,o),e),l=c.pow(a,s),p=c.pow(a,e);for(;!c.eql(p,c.ONE);){if(c.eql(p,c.ZERO))return c.ZERO;let x=1;for(let g=c.sqr(p);x<f&&!c.eql(g,c.ONE);x++)g=c.sqr(g);let E=c.pow(u,G<<BigInt(f-x-1));u=c.sqr(E),l=c.mul(l,E),p=c.mul(p,u),f=x}return l}}function za(r){if(r%Rn===Ma){let t=(r+G)/Rn;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%Ds===_s){let t=(r-_s)/Ds;return function(n,o){let s=n.mul(o,le),i=n.pow(s,t),c=n.mul(o,i),a=n.mul(n.mul(c,le),i),f=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return r%Ka,Ha(r)}var Ns=(r,t)=>(z(r,t)&G)===G,Va=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Un(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Va.reduce((n,o)=>(n[o]="function",n),t);return Pt(r,e)}function Fa(r,t,e){if(e<et)throw new Error("invalid exponent, negatives unsupported");if(e===et)return r.ONE;if(e===G)return t;let n=r.ONE,o=t;for(;e>et;)e&G&&(n=r.mul(n,o)),o=r.sqr(o),e>>=G;return n}function Ga(r,t){let e=new Array(t.length),n=t.reduce((s,i,c)=>r.is0(i)?s:(e[c]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,c)=>r.is0(i)?s:(e[c]=r.mul(s,e[c]),r.mul(s,i)),o),e}function Pn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function te(r,t,e=!1,n={}){if(r<=et)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=Pn(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:We(o),ZERO:et,ONE:G,create:a=>z(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return et<=a&&a<r},is0:a=>a===et,isOdd:a=>(a&G)===G,neg:a=>z(-a,r),eql:(a,f)=>a===f,sqr:a=>z(a*a,r),add:(a,f)=>z(a+f,r),sub:(a,f)=>z(a-f,r),mul:(a,f)=>z(a*f,r),pow:(a,f)=>Fa(c,a,f),div:(a,f)=>z(a*Lr(f,r),r),sqrN:a=>a*a,addN:(a,f)=>a+f,subN:(a,f)=>a-f,mulN:(a,f)=>a*f,inv:a=>Lr(a,r),sqrt:n.sqrt||(a=>(i||(i=za(r)),i(c,a))),invertBatch:a=>Ga(c,a),cmov:(a,f,u)=>u?f:a,toBytes:a=>e?ue(a,s):Qt(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?Jt(a):Ht(a)}});return Object.freeze(c)}function Rs(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 kn(r){let t=Rs(r);return t+Math.ceil(t/2)}function Us(r,t,e=!1){let n=r.length,o=Rs(t),s=kn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Jt(r):Ht(r),c=z(i,t-G)+G;return e?ue(c,o):Qt(c,o)}var Ps=BigInt(0),Tr=BigInt(1);function Cn(r,t){let e=t.negate();return r?e:t}function ks(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Mn(r,t){ks(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function Za(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 Ya(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 On=new WeakMap,Cs=new WeakMap;function Kn(r){return Cs.get(r)||1}function _r(r,t){return{constTimeNegate:Cn,hasPrecomputes(e){return Kn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Ps;)n&Tr&&(o=o.add(s)),s=s.double(),n>>=Tr;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Mn(n,t),i=[],c=e,a=c;for(let f=0;f<o;f++){a=c,i.push(a);for(let u=1;u<s;u++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(e,n,o){let{windows:s,windowSize:i}=Mn(e,t),c=r.ZERO,a=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+=Tr);let g=x,h=x+Math.abs(E)-1,y=p%2!==0,S=E<0;E===0?a=a.add(Cn(y,n[g])):c=c.add(Cn(S,n[h]))}return{p:c,f:a}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:c}=Mn(e,t),a=BigInt(2**e-1),f=2**e,u=BigInt(e);for(let l=0;l<i;l++){let p=l*c;if(o===Ps)break;let x=Number(o&a);if(o>>=u,x>c&&(x-=f,o+=Tr),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=On.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&On.set(n,o(s))),s},wNAFCached(e,n,o){let s=Kn(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=Kn(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ks(n,t),Cs.set(e,n),On.delete(e)}}}function Dr(r,t,e,n){if(Za(e,r),Ya(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=Dn(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,c=(1<<i)-1,a=new Array(c+1).fill(o),f=Math.floor((t.BITS-1)/i)*i,u=o;for(let l=f;l>=0;l-=i){a.fill(o);for(let x=0;x<n.length;x++){let E=n[x],g=Number(E>>BigInt(l)&BigInt(c));a[g]=a[g].add(e[x])}let p=o;for(let x=a.length-1,E=o;x>0;x--)E=E.add(a[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 Xe(r){return Un(r.Fp),Pt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Pn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Dt=BigInt(0),xt=BigInt(1),Nr=BigInt(2),Wa=BigInt(8),Xa={zip215:!0};function $a(r){let t=Xe(r);return Pt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Ms(r){let t=$a(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,f=Nr<<BigInt(c*8)-xt,u=e.create,l=te(t.n,t.nBitLength),p=t.uvRatio||((b,d)=>{try{return{isValid:!0,value:e.sqrt(b*e.inv(d))}}catch{return{isValid:!1,value:Dt}}}),x=t.adjustScalarBytes||(b=>b),E=t.domain||((b,d,w)=>{if(_t("phflag",w),d.length||w)throw new Error("Contexts/pre-hash are not supported");return b});function g(b,d){yt("coordinate "+b,d,Dt,f)}function h(b){if(!(b instanceof m))throw new Error("ExtendedPoint expected")}let y=fe((b,d)=>{let{ex:w,ey:A,ez:R}=b,U=b.is0();d==null&&(d=U?Wa:e.inv(R));let C=u(w*d),O=u(A*d),P=u(R*d);if(U)return{x:Dt,y:xt};if(P!==xt)throw new Error("invZ was invalid");return{x:C,y:O}}),S=fe(b=>{let{a:d,d:w}=t;if(b.is0())throw new Error("bad point: ZERO");let{ex:A,ey:R,ez:U,et:C}=b,O=u(A*A),P=u(R*R),H=u(U*U),V=u(H*H),nt=u(O*d),ot=u(H*u(nt+P)),it=u(V+u(w*u(O*P)));if(ot!==it)throw new Error("bad point: equation left != right (1)");let at=u(A*R),bt=u(U*C);if(at!==bt)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(d,w,A,R){this.ex=d,this.ey=w,this.ez=A,this.et=R,g("x",d),g("y",w),g("z",A),g("t",R),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 g("x",w),g("y",A),new m(w,A,xt,u(w*A))}static normalizeZ(d){let w=e.invertBatch(d.map(A=>A.ez));return d.map((A,R)=>A.toAffine(w[R])).map(m.fromAffine)}static msm(d,w){return Dr(m,l,d,w)}_setWindowSize(d){N.setWindowSize(this,d)}assertValidity(){S(this)}equals(d){h(d);let{ex:w,ey:A,ez:R}=this,{ex:U,ey:C,ez:O}=d,P=u(w*O),H=u(U*R),V=u(A*O),nt=u(C*R);return P===H&&V===nt}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:R}=this,U=u(w*w),C=u(A*A),O=u(Nr*u(R*R)),P=u(d*U),H=w+A,V=u(u(H*H)-U-C),nt=P+C,ot=nt-O,it=P-C,at=u(V*ot),bt=u(nt*it),dt=u(V*it),Ut=u(ot*nt);return new m(at,bt,Ut,dt)}add(d){h(d);let{a:w,d:A}=t,{ex:R,ey:U,ez:C,et:O}=this,{ex:P,ey:H,ez:V,et:nt}=d;if(w===BigInt(-1)){let Yo=u((U-R)*(H+P)),Wo=u((U+R)*(H-P)),hn=u(Wo-Yo);if(hn===Dt)return this.double();let Xo=u(C*Nr*nt),$o=u(O*Nr*V),jo=$o+Xo,Jo=Wo+Yo,Qo=$o-Xo,oc=u(jo*hn),sc=u(Jo*Qo),ic=u(jo*Qo),cc=u(hn*Jo);return new m(oc,sc,cc,ic)}let ot=u(R*P),it=u(U*H),at=u(O*A*nt),bt=u(C*V),dt=u((R+U)*(P+H)-ot-it),Ut=bt-at,Ct=bt+at,qe=u(it-w*ot),tc=u(dt*Ut),ec=u(Ct*qe),rc=u(dt*qe),nc=u(Ut*Ct);return new m(tc,ec,nc,rc)}subtract(d){return this.add(d.negate())}wNAF(d){return N.wNAFCached(this,d,m.normalizeZ)}multiply(d){let w=d;yt("scalar",w,xt,n);let{p:A,f:R}=this.wNAF(w);return m.normalizeZ([A,R])[0]}multiplyUnsafe(d,w=m.ZERO){let A=d;return yt("scalar",A,Dt,n),A===Dt?D:this.is0()||A===xt?this:N.wNAFCachedUnsafe(this,A,m.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(d){return y(this,d)}clearCofactor(){let{h:d}=t;return d===xt?this:this.multiplyUnsafe(d)}static fromHex(d,w=!1){let{d:A,a:R}=t,U=e.BYTES;d=Y("pointHex",d,U),_t("zip215",w);let C=d.slice(),O=d[U-1];C[U-1]=O&-129;let P=Jt(C),H=w?f:e.ORDER;yt("pointHex.y",P,Dt,H);let V=u(P*P),nt=u(V-xt),ot=u(A*V-R),{isValid:it,value:at}=p(nt,ot);if(!it)throw new Error("Point.fromHex: invalid y coordinate");let bt=(at&xt)===xt,dt=(O&128)!==0;if(!w&&at===Dt&&dt)throw new Error("Point.fromHex: x=0 and x_0=1");return dt!==bt&&(at=u(-at)),m.fromAffine({x:at,y:P})}static fromPrivateKey(d){return L(d).point}toRawBytes(){let{x:d,y:w}=this.toAffine(),A=ue(w,e.BYTES);return A[A.length-1]|=d&xt?128:0,A}toHex(){return qt(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,xt,u(t.Gx*t.Gy)),m.ZERO=new m(Dt,xt,xt,Dt);let{BASE:B,ZERO:D}=m,N=_r(m,c*8);function I(b){return z(b,n)}function _(b){return I(Jt(b))}function L(b){let d=e.BYTES;b=Y("private key",b,d);let w=Y("hashed private key",s(b),2*d),A=x(w.slice(0,d)),R=w.slice(d,2*d),U=_(A),C=B.multiply(U),O=C.toRawBytes();return{head:A,prefix:R,scalar:U,point:C,pointBytes:O}}function F(b){return L(b).pointBytes}function K(b=new Uint8Array,...d){let w=zt(...d);return _(s(E(w,Y("context",b),!!o)))}function M(b,d,w={}){b=Y("message",b),o&&(b=o(b));let{prefix:A,scalar:R,pointBytes:U}=L(d),C=K(w.context,A,b),O=B.multiply(C).toRawBytes(),P=K(w.context,O,U,b),H=I(C+P*R);yt("signature.s",H,Dt,n);let V=zt(O,ue(H,e.BYTES));return Y("result",V,e.BYTES*2)}let Q=Xa;function v(b,d,w,A=Q){let{context:R,zip215:U}=A,C=e.BYTES;b=Y("signature",b,2*C),d=Y("message",d),w=Y("publicKey",w,C),U!==void 0&&_t("zip215",U),o&&(d=o(d));let O=Jt(b.slice(C,2*C)),P,H,V;try{P=m.fromHex(w,U),H=m.fromHex(b.slice(0,C),U),V=B.multiplyUnsafe(O)}catch{return!1}if(!U&&P.isSmallOrder())return!1;let nt=K(R,H.toRawBytes(),P.toRawBytes(),d);return H.add(P.multiplyUnsafe(nt)).subtract(V).clearCofactor().equals(m.ZERO)}return B._setWindowSize(8),{CURVE:t,getPublicKey:F,sign:M,verify:v,ExtendedPoint:m,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>i(e.BYTES),precompute(b=8,d=m.BASE){return d._setWindowSize(b),d.multiply(BigInt(3)),d}}}}var qn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Os=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Zl=BigInt(0),ja=BigInt(1),Ks=BigInt(2),Yl=BigInt(3),Ja=BigInt(5),Qa=BigInt(8);function tu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=qn,c=r*r%s*r%s,a=Z(c,Ks,s)*c%s,f=Z(a,ja,s)*r%s,u=Z(f,Ja,s)*f%s,l=Z(u,t,s)*u%s,p=Z(l,e,s)*l%s,x=Z(p,n,s)*p%s,E=Z(x,o,s)*x%s,g=Z(E,o,s)*x%s,h=Z(g,t,s)*u%s;return{pow_p_5_8:Z(h,Ks,s)*r%s,b2:c}}function eu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function ru(r,t){let e=qn,n=z(t*t*t,e),o=z(n*n*t,e),s=tu(r*o).pow_p_5_8,i=z(r*n*s,e),c=z(t*i*i,e),a=i,f=z(i*Os,e),u=c===r,l=c===z(-r,e),p=c===z(-r*Os,e);return u&&(i=a),(l||p)&&(i=f),Ns(i,e)&&(i=z(-i,e)),{isValid:u||l,value:i}}var nu=te(qn,void 0,!0),ou={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:nu,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Qa,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Is,randomBytes:Ne,adjustScalarBytes:eu,uvRatio:ru},qs=Ms(ou);var Rr=32;function Hs(r,t,e){return qs.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Ur=class{type="Ed25519";raw;constructor(t){this.raw=Hn(t,Rr)}toMultihash(){return Ot.digest(he(this))}toCID(){return gt.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:At(this.raw,t.raw)}verify(t,e){return Hs(this.raw,e,t)}};function zn(r){return r=Hn(r,Rr),new Ur(r)}function Hn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new tt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function Vt(r=0){return new Uint8Array(r)}function ut(r=0){return new Uint8Array(r)}var iu=Math.pow(2,7),cu=Math.pow(2,14),au=Math.pow(2,21),Vn=Math.pow(2,28),Fn=Math.pow(2,35),Gn=Math.pow(2,42),Zn=Math.pow(2,49),q=128,ft=127;function Nt(r){if(r<iu)return 1;if(r<cu)return 2;if(r<au)return 3;if(r<Vn)return 4;if(r<Fn)return 5;if(r<Gn)return 6;if(r<Zn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Yn(r,t,e=0){switch(Nt(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 uu(r,t,e=0){switch(Nt(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 Wn(r,t){let e=r[t],n=0;if(n+=e&ft,e<q||(e=r[t+1],n+=(e&ft)<<7,e<q)||(e=r[t+2],n+=(e&ft)<<14,e<q)||(e=r[t+3],n+=(e&ft)<<21,e<q)||(e=r[t+4],n+=(e&ft)*Vn,e<q)||(e=r[t+5],n+=(e&ft)*Fn,e<q)||(e=r[t+6],n+=(e&ft)*Gn,e<q)||(e=r[t+7],n+=(e&ft)*Zn,e<q))return n;throw new RangeError("Could not decode varint")}function fu(r,t){let e=r.get(t),n=0;if(n+=e&ft,e<q||(e=r.get(t+1),n+=(e&ft)<<7,e<q)||(e=r.get(t+2),n+=(e&ft)<<14,e<q)||(e=r.get(t+3),n+=(e&ft)<<21,e<q)||(e=r.get(t+4),n+=(e&ft)*Vn,e<q)||(e=r.get(t+5),n+=(e&ft)*Fn,e<q)||(e=r.get(t+6),n+=(e&ft)*Gn,e<q)||(e=r.get(t+7),n+=(e&ft)*Zn,e<q))return n;throw new RangeError("Could not decode varint")}function Vs(r,t,e=0){return t==null&&(t=ut(Nt(r))),t instanceof Uint8Array?Yn(r,t,e):uu(r,t,e)}function Fs(r,t=0){return r instanceof Uint8Array?Wn(r,t):fu(r,t)}var Xn=new Float32Array([-0]),ee=new Uint8Array(Xn.buffer);function Zs(r,t,e){Xn[0]=r,t[e]=ee[0],t[e+1]=ee[1],t[e+2]=ee[2],t[e+3]=ee[3]}function Ys(r,t){return ee[0]=r[t],ee[1]=r[t+1],ee[2]=r[t+2],ee[3]=r[t+3],Xn[0]}var $n=new Float64Array([-0]),lt=new Uint8Array($n.buffer);function Ws(r,t,e){$n[0]=r,t[e]=lt[0],t[e+1]=lt[1],t[e+2]=lt[2],t[e+3]=lt[3],t[e+4]=lt[4],t[e+5]=lt[5],t[e+6]=lt[6],t[e+7]=lt[7]}function Xs(r,t){return lt[0]=r[t],lt[1]=r[t+1],lt[2]=r[t+2],lt[3]=r[t+3],lt[4]=r[t+4],lt[5]=r[t+5],lt[6]=r[t+6],lt[7]=r[t+7],$n[0]}var lu=BigInt(Number.MAX_SAFE_INTEGER),hu=BigInt(Number.MIN_SAFE_INTEGER),vt=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 de;if(t<lu&&t>hu)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>$s&&(o=0n,++n>$s&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return de;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):de}},de=new vt(0,0);de.toBigInt=function(){return 0n};de.zzEncode=de.zzDecode=function(){return this};de.length=function(){return 1};var $s=4294967296n;function js(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 Js(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&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 jn(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 Pr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Jn=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 Pr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Rt(this,4);return Pr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Rt(this,4);let t=Ys(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Rt(this,4);let t=Xs(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 Js(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 vt(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=Pr(this.buf,this.pos+=4),e=Pr(this.buf,this.pos+=4);return new vt(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=Wn(this.buf,this.pos);return this.pos+=Nt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Qn(r){return new Jn(r instanceof Uint8Array?r:r.subarray())}function wt(r,t,e){let n=Qn(r);return t.decode(n,void 0,e)}var to={};pt(to,{base10:()=>du});var du=Zt({prefix:"9",name:"base10",alphabet:"0123456789"});var eo={};pt(eo,{base16:()=>pu,base16upper:()=>mu});var pu=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),mu=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ro={};pt(ro,{base2:()=>bu});var bu=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var no={};pt(no,{base256emoji:()=>Eu});var ti=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}"),gu=ti.reduce((r,t,e)=>(r[e]=t,r),[]),yu=ti.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function xu(r){return r.reduce((t,e)=>(t+=gu[e],t),"")}function wu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=yu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Eu=ve({prefix:"\u{1F680}",name:"base256emoji",encode:xu,decode:wu});var oo={};pt(oo,{base64:()=>Su,base64pad:()=>vu,base64url:()=>Au,base64urlpad:()=>Bu});var Su=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),vu=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Au=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bu=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var so={};pt(so,{base8:()=>Iu});var Iu=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var io={};pt(io,{identity:()=>Lu});var Lu=ve({prefix:"\0",name:"identity",encode:r=>is(r),decode:r=>ss(r)});var _h=new TextEncoder,Dh=new TextDecoder;var uo={};pt(uo,{sha256:()=>pe,sha512:()=>Du});function ao({name:r,code:t,encode:e}){return new co(r,t,e)}var co=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 ri(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var pe=ao({name:"sha2-256",code:18,encode:ri("SHA-256")}),Du=ao({name:"sha2-512",code:19,encode:ri("SHA-512")});var fo={...io,...ro,...so,...to,...eo,...xn,...wn,...yn,...oo,...no},zh={...uo,...vn};function oi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ni=oi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),lo=oi("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=ut(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Nu={utf8:ni,"utf-8":ni,hex:fo.base16,latin1:lo,ascii:lo,binary:lo,...fo},kr=Nu;function W(r,t="utf8"){let e=kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function ho(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ut(i);o+i>t&&(n=ut(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var me=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function po(){}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}},Ru=ho();function Uu(r){return globalThis.Buffer!=null?ut(r):Ru(r)}var je=class{len;head;tail;states;constructor(){this.len=0,this.head=new me(po,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new me(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new go((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Cr,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=vt.fromBigInt(t);return this._push(Cr,e.length(),e)}uint64Number(t){return this._push(Yn,Nt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=vt.fromBigInt(t).zzEncode();return this._push(Cr,e.length(),e)}sint64Number(t){let e=vt.fromNumber(t).zzEncode();return this._push(Cr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(mo,1,t?1:0)}fixed32(t){return this._push($e,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=vt.fromBigInt(t);return this._push($e,4,e.lo)._push($e,4,e.hi)}fixed64Number(t){let e=vt.fromNumber(t);return this._push($e,4,e.lo)._push($e,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(Zs,4,t)}double(t){return this._push(Ws,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(mo,1,0):this.uint32(e)._push(ku,e,t)}string(t){let e=js(t);return e!==0?this.uint32(e)._push(jn,e,t):this._push(mo,1,0)}fork(){return this.states=new bo(this),this.head=this.tail=new me(po,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 me(po,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=Uu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function mo(r,t,e){t[e]=r&255}function Pu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var go=class extends me{next;constructor(t,e){super(Pu,t,e),this.next=void 0}};function Cr(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 $e(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 ku(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(je.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Cu,t,r),this},je.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Mu,t,r),this});function Cu(r,t,e){t.set(r,e)}function Mu(r,t,e){r.length<40?jn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(W(r),e)}function yo(){return new je}function Et(r,t){let e=yo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Pe;(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"})(Pe||(Pe={}));function Mr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function xo(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return Mr("enum",Pe.VARINT,e,n)}function St(r,t){return Mr("message",Pe.LENGTH_DELIMITED,r,t)}var Bt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var rt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(rt||(rt={}));var wo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(wo||(wo={}));(function(r){r.codec=()=>xo(wo)})(rt||(rt={}));var kt;(function(r){let t;r.codec=()=>(t==null&&(t=St((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),rt.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 c=e.uint32();switch(c>>>3){case 1:{s.Type=rt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(kt||(kt={}));var Eo;(function(r){let t;r.codec=()=>(t==null&&(t=St((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),rt.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 c=e.uint32();switch(c>>>3){case 1:{s.Type=rt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(Eo||(Eo={}));var tr={};pt(tr,{MAX_RSA_KEY_SIZE:()=>Io,generateRSAKeyPair:()=>xi,jwkToJWKKeyPair:()=>wi,jwkToPkcs1:()=>Xu,jwkToPkix:()=>To,jwkToRSAPrivateKey:()=>yi,pkcs1ToJwk:()=>mi,pkcs1ToRSAPrivateKey:()=>gi,pkixToJwk:()=>bi,pkixToRSAPublicKey:()=>_o});var Ou=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]),re=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ne=new Uint32Array(64),So=class extends Re{constructor(){super(64,32,8,!1),this.A=re[0]|0,this.B=re[1]|0,this.C=re[2]|0,this.D=re[3]|0,this.E=re[4]|0,this.F=re[5]|0,this.G=re[6]|0,this.H=re[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){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=c|0,this.H=a|0}process(t,e){for(let l=0;l<16;l++,e+=4)ne[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let p=ne[l-15],x=ne[l-2],E=Tt(p,7)^Tt(p,18)^p>>>3,g=Tt(x,17)^Tt(x,19)^x>>>10;ne[l]=g+ne[l-7]+E+ne[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:f,H:u}=this;for(let l=0;l<64;l++){let p=Tt(c,6)^Tt(c,11)^Tt(c,25),x=u+p+vs(c,a,f)+Ou[l]+ne[l]|0,g=(Tt(n,2)^Tt(n,13)^Tt(n,22))+As(n,o,s)|0;u=f,f=a,a=c,c=i+x|0,i=s,s=o,o=n,n=x+g|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,c,a,f,u)}roundClean(){ne.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var ke=Sr(()=>new So);function J(r,t="utf8"){let e=kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}function be(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ut(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ci=Symbol.for("@achingbrain/uint8arraylist");function ii(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 Or(r){return!!r?.[ci]}var ct=class r{bufs;length;[ci]=!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(Or(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(Or(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=ii(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ii(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(Or(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 be(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:be(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],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let f=t>=c&&t<a,u=e>c&&e<=a;if(f&&u){if(t===c&&e===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Or(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 c=i,a=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=e;l<=a;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-c[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=ut(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=Vt(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=Vt(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=Vt(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=ut(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=Vt(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=Vt(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=Vt(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=Vt(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=Vt(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(!At(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 Ku=parseInt("11111",2),Ao=parseInt("10000000",2),qu=parseInt("01111111",2),ai={2:Hu,3:Fu,5:Vu,6:zu,16:vo,22:vo,48:vo};function Je(r,t={offset:0}){let e=r[t.offset]&Ku;if(t.offset++,ai[e]!=null)return ai[e](r,t);throw new Error("No decoder for tag "+e)}function Kr(r,t){let e=0;if((r[t.offset]&Ao)===Ao){let n=r[t.offset]&qu,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 vo(r,t){Kr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Je(r,t);if(n===null)break;e.push(n)}return e}function Hu(r,t){let e=Kr(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 zu(r,t){let e=Kr(r,t);return t.offset+=e,["oid-unimplemented"]}function Vu(r,t){return t.offset++,null}function Fu(r,t){let e=Kr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return Je(o,{offset:0})}function Gu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ct;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Bo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Gu(r.byteLength);return new ct(Uint8Array.from([t.byteLength|Ao]),t)}function It(r){let t=new ct,e=parseInt("10000000",2);return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ct(Uint8Array.from([2]),Bo(t),t)}function ui(r){let t=Uint8Array.from([0]),e=new ct(t,r);return new ct(Uint8Array.from([3]),Bo(e),e)}function qr(r){let t=new ct;for(let e of r)t.append(e);return new ct(Uint8Array.from([48]),Bo(t),t)}function Hr(r){if(isNaN(r)||r<=0)throw new tt("random bytes length must be a Number bigger than 0");return Ne(r)}var Qe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var fi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new zr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var oe=fi;async function li(r){let t=await oe.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 Zu(t);return{privateKey:e[0],publicKey:e[1]}}async function hi(r,t){let e=await oe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await oe.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function di(r,t,e){let n=await oe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return oe.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Zu(r){if(r.privateKey==null||r.publicKey==null)throw new tt("Private and public key are required");return Promise.all([oe.get().subtle.exportKey("jwk",r.privateKey),oe.get().subtle.exportKey("jwk",r.publicKey)])}function pi(r){if(r.kty!=="RSA")throw new tt("invalid key type");if(r.n==null)throw new tt("invalid key modulus");return W(r.n,"base64url").length*8}var Ce=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=tr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return gt.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:At(this.raw,t.raw)}verify(t,e){return di(this._key,e,t)}},er=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=tr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:At(this.raw,t.raw)}sign(t){return hi(this._key,t)}};var Io=8192,Lo=18,Yu=1062,Wu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function mi(r){let t=Je(r);return{n:J(t[1],"base64url"),e:J(t[2],"base64url"),d:J(t[3],"base64url"),p:J(t[4],"base64url"),q:J(t[5],"base64url"),dp:J(t[6],"base64url"),dq:J(t[7],"base64url"),qi:J(t[8],"base64url"),kty:"RSA"}}function Xu(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 tt("JWK was missing components");return qr([It(Uint8Array.from([0])),It(W(r.n,"base64url")),It(W(r.e,"base64url")),It(W(r.d,"base64url")),It(W(r.p,"base64url")),It(W(r.q,"base64url")),It(W(r.dp,"base64url")),It(W(r.dq,"base64url")),It(W(r.qi,"base64url"))]).subarray()}function bi(r){let t=Je(r,{offset:0});return{kty:"RSA",n:J(t[1][0],"base64url"),e:J(t[1][1],"base64url")}}function To(r){if(r.n==null||r.e==null)throw new tt("JWK was missing components");return qr([Wu,ui(qr([It(W(r.n,"base64url")),It(W(r.e,"base64url"))]))]).subarray()}function gi(r){let t=mi(r);return yi(t)}function _o(r,t){if(r.byteLength>=Yu)throw new Ee("Key size is too large");let e=bi(r);if(t==null){let n=ke(kt.encode({Type:rt.RSA,Data:r}));t=Lt(Lo,n)}return new Ce(e,t)}function yi(r){if(pi(r)>Io)throw new tt("Key size is too large");let t=wi(r),e=ke(kt.encode({Type:rt.RSA,Data:To(t.publicKey)})),n=Lt(Lo,e);return new er(t.privateKey,new Ce(t.publicKey,n))}async function xi(r){if(r>Io)throw new tt("Key size is too large");let t=await li(r),e=ke(kt.encode({Type:rt.RSA,Data:To(t.publicKey)})),n=Lt(Lo,e);return new er(t.privateKey,new Ce(t.publicKey,n))}function wi(r){if(r==null)throw new tt("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var Vr=class extends De{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,ws(t);let n=Ze(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 _e(this),this.iHash.update(t),this}digestInto(t){_e(this),Te(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:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Do=(r,t,e)=>new Vr(r,t).update(e).digest();Do.create=(r,t)=>new Vr(r,t);function Ei(r){r.lowS!==void 0&&_t("lowS",r.lowS),r.prehash!==void 0&&_t("prehash",r.prehash)}function $u(r){let t=Xe(r);Pt(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:ju,hexToBytes:Ju}=Ir,No=class extends Error{constructor(t=""){super(t)}},Ft={Err:No,_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=ce(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ce(o.length/2|128):"";return ce(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 a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+a);if(f.length!==a)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+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,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=ce(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 ju(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Ft,o=typeof r=="string"?Ju(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:c,l:a}=n.decode(2,s),{v:f,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),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),st=BigInt(1),dp=BigInt(2),Si=BigInt(3),pp=BigInt(4);function Qu(r){let t=$u(r),{Fp:e}=t,n=te(t.n,t.nBitLength),o=t.toBytes||((g,h,y)=>{let S=h.toAffine();return zt(Uint8Array.from([4]),e.toBytes(S.x),e.toBytes(S.y))}),s=t.fromBytes||(g=>{let h=g.subarray(1),y=e.fromBytes(h.subarray(0,e.BYTES)),S=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:y,y:S}});function i(g){let{a:h,b:y}=t,S=e.sqr(g),m=e.mul(S,g);return e.add(e.add(m,e.mul(g,h)),y)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function c(g){return Ye(g,st,t.n)}function a(g){let{allowedPrivateKeyLengths:h,nByteLength:y,wrapPrivateKey:S,n:m}=t;if(h&&typeof g!="bigint"){if(jt(g)&&(g=qt(g)),typeof g!="string"||!h.includes(g.length))throw new Error("invalid private key");g=g.padStart(y*2,"0")}let B;try{B=typeof g=="bigint"?g:Ht(Y("private key",g,y))}catch{throw new Error("invalid private key, expected hex or "+y+" bytes, got "+typeof g)}return S&&(B=z(B,m)),yt("private key",B,st,m),B}function f(g){if(!(g instanceof p))throw new Error("ProjectivePoint expected")}let u=fe((g,h)=>{let{px:y,py:S,pz:m}=g;if(e.eql(m,e.ONE))return{x:y,y:S};let B=g.is0();h==null&&(h=B?e.ONE:e.inv(m));let D=e.mul(y,h),N=e.mul(S,h),I=e.mul(m,h);if(B)return{x:e.ZERO,y:e.ZERO};if(!e.eql(I,e.ONE))throw new Error("invZ was invalid");return{x:D,y:N}}),l=fe(g=>{if(g.is0()){if(t.allowInfinityPoint&&!e.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:h,y}=g.toAffine();if(!e.isValid(h)||!e.isValid(y))throw new Error("bad point: x or y not FE");let S=e.sqr(y),m=i(h);if(!e.eql(S,m))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class p{constructor(h,y,S){if(this.px=h,this.py=y,this.pz=S,h==null||!e.isValid(h))throw new Error("x required");if(y==null||!e.isValid(y))throw new Error("y required");if(S==null||!e.isValid(S))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:y,y:S}=h||{};if(!h||!e.isValid(y)||!e.isValid(S))throw new Error("invalid affine point");if(h instanceof p)throw new Error("projective point not allowed");let m=B=>e.eql(B,e.ZERO);return m(y)&&m(S)?p.ZERO:new p(y,S,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let y=e.invertBatch(h.map(S=>S.pz));return h.map((S,m)=>S.toAffine(y[m])).map(p.fromAffine)}static fromHex(h){let y=p.fromAffine(s(Y("pointHex",h)));return y.assertValidity(),y}static fromPrivateKey(h){return p.BASE.multiply(a(h))}static msm(h,y){return Dr(p,n,h,y)}_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:y,py:S,pz:m}=this,{px:B,py:D,pz:N}=h,I=e.eql(e.mul(y,N),e.mul(B,m)),_=e.eql(e.mul(S,N),e.mul(D,m));return I&&_}negate(){return new p(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:y}=t,S=e.mul(y,Si),{px:m,py:B,pz:D}=this,N=e.ZERO,I=e.ZERO,_=e.ZERO,L=e.mul(m,m),F=e.mul(B,B),K=e.mul(D,D),M=e.mul(m,B);return M=e.add(M,M),_=e.mul(m,D),_=e.add(_,_),N=e.mul(h,_),I=e.mul(S,K),I=e.add(N,I),N=e.sub(F,I),I=e.add(F,I),I=e.mul(N,I),N=e.mul(M,N),_=e.mul(S,_),K=e.mul(h,K),M=e.sub(L,K),M=e.mul(h,M),M=e.add(M,_),_=e.add(L,L),L=e.add(_,L),L=e.add(L,K),L=e.mul(L,M),I=e.add(I,L),K=e.mul(B,D),K=e.add(K,K),L=e.mul(K,M),N=e.sub(N,L),_=e.mul(K,F),_=e.add(_,_),_=e.add(_,_),new p(N,I,_)}add(h){f(h);let{px:y,py:S,pz:m}=this,{px:B,py:D,pz:N}=h,I=e.ZERO,_=e.ZERO,L=e.ZERO,F=t.a,K=e.mul(t.b,Si),M=e.mul(y,B),Q=e.mul(S,D),v=e.mul(m,N),T=e.add(y,S),b=e.add(B,D);T=e.mul(T,b),b=e.add(M,Q),T=e.sub(T,b),b=e.add(y,m);let d=e.add(B,N);return b=e.mul(b,d),d=e.add(M,v),b=e.sub(b,d),d=e.add(S,m),I=e.add(D,N),d=e.mul(d,I),I=e.add(Q,v),d=e.sub(d,I),L=e.mul(F,b),I=e.mul(K,v),L=e.add(I,L),I=e.sub(Q,L),L=e.add(Q,L),_=e.mul(I,L),Q=e.add(M,M),Q=e.add(Q,M),v=e.mul(F,v),b=e.mul(K,b),Q=e.add(Q,v),v=e.sub(M,v),v=e.mul(F,v),b=e.add(b,v),M=e.mul(Q,b),_=e.add(_,M),M=e.mul(d,b),I=e.mul(T,I),I=e.sub(I,M),M=e.mul(T,Q),L=e.mul(d,L),L=e.add(L,M),new p(I,_,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:y,n:S}=t;yt("scalar",h,Gt,S);let m=p.ZERO;if(h===Gt)return m;if(this.is0()||h===st)return this;if(!y||E.hasPrecomputes(this))return E.wNAFCachedUnsafe(this,h,p.normalizeZ);let{k1neg:B,k1:D,k2neg:N,k2:I}=y.splitScalar(h),_=m,L=m,F=this;for(;D>Gt||I>Gt;)D&st&&(_=_.add(F)),I&st&&(L=L.add(F)),F=F.double(),D>>=st,I>>=st;return B&&(_=_.negate()),N&&(L=L.negate()),L=new p(e.mul(L.px,y.beta),L.py,L.pz),_.add(L)}multiply(h){let{endo:y,n:S}=t;yt("scalar",h,st,S);let m,B;if(y){let{k1neg:D,k1:N,k2neg:I,k2:_}=y.splitScalar(h),{p:L,f:F}=this.wNAF(N),{p:K,f:M}=this.wNAF(_);L=E.constTimeNegate(D,L),K=E.constTimeNegate(I,K),K=new p(e.mul(K.px,y.beta),K.py,K.pz),m=L.add(K),B=F.add(M)}else{let{p:D,f:N}=this.wNAF(h);m=D,B=N}return p.normalizeZ([m,B])[0]}multiplyAndAddUnsafe(h,y,S){let m=p.BASE,B=(N,I)=>I===Gt||I===st||!N.equals(m)?N.multiplyUnsafe(I):N.multiply(I),D=B(this,y).add(B(h,S));return D.is0()?void 0:D}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:y}=t;if(h===st)return!0;if(y)return y(p,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:y}=t;return h===st?this:y?y(p,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return _t("isCompressed",h),this.assertValidity(),o(p,this,h)}toHex(h=!0){return _t("isCompressed",h),qt(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=_r(p,t.endo?Math.ceil(x/2):x);return{CURVE:t,ProjectivePoint:p,normPrivateKeyToScalar:a,weierstrassEquation:i,isWithinCurveOrder:c}}function tf(r){let t=Xe(r);return Pt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function vi(r){let t=tf(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(v){return z(v,n)}function c(v){return Lr(v,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=Qu({...t,toBytes(v,T,b){let d=T.toAffine(),w=e.toBytes(d.x),A=zt;return _t("isCompressed",b),b?A(Uint8Array.from([T.hasEvenY()?2:3]),w):A(Uint8Array.from([4]),w,e.toBytes(d.y))},fromBytes(v){let T=v.length,b=v[0],d=v.subarray(1);if(T===o&&(b===2||b===3)){let w=Ht(d);if(!Ye(w,st,e.ORDER))throw new Error("Point is not on curve");let A=u(w),R;try{R=e.sqrt(A)}catch(O){let P=O instanceof Error?": "+O.message:"";throw new Error("Point is not on curve"+P)}let U=(R&st)===st;return(b&1)===1!==U&&(R=e.neg(R)),{x:w,y:R}}else if(T===s&&b===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 "+T)}}}),p=v=>qt(Qt(v,t.nByteLength));function x(v){let T=n>>st;return v>T}function E(v){return x(v)?i(-v):v}let g=(v,T,b)=>Ht(v.slice(T,b));class h{constructor(T,b,d){this.r=T,this.s=b,this.recovery=d,this.assertValidity()}static fromCompact(T){let b=t.nByteLength;return T=Y("compactSignature",T,b*2),new h(g(T,0,b),g(T,b,2*b))}static fromDER(T){let{r:b,s:d}=Ft.toSig(Y("DER",T));return new h(b,d)}assertValidity(){yt("r",this.r,st,n),yt("s",this.s,st,n)}addRecoveryBit(T){return new h(this.r,this.s,T)}recoverPublicKey(T){let{r:b,s:d,recovery:w}=this,A=N(Y("msgHash",T));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let R=w===2||w===3?b+t.n:b;if(R>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let U=(w&1)===0?"02":"03",C=a.fromHex(U+p(R)),O=c(R),P=i(-A*O),H=i(d*O),V=a.BASE.multiplyAndAddUnsafe(C,P,H);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 ae(this.toDERHex())}toDERHex(){return Ft.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ae(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}let y={isValidPrivateKey(v){try{return f(v),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let v=kn(t.n);return Us(t.randomBytes(v),t.n)},precompute(v=8,T=a.BASE){return T._setWindowSize(v),T.multiply(BigInt(3)),T}};function S(v,T=!0){return a.fromPrivateKey(v).toRawBytes(T)}function m(v){let T=jt(v),b=typeof v=="string",d=(T||b)&&v.length;return T?d===o||d===s:b?d===2*o||d===2*s:v instanceof a}function B(v,T,b=!0){if(m(v))throw new Error("first arg must be private key");if(!m(T))throw new Error("second arg must be public key");return a.fromHex(T).multiply(f(v)).toRawBytes(b)}let D=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let T=Ht(v),b=v.length*8-t.nBitLength;return b>0?T>>BigInt(b):T},N=t.bits2int_modN||function(v){return i(D(v))},I=We(t.nBitLength);function _(v){return yt("num < 2^"+t.nBitLength,v,Gt,I),Qt(v,t.nByteLength)}function L(v,T,b=F){if(["recovered","canonical"].some(ot=>ot in b))throw new Error("sign() legacy options not supported");let{hash:d,randomBytes:w}=t,{lowS:A,prehash:R,extraEntropy:U}=b;A==null&&(A=!0),v=Y("msgHash",v),Ei(b),R&&(v=Y("prehashed msgHash",d(v)));let C=N(v),O=f(T),P=[_(O),_(C)];if(U!=null&&U!==!1){let ot=U===!0?w(e.BYTES):U;P.push(Y("extraEntropy",ot))}let H=zt(...P),V=C;function nt(ot){let it=D(ot);if(!l(it))return;let at=c(it),bt=a.BASE.multiply(it).toAffine(),dt=i(bt.x);if(dt===Gt)return;let Ut=i(at*i(V+dt*O));if(Ut===Gt)return;let Ct=(bt.x===dt?0:2)|Number(bt.y&st),qe=Ut;return A&&x(Ut)&&(qe=E(Ut),Ct^=1),new h(dt,qe,Ct)}return{seed:H,k2sig:nt}}let F={lowS:t.lowS,prehash:!1},K={lowS:t.lowS,prehash:!1};function M(v,T,b=F){let{seed:d,k2sig:w}=L(v,T,b),A=t;return Nn(A.hash.outputLen,A.nByteLength,A.hmac)(d,w)}a.BASE._setWindowSize(8);function Q(v,T,b,d=K){let w=v;T=Y("msgHash",T),b=Y("publicKey",b);let{lowS:A,prehash:R,format:U}=d;if(Ei(d),"strict"in d)throw new Error("options.strict was renamed to lowS");if(U!==void 0&&U!=="compact"&&U!=="der")throw new Error("format must be compact or der");let C=typeof w=="string"||jt(w),O=!C&&!U&&typeof w=="object"&&w!==null&&typeof w.r=="bigint"&&typeof w.s=="bigint";if(!C&&!O)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let P,H;try{if(O&&(P=new h(w.r,w.s)),C){try{U!=="compact"&&(P=h.fromDER(w))}catch(Ct){if(!(Ct instanceof Ft.Err))throw Ct}!P&&U!=="der"&&(P=h.fromCompact(w))}H=a.fromHex(b)}catch{return!1}if(!P||A&&P.hasHighS())return!1;R&&(T=t.hash(T));let{r:V,s:nt}=P,ot=N(T),it=c(nt),at=i(ot*it),bt=i(V*it),dt=a.BASE.multiplyAndAddUnsafe(H,at,bt)?.toAffine();return dt?i(dt.x)===V:!1}return{CURVE:t,getPublicKey:S,getSharedSecret:B,sign:M,verify:Q,ProjectivePoint:a,Signature:h,utils:y}}function ef(r){return{hash:r,hmac:(t,...e)=>Do(r,t,An(...e)),randomBytes:Ne}}function Ai(r,t){let e=n=>vi({...r,...ef(n)});return{...e(t),create:e}}var Li=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Bi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),rf=BigInt(1),Ro=BigInt(2),Ii=(r,t)=>(r+t/Ro)/t;function nf(r){let t=Li,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),f=r*r*r%t,u=f*f*r%t,l=Z(u,e,t)*u%t,p=Z(l,e,t)*u%t,x=Z(p,Ro,t)*f%t,E=Z(x,o,t)*x%t,g=Z(E,s,t)*E%t,h=Z(g,c,t)*g%t,y=Z(h,a,t)*h%t,S=Z(y,c,t)*g%t,m=Z(S,e,t)*u%t,B=Z(m,i,t)*E%t,D=Z(B,n,t)*f%t,N=Z(D,Ro,t);if(!Uo.eql(Uo.sqr(N),r))throw new Error("Cannot find square root");return N}var Uo=te(Li,void 0,void 0,{sqrt:nf}),ge=Ai({a:BigInt(0),b:BigInt(7),Fp:Uo,n:Bi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Bi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-rf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=Ii(s*r,t),a=Ii(-n*r,t),f=z(r-c*e-a*o,t),u=z(-c*n-a*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}}}},ke),vp=BigInt(0);var Ap=ge.ProjectivePoint;function Ti(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function _i(r,t,e){let n=pe.digest(e instanceof Uint8Array?e:e.subarray());if(Ti(n))return n.then(({digest:o})=>ge.verify(t,o,r)).catch(o=>{throw new Qe(String(o))});try{return ge.verify(t,n.digest,r)}catch(o){throw new Qe(String(o))}}var Fr=class{type="secp256k1";raw;_key;constructor(t){this._key=Ni(t),this.raw=Di(this._key)}toMultihash(){return Ot.digest(he(this))}toCID(){return gt.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:At(this.raw,t.raw)}verify(t,e){return _i(this._key,e,t)}};function Po(r){return new Fr(r)}function Di(r){return ge.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Ni(r){try{return ge.ProjectivePoint.fromHex(r),r}catch(t){throw new Ee(String(t))}}function ko(r,t){let{Type:e,Data:n}=kt.decode(r),o=n??new Uint8Array;switch(e){case rt.RSA:return _o(o,t);case rt.Ed25519:return zn(o);case rt.secp256k1:return Po(o);default:throw new se}}function Ri(r){let{Type:t,Data:e}=kt.decode(r.digest),n=e??new Uint8Array;switch(t){case rt.Ed25519:return zn(n);case rt.secp256k1:return Po(n);default:throw new se}}function he(r){return kt.encode({Type:rt[r.type],Data:r.raw})}var Ui=Symbol.for("nodejs.util.inspect.custom"),of=114,rr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[dn]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return gt.createV1(of,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return At(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return At(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ui](){return`PeerId(${this.toString()})`}},nr=class extends rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},or=class extends rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},sr=class extends rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},sf=2336,Gr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ot.digest(W(this.url))}[Ui](){return`PeerId(${this.url})`}[dn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return gt.createV1(sf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=J(t)),t.toString()===this.toString())}};function Co(r){if(r.type==="Ed25519")return new or({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new sr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new nr({multihash:r.toCID().multihash,publicKey:r});throw new se}function Pi(r){return Co(r.publicKey)}function ir(r){if(af(r))return new nr({multihash:r});if(cf(r))try{let t=Ri(r);if(t.type==="Ed25519")return new or({multihash:r,publicKey:t});if(t.type==="secp256k1")return new sr({multihash:r,publicKey:t})}catch{let e=J(r.digest);return new Gr(new URL(e))}throw new yr("Supplied PeerID Multihash is invalid")}function cf(r){return r.code===Ot.code}function af(r){return r.code===pe.code}function ye(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=Yt(j.decode(`z${r}`));return ir(t)}var cr=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 ye(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 ye(this.map.values(),t=>t.key)}values(){return ye(this.map.values(),t=>t.value)}get size(){return this.map.size}};var ar=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 ye(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 ye(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 Yr(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Wr=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}},Me=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Wr(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 Wr(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 Mo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Oe(r={}){return uf(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 uf(r,t){t=t??{};let e=t.onEnd,n=new Me,o,s,i,c=Yr(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,y)=>{s=S=>{s=null,n.push(S);try{h(r(n))}catch(m){y(m)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Yr()})}},f=h=>s!=null?s(h):(n.push(h),o),u=h=>(n=new Me,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 Me,p(),{done:!0}),E=h=>(p(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:x,throw:E,push:l,end:p,get readableLength(){return n.size},onEmpty:async h=>{let y=h?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let S,m;y!=null&&(S=new Promise((B,D)=>{m=()=>{D(new Mo)},y.addEventListener("abort",m)}));try{await Promise.race([c.promise,S])}finally{m!=null&&y!=null&&y?.removeEventListener("abort",m)}}},e==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(h){return g.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return g.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(h){return g.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return g.readableLength},onEmpty:h=>g.onEmpty(h)},o}function ff(r){return r[Symbol.asyncIterator]!=null}async function lf(r,t){try{await Promise.all(r.map(async e=>{for await(let n of e)t.push(n)})),t.end()}catch(e){t.end(e)}}async function*hf(r){let t=Oe({objectMode:!0});lf(r,t).catch(()=>{}),yield*t}function*df(r){for(let t of r)yield*t}function pf(...r){let t=[];for(let e of r)ff(e)||t.push(e);return t.length===r.length?df(t):hf(r)}var ki=pf;function ur(r,...t){if(r==null)throw new Error("Empty pipeline");if(Oo(r)){let n=r;r=()=>n.source}else if(Mi(r)||Ci(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Oo(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++)Oo(e[n])&&(e[n]=bf(e[n]));return mf(...e)}var mf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},Ci=r=>r?.[Symbol.asyncIterator]!=null,Mi=r=>r?.[Symbol.iterator]!=null,Oo=r=>r==null?!1:r.sink!=null&&r.source!=null,bf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Oe({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Ci(s))o=async function*(){yield*s,n.end()};else if(Mi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return ki(n,o())}return r.source};var qo=pc(Ki(),1);var lr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Ho=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},qi=r=>globalThis.DOMException===void 0?new Ho(r):new DOMException(r),Hi=r=>{let t=r.reason===void 0?qi("This operation was aborted."):r.reason;return t instanceof Error?t:qi(t)};function zo(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,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(Hi(x)),c=()=>{l(Hi(x))},x.addEventListener("abort",c,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,l);return}let p=new lr;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(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}function Vo(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var hr=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let o=Vo(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var dr=class extends qo.default{#t;#i;#s=0;#d;#c;#p=0;#r;#a;#e;#m;#n=0;#u;#o;#b;#x=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:hr,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#c=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#b=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.#y(),this.#g(),this.#a=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.#a===void 0&&(this.#a=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.#g(),!0):!1}}return!1}#g(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#y()},this.#c),this.#p=Date.now()+this.#c)}#y(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#B(t){return new Promise((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.#b,...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=zo(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#B(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof lr&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function zi(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 Vi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Fi(r,t){let e=zi(r).return?.();Vi(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var $r=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ke=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},jr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},pr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Jr(r){return r[Symbol.asyncIterator]!=null}function Gi(r,t){if(r.byteLength>t)throw new Ke("Message length too long")}var tn=r=>{let t=Nt(r),e=ut(t);return Vs(r,e),tn.bytes=t,e};tn.bytes=0;function en(r,t){t=t??{};let e=t.lengthEncoder??tn,n=t?.maxDataLength??4194304;function*o(s){Gi(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)}()}en.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??tn,n=t?.maxDataLength??4194304;return Gi(r,n),new ct(e(r.byteLength),r)};var xe;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(xe||(xe={}));var Fo=r=>{let t=Fs(r);return Fo.bytes=Nt(t),t};Fo.bytes=0;function mr(r,t){let e=new ct,n=xe.LENGTH,o=-1,s=t?.lengthDecoder??Fo,i=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;e.byteLength>0;){if(n===xe.LENGTH)try{if(o=s(e),o<0)throw new $r("Invalid message length");if(o>c)throw new Ke("Message length too long");let f=s.bytes;e.consume(f),t?.onLength!=null&&t.onLength(o),n=xe.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>i)throw new jr("Message length length too long");break}throw f}if(n===xe.DATA){if(e.byteLength<o)break;let f=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(f),yield f,n=xe.LENGTH}}}return Jr(r)?async function*(){for await(let f of r)e.append(f),yield*a();if(e.byteLength>0)throw new pr("Unexpected end of input")}():function*(){for(let f of r)e.append(f),yield*a();if(e.byteLength>0)throw new pr("Unexpected end of input")}()}mr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return mr(n,{...t??{},onLength:s=>{e=s}})};var rn=class extends Se{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 ct(t):t)}attachInboundStream(t,e){let n=()=>{Fi(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=ur(this._rawInboundStream,o=>mr(o,e)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let e=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=Oe({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),ur(this.outboundStream,n=>en(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 Zi(){return BigInt(`0x${J(Hr(8),"base16")}`)}var Yi=(r,t)=>{let e=W(t.toString(16).padStart(16,"0"),"base16"),n=he(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},Wi=r=>pe.encode(r);var Xi=function(r){return Array.isArray(r)?r:[r]},Ef=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=ir(Yt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return Co(ko(e)).equals(t)}return!1},$i=async r=>{if(r.from==null)throw new $("RPC message was missing from");if(!await Ef(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=ir(Yt(r.from)),e=r.key??t.publicKey;if(e==null)throw new $("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:vf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?ko(e):e}},br=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:Sf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?he(r.key):void 0}:{data:r.data,topic:r.topic},Sf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),W(t,"base16")},vf=r=>BigInt(`0x${J(r,"base16")}`);var ji=W("libp2p-pubsub:");async function Ji(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Pi(r)},o=be([ji,e(br(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function Qi(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=be([ji,t({...br(r),signature:void 0,key:void 0}).subarray()]);return Af(r).verify(e,r.signature)}function Af(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 nn=class extends Se{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:c=10,maxInboundStreams:a=1,maxOutboundStreams:f=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=Xi(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new cr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new dr({concurrency:c}),this.maxInboundStreams=a,this.maxOutboundStreams=f,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let 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(c=>{this.log(c)})}_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 rn(this.components,{id:t,protocol:e});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return e}}async processMessages(t,e,n){try{await ur(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),c=[];for(let a of i.messages??[]){if(a.from==null||a.data==null||a.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}c.push({from:a.from,data:a.data,topic:a.topic,sequenceNumber:a.sequenceNumber??void 0,signature:a.signature??void 0,key:a.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(a=>({subscribe:!!a.subscribe,topic:a.topic??""})),messages:c}).catch(a=>{this.log(a)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,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:c})=>({topic:`${i??""}`,subscribe:!!c}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let c=await $i(i);await this.processMessage(t,c)}catch(c){this.log.error(c)}})).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 ar,this.topics.set(n,o)),e.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,e){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,e)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new $('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new $("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new $("Need key when signature policy is StrictSign but it was missing");return Yi(t.key,t.sequenceNumber);case"StrictNoSign":return Wi(t.data);default:throw new $("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,e){let{messages:n,subscriptions:o,subscribe:s}=e;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(br)})}sendRpc(t,e){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(e))}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new $('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new $("StrictNoSigning: signature should not be present");if(e.key!=null)throw new $("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new $("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new $('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new $("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new $("StrictSigning: Signing required and no sequenceNumber was present");if(!await Qi(e,this.encodeMessage.bind(this)))throw new $("StrictSigning: Invalid message signature");break;default:throw new $("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===He.Reject||s===He.Ignore)throw new $("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Ji(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new $("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new xr("not started yet");if(t==null)throw new tt("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:Zi()};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 on=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 Go="/floodsub/1.0.0";var we;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=St((i,c,a={})=>{a.lengthDelimited!==!1&&c.fork(),i.subscribe!=null&&(c.uint32(8),c.bool(i.subscribe)),i.topic!=null&&(c.uint32(18),c.string(i.topic)),a.lengthDelimited!==!1&&c.ldelim()},(i,c,a={})=>{let f={},u=c==null?i.len:i.pos+c;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=>Et(i,o.codec()),o.decode=(i,c)=>wt(i,o.codec(),c)})(t=r.SubOpts||(r.SubOpts={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=St((i,c,a={})=>{a.lengthDelimited!==!1&&c.fork(),i.from!=null&&(c.uint32(10),c.bytes(i.from)),i.data!=null&&(c.uint32(18),c.bytes(i.data)),i.sequenceNumber!=null&&(c.uint32(26),c.bytes(i.sequenceNumber)),i.topic!=null&&(c.uint32(34),c.string(i.topic)),i.signature!=null&&(c.uint32(42),c.bytes(i.signature)),i.key!=null&&(c.uint32(50),c.bytes(i.key)),a.lengthDelimited!==!1&&c.ldelim()},(i,c,a={})=>{let f={},u=c==null?i.len:i.pos+c;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=>Et(i,o.codec()),o.decode=(i,c)=>wt(i,o.codec(),c)})(e=r.Message||(r.Message={}));let n;r.codec=()=>(n==null&&(n=St((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.subscriptions!=null)for(let c of o.subscriptions)s.uint32(10),r.SubOpts.codec().encode(c,s);if(o.messages!=null)for(let c of o.messages)s.uint32(18),r.Message.codec().encode(c,s);o.control!=null&&(s.uint32(26),sn.codec().encode(o.control,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let c={subscriptions:[],messages:[]},a=s==null?o.len:o.pos+s;for(;o.pos<a;){let f=o.uint32();switch(f>>>3){case 1:{if(i.limits?.subscriptions!=null&&c.subscriptions.length===i.limits.subscriptions)throw new Bt('Decode error - map field "subscriptions" had too many elements');c.subscriptions.push(r.SubOpts.codec().decode(o,o.uint32(),{limits:i.limits?.subscriptions$}));break}case 2:{if(i.limits?.messages!=null&&c.messages.length===i.limits.messages)throw new Bt('Decode error - map field "messages" had too many elements');c.messages.push(r.Message.codec().decode(o,o.uint32(),{limits:i.limits?.messages$}));break}case 3:{c.control=sn.codec().decode(o,o.uint32(),{limits:i.limits?.control});break}default:{o.skipType(f&7);break}}}return c})),n),r.encode=o=>Et(o,r.codec()),r.decode=(o,s)=>wt(o,r.codec(),s)})(we||(we={}));var sn;(function(r){let t;r.codec=()=>(t==null&&(t=St((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.ihave!=null)for(let s of e.ihave)n.uint32(10),cn.codec().encode(s,n);if(e.iwant!=null)for(let s of e.iwant)n.uint32(18),an.codec().encode(s,n);if(e.graft!=null)for(let s of e.graft)n.uint32(26),un.codec().encode(s,n);if(e.prune!=null)for(let s of e.prune)n.uint32(34),fn.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 c=e.uint32();switch(c>>>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(cn.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(an.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(un.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(fn.codec().decode(e,e.uint32(),{limits:o.limits?.prune$}));break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(sn||(sn={}));var cn;(function(r){let t;r.codec=()=>(t==null&&(t=St((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 c=e.uint32();switch(c>>>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(c&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(cn||(cn={}));var an;(function(r){let t;r.codec=()=>(t==null&&(t=St((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 c=e.uint32();switch(c>>>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(c&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(an||(an={}));var un;(function(r){let t;r.codec=()=>(t==null&&(t=St((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 c=e.uint32();switch(c>>>3){case 1:{s.topic=e.string();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(un||(un={}));var fn;(function(r){let t;r.codec=()=>(t==null&&(t=St((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),ln.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 c=e.uint32();switch(c>>>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(ln.codec().decode(e,e.uint32(),{limits:o.limits?.peers$}));break}case 3:{s.backoff=e.uint64();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(fn||(fn={}));var ln;(function(r){let t;r.codec=()=>(t==null&&(t=St((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 c=e.uint32();switch(c>>>3){case 1:{s.peerID=e.bytes();break}case 2:{s.signedPeerRecord=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(ln||(ln={}));var Zo=class extends nn{seenCache;constructor(t,e){super(t,{...e,canRelayMessage:!0,multicodecs:[Go]}),this.log=t.logger.forComponent("libp2p:floodsub"),this.seenCache=new on({validityMs:e?.seenTTL??3e4})}[es]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[rs]=["@libp2p/pubsub"];[ns]=["@libp2p/identify"];decodeRpc(t){return we.decode(t)}encodeRpc(t){return we.encode(t)}decodeMessage(t){return we.Message.decode(t)}encodeMessage(t){return we.Message.encode(t)}async processMessage(t,e){let n=await super.getMsgId(e),o=J(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 Bf(r={}){return t=>new Zo(t,r)}return mc(If);})();
|
|
2
|
+
"use strict";var Libp2PFloodsub=(()=>{var ha=Object.create;var gr=Object.defineProperty;var da=Object.getOwnPropertyDescriptor;var pa=Object.getOwnPropertyNames;var ma=Object.getPrototypeOf,ba=Object.prototype.hasOwnProperty;var ga=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),pt=(r,t)=>{for(var e in t)gr(r,e,{get:t[e],enumerable:!0})},rs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of pa(t))!ba.call(r,o)&&o!==e&&gr(r,o,{get:()=>t[o],enumerable:!(n=da(t,o))||n.enumerable});return r};var ya=(r,t,e)=>(e=r!=null?ha(ma(r)):{},rs(t||!r||!r.__esModule?gr(e,"default",{value:r,enumerable:!0}):e,r)),xa=r=>rs(gr({},"__esModule",{value:!0}),r);var Vi=ga((om,Ho)=>{"use strict";var Ef=Object.prototype.hasOwnProperty,mt="~";function fr(){}Object.create&&(fr.prototype=Object.create(null),new fr().__proto__||(mt=!1));function Sf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function zi(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new Sf(e,n||r,o),i=mt?mt+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 $r(r,t){--r._eventsCount===0?r._events=new fr:delete r._events[t]}function ht(){this._events=new fr,this._eventsCount=0}ht.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Ef.call(e,n)&&t.push(mt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};ht.prototype.listeners=function(t){var e=mt?mt+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};ht.prototype.listenerCount=function(t){var e=mt?mt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};ht.prototype.emit=function(t,e,n,o,s,i){var a=mt?mt+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};ht.prototype.on=function(t,e,n){return zi(this,t,e,n,!1)};ht.prototype.once=function(t,e,n){return zi(this,t,e,n,!0)};ht.prototype.removeListener=function(t,e,n,o){var s=mt?mt+t:t;if(!this._events[s])return this;if(!e)return $r(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&$r(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:$r(this,s)}return this};ht.prototype.removeAllListeners=function(t){var e;return t?(e=mt?mt+t:t,this._events[e]&&$r(this,e)):(this._events=new fr,this._eventsCount=0),this};ht.prototype.off=ht.prototype.removeListener;ht.prototype.addListener=ht.prototype.on;ht.prefixed=mt;ht.EventEmitter=ht;typeof Ho<"u"&&(Ho.exports=ht)});var Df={};pt(Df,{floodsub:()=>_f,multicodec:()=>Yo});var pn=Symbol.for("@libp2p/peer-id");var He;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(He||(He={}));var ns=Symbol.for("@libp2p/pubsub");var tt=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 yr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var $=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var xr=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 xn={};pt(xn,{base58btc:()=>j,base58flickr:()=>Ba});var ol=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 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 as(r){return new TextEncoder().encode(r)}function cs(r){return new TextDecoder().decode(r)}function wa(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 g=0,h=0,y=0,S=E.length;y!==S&&E[y]===0;)y++,g++;for(var m=(S-y)*u+1>>>0,B=new Uint8Array(m);y!==S;){for(var D=E[y],N=0,I=m-1;(D!==0||N<h)&&I!==-1;I--,N++)D+=256*B[I]>>>0,B[I]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");h=N,y++}for(var _=m-h;_!==m&&B[_]===0;)_++;for(var L=c.repeat(g);_<m;++_)L+=r.charAt(B[_]);return L}function p(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var g=0;if(E[g]!==" "){for(var h=0,y=0;E[g]===c;)h++,g++;for(var S=(E.length-g)*f+1>>>0,m=new Uint8Array(S);E[g];){var B=e[E.charCodeAt(g)];if(B===255)return;for(var D=0,N=S-1;(B!==0||D<y)&&N!==-1;N--,D++)B+=a*m[N]>>>0,m[N]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");y=D,g++}if(E[g]!==" "){for(var I=S-y;I!==S&&m[I]===0;)I++;for(var _=new Uint8Array(h+(S-I)),L=h;I!==S;)_[L++]=m[I++];return _}}}function x(E){var g=p(E);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:p,decode:x}}var Ea=wa,Sa=Ea,fs=Sa;var mn=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")}},bn=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)}},gn=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 gn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var yn=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 mn(t,e,n),this.decoder=new bn(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 yn(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=>Mt(o(s))})}function va(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 Aa(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function X({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ae({prefix:t,name:r,encode(o){return Aa(o,n,e)},decode(o){return va(o,n,e,r)}})}var j=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ba=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var wn={};pt(wn,{base32:()=>Be,base32hex:()=>_a,base32hexpad:()=>Na,base32hexpadupper:()=>Ra,base32hexupper:()=>Da,base32pad:()=>La,base32padupper:()=>Ta,base32upper:()=>Ia,base32z:()=>Ua});var Be=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ia=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),La=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ta=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),_a=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Da=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Na=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ra=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ua=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var En={};pt(En,{base36:()=>ze,base36upper:()=>Pa});var ze=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Pa=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ka=ps,hs=128,Ca=127,Ma=~Ca,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 Ka=Sn,qa=128,ds=127;function Sn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Sn.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>=qa);return Sn.bytes=s-n,e}var Ha=Math.pow(2,7),za=Math.pow(2,14),Va=Math.pow(2,21),Fa=Math.pow(2,28),Ga=Math.pow(2,35),Za=Math.pow(2,42),Ya=Math.pow(2,49),Wa=Math.pow(2,56),Xa=Math.pow(2,63),$a=function(r){return r<Ha?1:r<za?2:r<Va?3:r<Fa?4:r<Ga?5:r<Za?6:r<Ya?7:r<Wa?8:r<Xa?9:10},ja={encode:ka,decode:Ka,encodingLength:$a},Ja=ja,Ve=Ja;function Fe(r,t=0){return[Ve.decode(r,t),Ve.decode.bytes]}function Ie(r,t,e=0){return Ve.encode(r,t,e),t}function Le(r){return Ve.encodingLength(r)}function Lt(r,t){let e=t.byteLength,n=Le(r),o=n+Le(e),s=new Uint8Array(o+e);return Ie(r,s,0),Ie(e,s,n),s.set(t,o),new Te(r,e,t,s)}function Wt(r){let t=Mt(r),[e,n]=Fe(t),[o,s]=Fe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Te(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 Te=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function bs(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return tc(e,vn(r),t??j.encoder);default:return ec(e,vn(r),t??Be.encoder)}}var gs=new WeakMap;function vn(r){let t=gs.get(r);if(t==null){let e=new Map;return gs.set(r,e),e}return t}var gt=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!==Ge)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==rc)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&&ms(t.multihash,n.multihash)}toString(t){return bs(this,t)}toJSON(){return{"/":bs(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??ys(n,o,s.bytes))}else if(e[nc]===!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!==Ge)throw new Error(`Version 0 CID must use dag-pb (code: ${Ge}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ys(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ge,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 Te(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]=Fe(t.subarray(e));return e+=p,l},o=n(),s=Ge;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]=Qa(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 vn(s).set(n,t),s}};function Qa(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 Be.prefix:{let e=t??Be;return[Be.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 tc(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 ec(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 Ge=112,rc=18;function ys(r,t,e){let n=Le(r),o=n+Le(t),s=new Uint8Array(o+e.byteLength);return Ie(r,s,0),Ie(t,s,n),s.set(e,o),s}var nc=Symbol.for("@ipld/js-cid/CID");var An={};pt(An,{identity:()=>Ot});var xs=0,oc="identity",ws=Mt;function sc(r){return Lt(xs,ws(r))}var Ot={code:xs,name:oc,encode:ws,digest:sc};function At(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 Es(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ic(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function _e(r,...t){if(!ic(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 Ss(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Es(r.outputLen),Es(r.blockLen)}function De(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function vs(r,t){_e(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ae=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Er(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Tt(r,t){return r<<32-t|r>>>t}function As(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Ze(r){return typeof r=="string"&&(r=As(r)),_e(r),r}function Bn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];_e(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 Sr(r){let t=n=>r().update(Ze(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Re(r=32){if(ae&&typeof ae.getRandomValues=="function")return ae.getRandomValues(new Uint8Array(r));if(ae&&typeof ae.randomBytes=="function")return ae.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function ac(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 Bs(r,t,e){return r&t^~r&e}function Is(r,t,e){return r&t^r&e^t&e}var Ue=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=Er(this.buffer)}update(t){De(this);let{view:e,buffer:n,blockLen:o}=this;t=Ze(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=Er(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){De(this),vs(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;ac(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Er(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 vr=BigInt(4294967295),In=BigInt(32);function Ls(r,t=!1){return t?{h:Number(r&vr),l:Number(r>>In&vr)}:{h:Number(r>>In&vr)|0,l:Number(r&vr)|0}}function cc(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}=Ls(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var uc=(r,t)=>BigInt(r>>>0)<<In|BigInt(t>>>0),fc=(r,t,e)=>r>>>e,lc=(r,t,e)=>r<<32-e|t>>>e,hc=(r,t,e)=>r>>>e|t<<32-e,dc=(r,t,e)=>r<<32-e|t>>>e,pc=(r,t,e)=>r<<64-e|t>>>e-32,mc=(r,t,e)=>r>>>e-32|t<<64-e,bc=(r,t)=>t,gc=(r,t)=>r,yc=(r,t,e)=>r<<e|t>>>32-e,xc=(r,t,e)=>t<<e|r>>>32-e,wc=(r,t,e)=>t<<e-32|r>>>64-e,Ec=(r,t,e)=>r<<e-32|t>>>64-e;function Sc(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var vc=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ac=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Bc=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Ic=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Lc=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Tc=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var _c={fromBig:Ls,split:cc,toBig:uc,shrSH:fc,shrSL:lc,rotrSH:hc,rotrSL:dc,rotrBH:pc,rotrBL:mc,rotr32H:bc,rotr32L:gc,rotlSH:yc,rotlSL:xc,rotlBH:wc,rotlBL:Ec,add:Sc,add3L:vc,add3H:Ac,add4L:Bc,add4H:Ic,add5H:Tc,add5L:Lc},k=_c;var[Dc,Nc]=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))),$t=new Uint32Array(80),jt=new Uint32Array(80),Ln=class extends Ue{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:g,Hl:h}=this;return[t,e,n,o,s,i,a,c,f,u,l,p,x,E,g,h]}set(t,e,n,o,s,i,a,c,f,u,l,p,x,E,g,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=g|0,this.Hl=h|0}process(t,e){for(let m=0;m<16;m++,e+=4)$t[m]=t.getUint32(e),jt[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let B=$t[m-15]|0,D=jt[m-15]|0,N=k.rotrSH(B,D,1)^k.rotrSH(B,D,8)^k.shrSH(B,D,7),I=k.rotrSL(B,D,1)^k.rotrSL(B,D,8)^k.shrSL(B,D,7),_=$t[m-2]|0,L=jt[m-2]|0,F=k.rotrSH(_,L,19)^k.rotrBH(_,L,61)^k.shrSH(_,L,6),K=k.rotrSL(_,L,19)^k.rotrBL(_,L,61)^k.shrSL(_,L,6),M=k.add4L(I,K,jt[m-7],jt[m-16]),Q=k.add4H(M,N,F,$t[m-7],$t[m-16]);$t[m]=Q|0,jt[m]=M|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:g,Gl:h,Hh:y,Hl:S}=this;for(let m=0;m<80;m++){let B=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),N=l&x^~l&g,I=p&E^~p&h,_=k.add5L(S,D,I,Nc[m],jt[m]),L=k.add5H(_,y,B,N,Dc[m],$t[m]),F=_|0,K=k.rotrSH(n,o,28)^k.rotrBH(n,o,34)^k.rotrBH(n,o,39),M=k.rotrSL(n,o,28)^k.rotrBL(n,o,34)^k.rotrBL(n,o,39),Q=n&s^n&a^s&a,v=o&i^o&c^i&c;y=g|0,S=h|0,g=x|0,h=E|0,x=l|0,E=p|0,{h:l,l:p}=k.add(f|0,u|0,L|0,F|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let T=k.add3L(F,M,v);n=k.add3H(T,L,K,Q),o=T|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:g,l:h}=k.add(this.Gh|0,this.Gl|0,g|0,h|0),{h:y,l:S}=k.add(this.Hh|0,this.Hl|0,y|0,S|0),this.set(n,o,s,i,a,c,f,u,l,p,x,E,g,h,y,S)}roundClean(){$t.fill(0),jt.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 Ts=Sr(()=>new Ln);var Ir={};pt(Ir,{aInRange:()=>yt,abool:()=>_t,abytes:()=>Pe,bitGet:()=>Mc,bitLen:()=>Nn,bitMask:()=>We,bitSet:()=>Oc,bytesToHex:()=>qt,bytesToNumberBE:()=>Ht,bytesToNumberLE:()=>Qt,concatBytes:()=>zt,createHmacDrbg:()=>Rn,ensureBytes:()=>Y,equalBytes:()=>kc,hexToBytes:()=>ue,hexToNumber:()=>Dn,inRange:()=>Ye,isBytes:()=>Jt,memoized:()=>le,notImplemented:()=>qc,numberToBytesBE:()=>te,numberToBytesLE:()=>fe,numberToHexUnpadded:()=>ce,numberToVarBytesBE:()=>Pc,utf8ToBytes:()=>Cc,validateObject:()=>Pt});var Ar=BigInt(0),Br=BigInt(1),Rc=BigInt(2);function Jt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Pe(r){if(!Jt(r))throw new Error("Uint8Array expected")}function _t(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var Uc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function qt(r){Pe(r);let t="";for(let e=0;e<r.length;e++)t+=Uc[r[e]];return t}function ce(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Dn(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Ar:BigInt("0x"+r)}var Kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function _s(r){if(r>=Kt._0&&r<=Kt._9)return r-Kt._0;if(r>=Kt.A&&r<=Kt.F)return r-(Kt.A-10);if(r>=Kt.a&&r<=Kt.f)return r-(Kt.a-10)}function ue(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=_s(r.charCodeAt(s)),a=_s(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 Ht(r){return Dn(qt(r))}function Qt(r){return Pe(r),Dn(qt(Uint8Array.from(r).reverse()))}function te(r,t){return ue(r.toString(16).padStart(t*2,"0"))}function fe(r,t){return te(r,t).reverse()}function Pc(r){return ue(ce(r))}function Y(r,t,e){let n;if(typeof t=="string")try{n=ue(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Jt(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 zt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Pe(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 kc(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 Cc(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Tn=r=>typeof r=="bigint"&&Ar<=r;function Ye(r,t,e){return Tn(r)&&Tn(t)&&Tn(e)&&t<=r&&r<e}function yt(r,t,e,n){if(!Ye(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Nn(r){let t;for(t=0;r>Ar;r>>=Br,t+=1);return t}function Mc(r,t){return r>>BigInt(t)&Br}function Oc(r,t,e){return r|(e?Br:Ar)<<BigInt(t)}var We=r=>(Rc<<BigInt(r-1))-Br,_n=r=>new Uint8Array(r),Ds=r=>Uint8Array.from(r);function Rn(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=_n(r),o=_n(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...l)=>e(o,n,...l),c=(l=_n())=>{o=a(Ds([0]),l),n=a(),l.length!==0&&(o=a(Ds([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 zt(...p)};return(l,p)=>{i(),c(l);let x;for(;!(x=p(f()));)c();return i(),x}}var Kc={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"||Jt(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 Pt(r,t,e={}){let n=(o,s,i)=>{let a=Kc[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 qc=()=>{throw new Error("not implemented")};function le(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 et=BigInt(0),G=BigInt(1),he=BigInt(2),Hc=BigInt(3),Un=BigInt(4),Ns=BigInt(5),Rs=BigInt(8),zc=BigInt(9),Vc=BigInt(16);function z(r,t){let e=r%t;return e>=et?e:t+e}function Fc(r,t,e){if(t<et)throw new Error("invalid exponent, negatives unsupported");if(e<=et)throw new Error("invalid modulus");if(e===G)return et;let n=G;for(;t>et;)t&G&&(n=n*r%e),r=r*r%e,t>>=G;return n}function Z(r,t,e){let n=r;for(;t-- >et;)n*=n,n%=e;return n}function Lr(r,t){if(r===et)throw new Error("invert: expected non-zero number");if(t<=et)throw new Error("invert: expected positive modulus, got "+t);let e=z(r,t),n=t,o=et,s=G,i=G,a=et;for(;e!==et;){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!==G)throw new Error("invert: does not exist");return z(o,t)}function Gc(r){let t=(r-G)/he,e,n,o;for(e=r-G,n=0;e%he===et;e/=he,n++);for(o=he;o<r&&Fc(o,t,r)!==r-G;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+G)/Un;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+G)/he;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 g=a.sqr(p);x<f&&!a.eql(g,a.ONE);x++)g=a.sqr(g);let E=a.pow(u,G<<BigInt(f-x-1));u=a.sqr(E),l=a.mul(l,E),p=a.mul(p,u),f=x}return l}}function Zc(r){if(r%Un===Hc){let t=(r+G)/Un;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%Rs===Ns){let t=(r-Ns)/Rs;return function(n,o){let s=n.mul(o,he),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,he),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%Vc,Gc(r)}var Us=(r,t)=>(z(r,t)&G)===G,Yc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Pn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Yc.reduce((n,o)=>(n[o]="function",n),t);return Pt(r,e)}function Wc(r,t,e){if(e<et)throw new Error("invalid exponent, negatives unsupported");if(e===et)return r.ONE;if(e===G)return t;let n=r.ONE,o=t;for(;e>et;)e&G&&(n=r.mul(n,o)),o=r.sqr(o),e>>=G;return n}function Xc(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 kn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function ee(r,t,e=!1,n={}){if(r<=et)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=kn(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:We(o),ZERO:et,ONE:G,create:c=>z(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return et<=c&&c<r},is0:c=>c===et,isOdd:c=>(c&G)===G,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)=>Wc(a,c,f),div:(c,f)=>z(c*Lr(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Lr(c,r),sqrt:n.sqrt||(c=>(i||(i=Zc(r)),i(a,c))),invertBatch:c=>Xc(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>e?fe(c,s):te(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?Qt(c):Ht(c)}});return Object.freeze(a)}function Ps(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 Cn(r){let t=Ps(r);return t+Math.ceil(t/2)}function ks(r,t,e=!1){let n=r.length,o=Ps(t),s=Cn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Qt(r):Ht(r),a=z(i,t-G)+G;return e?fe(a,o):te(a,o)}var Cs=BigInt(0),Tr=BigInt(1);function Mn(r,t){let e=t.negate();return r?e:t}function Ms(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function On(r,t){Ms(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function $c(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 jc(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 Kn=new WeakMap,Os=new WeakMap;function qn(r){return Os.get(r)||1}function _r(r,t){return{constTimeNegate:Mn,hasPrecomputes(e){return qn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Cs;)n&Tr&&(o=o.add(s)),s=s.double(),n>>=Tr;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=On(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}=On(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+=Tr);let g=x,h=x+Math.abs(E)-1,y=p%2!==0,S=E<0;E===0?c=c.add(Mn(y,n[g])):a=a.add(Mn(S,n[h]))}return{p:a,f:c}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:a}=On(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===Cs)break;let x=Number(o&c);if(o>>=u,x>a&&(x-=f,o+=Tr),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=Kn.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&Kn.set(n,o(s))),s},wNAFCached(e,n,o){let s=qn(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=qn(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Ms(n,t),Os.set(e,n),Kn.delete(e)}}}function Dr(r,t,e,n){if($c(e,r),jc(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=Nn(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],g=Number(E>>BigInt(l)&BigInt(a));c[g]=c[g].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 Xe(r){return Pn(r.Fp),Pt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...kn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Dt=BigInt(0),xt=BigInt(1),Nr=BigInt(2),Jc=BigInt(8),Qc={zip215:!0};function tu(r){let t=Xe(r);return Pt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Ks(r){let t=tu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,f=Nr<<BigInt(a*8)-xt,u=e.create,l=ee(t.n,t.nBitLength),p=t.uvRatio||((b,d)=>{try{return{isValid:!0,value:e.sqrt(b*e.inv(d))}}catch{return{isValid:!1,value:Dt}}}),x=t.adjustScalarBytes||(b=>b),E=t.domain||((b,d,w)=>{if(_t("phflag",w),d.length||w)throw new Error("Contexts/pre-hash are not supported");return b});function g(b,d){yt("coordinate "+b,d,Dt,f)}function h(b){if(!(b instanceof m))throw new Error("ExtendedPoint expected")}let y=le((b,d)=>{let{ex:w,ey:A,ez:R}=b,U=b.is0();d==null&&(d=U?Jc:e.inv(R));let C=u(w*d),O=u(A*d),P=u(R*d);if(U)return{x:Dt,y:xt};if(P!==xt)throw new Error("invZ was invalid");return{x:C,y:O}}),S=le(b=>{let{a:d,d:w}=t;if(b.is0())throw new Error("bad point: ZERO");let{ex:A,ey:R,ez:U,et:C}=b,O=u(A*A),P=u(R*R),H=u(U*U),V=u(H*H),nt=u(O*d),ot=u(H*u(nt+P)),it=u(V+u(w*u(O*P)));if(ot!==it)throw new Error("bad point: equation left != right (1)");let ct=u(A*R),bt=u(U*C);if(ct!==bt)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(d,w,A,R){this.ex=d,this.ey=w,this.ez=A,this.et=R,g("x",d),g("y",w),g("z",A),g("t",R),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 g("x",w),g("y",A),new m(w,A,xt,u(w*A))}static normalizeZ(d){let w=e.invertBatch(d.map(A=>A.ez));return d.map((A,R)=>A.toAffine(w[R])).map(m.fromAffine)}static msm(d,w){return Dr(m,l,d,w)}_setWindowSize(d){N.setWindowSize(this,d)}assertValidity(){S(this)}equals(d){h(d);let{ex:w,ey:A,ez:R}=this,{ex:U,ey:C,ez:O}=d,P=u(w*O),H=u(U*R),V=u(A*O),nt=u(C*R);return P===H&&V===nt}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:R}=this,U=u(w*w),C=u(A*A),O=u(Nr*u(R*R)),P=u(d*U),H=w+A,V=u(u(H*H)-U-C),nt=P+C,ot=nt-O,it=P-C,ct=u(V*ot),bt=u(nt*it),dt=u(V*it),Ut=u(ot*nt);return new m(ct,bt,Ut,dt)}add(d){h(d);let{a:w,d:A}=t,{ex:R,ey:U,ez:C,et:O}=this,{ex:P,ey:H,ez:V,et:nt}=d;if(w===BigInt(-1)){let Xo=u((U-R)*(H+P)),$o=u((U+R)*(H-P)),dn=u($o-Xo);if(dn===Dt)return this.double();let jo=u(C*Nr*nt),Jo=u(O*Nr*V),Qo=Jo+jo,ts=$o+Xo,es=Jo-jo,ca=u(Qo*dn),ua=u(ts*es),fa=u(Qo*es),la=u(dn*ts);return new m(ca,ua,la,fa)}let ot=u(R*P),it=u(U*H),ct=u(O*A*nt),bt=u(C*V),dt=u((R+U)*(P+H)-ot-it),Ut=bt-ct,Ct=bt+ct,qe=u(it-w*ot),oa=u(dt*Ut),sa=u(Ct*qe),ia=u(dt*qe),aa=u(Ut*Ct);return new m(oa,sa,aa,ia)}subtract(d){return this.add(d.negate())}wNAF(d){return N.wNAFCached(this,d,m.normalizeZ)}multiply(d){let w=d;yt("scalar",w,xt,n);let{p:A,f:R}=this.wNAF(w);return m.normalizeZ([A,R])[0]}multiplyUnsafe(d,w=m.ZERO){let A=d;return yt("scalar",A,Dt,n),A===Dt?D:this.is0()||A===xt?this:N.wNAFCachedUnsafe(this,A,m.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(d){return y(this,d)}clearCofactor(){let{h:d}=t;return d===xt?this:this.multiplyUnsafe(d)}static fromHex(d,w=!1){let{d:A,a:R}=t,U=e.BYTES;d=Y("pointHex",d,U),_t("zip215",w);let C=d.slice(),O=d[U-1];C[U-1]=O&-129;let P=Qt(C),H=w?f:e.ORDER;yt("pointHex.y",P,Dt,H);let V=u(P*P),nt=u(V-xt),ot=u(A*V-R),{isValid:it,value:ct}=p(nt,ot);if(!it)throw new Error("Point.fromHex: invalid y coordinate");let bt=(ct&xt)===xt,dt=(O&128)!==0;if(!w&&ct===Dt&&dt)throw new Error("Point.fromHex: x=0 and x_0=1");return dt!==bt&&(ct=u(-ct)),m.fromAffine({x:ct,y:P})}static fromPrivateKey(d){return L(d).point}toRawBytes(){let{x:d,y:w}=this.toAffine(),A=fe(w,e.BYTES);return A[A.length-1]|=d&xt?128:0,A}toHex(){return qt(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,xt,u(t.Gx*t.Gy)),m.ZERO=new m(Dt,xt,xt,Dt);let{BASE:B,ZERO:D}=m,N=_r(m,a*8);function I(b){return z(b,n)}function _(b){return I(Qt(b))}function L(b){let d=e.BYTES;b=Y("private key",b,d);let w=Y("hashed private key",s(b),2*d),A=x(w.slice(0,d)),R=w.slice(d,2*d),U=_(A),C=B.multiply(U),O=C.toRawBytes();return{head:A,prefix:R,scalar:U,point:C,pointBytes:O}}function F(b){return L(b).pointBytes}function K(b=new Uint8Array,...d){let w=zt(...d);return _(s(E(w,Y("context",b),!!o)))}function M(b,d,w={}){b=Y("message",b),o&&(b=o(b));let{prefix:A,scalar:R,pointBytes:U}=L(d),C=K(w.context,A,b),O=B.multiply(C).toRawBytes(),P=K(w.context,O,U,b),H=I(C+P*R);yt("signature.s",H,Dt,n);let V=zt(O,fe(H,e.BYTES));return Y("result",V,e.BYTES*2)}let Q=Qc;function v(b,d,w,A=Q){let{context:R,zip215:U}=A,C=e.BYTES;b=Y("signature",b,2*C),d=Y("message",d),w=Y("publicKey",w,C),U!==void 0&&_t("zip215",U),o&&(d=o(d));let O=Qt(b.slice(C,2*C)),P,H,V;try{P=m.fromHex(w,U),H=m.fromHex(b.slice(0,C),U),V=B.multiplyUnsafe(O)}catch{return!1}if(!U&&P.isSmallOrder())return!1;let nt=K(R,H.toRawBytes(),P.toRawBytes(),d);return H.add(P.multiplyUnsafe(nt)).subtract(V).clearCofactor().equals(m.ZERO)}return B._setWindowSize(8),{CURVE:t,getPublicKey:F,sign:M,verify:v,ExtendedPoint:m,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>i(e.BYTES),precompute(b=8,d=m.BASE){return d._setWindowSize(b),d.multiply(BigInt(3)),d}}}}var Hn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),qs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),$l=BigInt(0),eu=BigInt(1),Hs=BigInt(2),jl=BigInt(3),ru=BigInt(5),nu=BigInt(8);function ou(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Hn,a=r*r%s*r%s,c=Z(a,Hs,s)*a%s,f=Z(c,eu,s)*r%s,u=Z(f,ru,s)*f%s,l=Z(u,t,s)*u%s,p=Z(l,e,s)*l%s,x=Z(p,n,s)*p%s,E=Z(x,o,s)*x%s,g=Z(E,o,s)*x%s,h=Z(g,t,s)*u%s;return{pow_p_5_8:Z(h,Hs,s)*r%s,b2:a}}function su(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function iu(r,t){let e=Hn,n=z(t*t*t,e),o=z(n*n*t,e),s=ou(r*o).pow_p_5_8,i=z(r*n*s,e),a=z(t*i*i,e),c=i,f=z(i*qs,e),u=a===r,l=a===z(-r,e),p=a===z(-r*qs,e);return u&&(i=c),(l||p)&&(i=f),Us(i,e)&&(i=z(-i,e)),{isValid:u||l,value:i}}var au=ee(Hn,void 0,!0),cu={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:au,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:nu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ts,randomBytes:Re,adjustScalarBytes:su,uvRatio:iu},zs=Ks(cu);var Rr=32;function Vs(r,t,e){return zs.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Ur=class{type="Ed25519";raw;constructor(t){this.raw=zn(t,Rr)}toMultihash(){return Ot.digest(de(this))}toCID(){return gt.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:At(this.raw,t.raw)}verify(t,e){return Vs(this.raw,e,t)}};function Vn(r){return r=zn(r,Rr),new Ur(r)}function zn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new tt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function Vt(r=0){return new Uint8Array(r)}function ut(r=0){return new Uint8Array(r)}var fu=Math.pow(2,7),lu=Math.pow(2,14),hu=Math.pow(2,21),Fn=Math.pow(2,28),Gn=Math.pow(2,35),Zn=Math.pow(2,42),Yn=Math.pow(2,49),q=128,ft=127;function Nt(r){if(r<fu)return 1;if(r<lu)return 2;if(r<hu)return 3;if(r<Fn)return 4;if(r<Gn)return 5;if(r<Zn)return 6;if(r<Yn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Wn(r,t,e=0){switch(Nt(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 du(r,t,e=0){switch(Nt(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 Xn(r,t){let e=r[t],n=0;if(n+=e&ft,e<q||(e=r[t+1],n+=(e&ft)<<7,e<q)||(e=r[t+2],n+=(e&ft)<<14,e<q)||(e=r[t+3],n+=(e&ft)<<21,e<q)||(e=r[t+4],n+=(e&ft)*Fn,e<q)||(e=r[t+5],n+=(e&ft)*Gn,e<q)||(e=r[t+6],n+=(e&ft)*Zn,e<q)||(e=r[t+7],n+=(e&ft)*Yn,e<q))return n;throw new RangeError("Could not decode varint")}function pu(r,t){let e=r.get(t),n=0;if(n+=e&ft,e<q||(e=r.get(t+1),n+=(e&ft)<<7,e<q)||(e=r.get(t+2),n+=(e&ft)<<14,e<q)||(e=r.get(t+3),n+=(e&ft)<<21,e<q)||(e=r.get(t+4),n+=(e&ft)*Fn,e<q)||(e=r.get(t+5),n+=(e&ft)*Gn,e<q)||(e=r.get(t+6),n+=(e&ft)*Zn,e<q)||(e=r.get(t+7),n+=(e&ft)*Yn,e<q))return n;throw new RangeError("Could not decode varint")}function Gs(r,t,e=0){return t==null&&(t=ut(Nt(r))),t instanceof Uint8Array?Wn(r,t,e):du(r,t,e)}function Zs(r,t=0){return r instanceof Uint8Array?Xn(r,t):pu(r,t)}var $n=new Float32Array([-0]),re=new Uint8Array($n.buffer);function Ws(r,t,e){$n[0]=r,t[e]=re[0],t[e+1]=re[1],t[e+2]=re[2],t[e+3]=re[3]}function Xs(r,t){return re[0]=r[t],re[1]=r[t+1],re[2]=r[t+2],re[3]=r[t+3],$n[0]}var jn=new Float64Array([-0]),lt=new Uint8Array(jn.buffer);function $s(r,t,e){jn[0]=r,t[e]=lt[0],t[e+1]=lt[1],t[e+2]=lt[2],t[e+3]=lt[3],t[e+4]=lt[4],t[e+5]=lt[5],t[e+6]=lt[6],t[e+7]=lt[7]}function js(r,t){return lt[0]=r[t],lt[1]=r[t+1],lt[2]=r[t+2],lt[3]=r[t+3],lt[4]=r[t+4],lt[5]=r[t+5],lt[6]=r[t+6],lt[7]=r[t+7],jn[0]}var mu=BigInt(Number.MAX_SAFE_INTEGER),bu=BigInt(Number.MIN_SAFE_INTEGER),vt=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 pe;if(t<mu&&t>bu)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>Js&&(o=0n,++n>Js&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return pe;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):pe}},pe=new vt(0,0);pe.toBigInt=function(){return 0n};pe.zzEncode=pe.zzDecode=function(){return this};pe.length=function(){return 1};var Js=4294967296n;function Qs(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 ti(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 Jn(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 Pr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Qn=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 Pr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Rt(this,4);return Pr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Rt(this,4);let t=Xs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Rt(this,4);let t=js(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 ti(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 vt(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=Pr(this.buf,this.pos+=4),e=Pr(this.buf,this.pos+=4);return new vt(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=Xn(this.buf,this.pos);return this.pos+=Nt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function to(r){return new Qn(r instanceof Uint8Array?r:r.subarray())}function wt(r,t,e){let n=to(r);return t.decode(n,void 0,e)}var eo={};pt(eo,{base10:()=>gu});var gu=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var ro={};pt(ro,{base16:()=>yu,base16upper:()=>xu});var yu=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),xu=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var no={};pt(no,{base2:()=>wu});var wu=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var oo={};pt(oo,{base256emoji:()=>Bu});var ri=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}"),Eu=ri.reduce((r,t,e)=>(r[e]=t,r),[]),Su=ri.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function vu(r){return r.reduce((t,e)=>(t+=Eu[e],t),"")}function Au(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Su[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Bu=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:vu,decode:Au});var so={};pt(so,{base64:()=>Iu,base64pad:()=>Lu,base64url:()=>Tu,base64urlpad:()=>_u});var Iu=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Lu=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Tu=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),_u=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var io={};pt(io,{base8:()=>Du});var Du=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ao={};pt(ao,{identity:()=>Nu});var Nu=Ae({prefix:"\0",name:"identity",encode:r=>cs(r),decode:r=>as(r)});var Uh=new TextEncoder,Ph=new TextDecoder;var fo={};pt(fo,{sha256:()=>me,sha512:()=>Pu});function uo({name:r,code:t,encode:e}){return new co(r,t,e)}var co=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 oi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var me=uo({name:"sha2-256",code:18,encode:oi("SHA-256")}),Pu=uo({name:"sha2-512",code:19,encode:oi("SHA-512")});var lo={...ao,...no,...io,...eo,...ro,...wn,...En,...xn,...so,...oo},Zh={...fo,...An};function ii(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var si=ii("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ho=ii("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=ut(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ku={utf8:si,"utf-8":si,hex:lo.base16,latin1:ho,ascii:ho,binary:ho,...lo},kr=ku;function W(r,t="utf8"){let e=kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function po(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ut(i);o+i>t&&(n=ut(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 mo(){}var go=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Cu=po();function Mu(r){return globalThis.Buffer!=null?ut(r):Cu(r)}var je=class{len;head;tail;states;constructor(){this.len=0,this.head=new be(mo,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 yo((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Cr,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=vt.fromBigInt(t);return this._push(Cr,e.length(),e)}uint64Number(t){return this._push(Wn,Nt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=vt.fromBigInt(t).zzEncode();return this._push(Cr,e.length(),e)}sint64Number(t){let e=vt.fromNumber(t).zzEncode();return this._push(Cr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(bo,1,t?1:0)}fixed32(t){return this._push($e,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=vt.fromBigInt(t);return this._push($e,4,e.lo)._push($e,4,e.hi)}fixed64Number(t){let e=vt.fromNumber(t);return this._push($e,4,e.lo)._push($e,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(Ws,4,t)}double(t){return this._push($s,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(bo,1,0):this.uint32(e)._push(Ku,e,t)}string(t){let e=Qs(t);return e!==0?this.uint32(e)._push(Jn,e,t):this._push(bo,1,0)}fork(){return this.states=new go(this),this.head=this.tail=new be(mo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new be(mo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Mu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function bo(r,t,e){t[e]=r&255}function Ou(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var yo=class extends be{next;constructor(t,e){super(Ou,t,e),this.next=void 0}};function Cr(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 $e(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 Ku(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(je.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(qu,t,r),this},je.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Hu,t,r),this});function qu(r,t,e){t.set(r,e)}function Hu(r,t,e){r.length<40?Jn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(W(r),e)}function xo(){return new je}function Et(r,t){let e=xo();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 Mr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function wo(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 Mr("enum",ke.VARINT,e,n)}function St(r,t){return Mr("message",ke.LENGTH_DELIMITED,r,t)}var Bt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var rt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(rt||(rt={}));var Eo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(Eo||(Eo={}));(function(r){r.codec=()=>wo(Eo)})(rt||(rt={}));var kt;(function(r){let t;r.codec=()=>(t==null&&(t=St((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),rt.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=rt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(kt||(kt={}));var So;(function(r){let t;r.codec=()=>(t==null&&(t=St((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),rt.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=rt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(So||(So={}));var tr={};pt(tr,{MAX_RSA_KEY_SIZE:()=>Lo,generateRSAKeyPair:()=>Ei,jwkToJWKKeyPair:()=>Si,jwkToPkcs1:()=>Qu,jwkToPkix:()=>_o,jwkToRSAPrivateKey:()=>wi,pkcs1ToJwk:()=>gi,pkcs1ToRSAPrivateKey:()=>xi,pkixToJwk:()=>yi,pkixToRSAPublicKey:()=>Do});var zu=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]),ne=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),oe=new Uint32Array(64),vo=class extends Ue{constructor(){super(64,32,8,!1),this.A=ne[0]|0,this.B=ne[1]|0,this.C=ne[2]|0,this.D=ne[3]|0,this.E=ne[4]|0,this.F=ne[5]|0,this.G=ne[6]|0,this.H=ne[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)oe[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let p=oe[l-15],x=oe[l-2],E=Tt(p,7)^Tt(p,18)^p>>>3,g=Tt(x,17)^Tt(x,19)^x>>>10;oe[l]=g+oe[l-7]+E+oe[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+Bs(a,c,f)+zu[l]+oe[l]|0,g=(Tt(n,2)^Tt(n,13)^Tt(n,22))+Is(n,o,s)|0;u=f,f=c,c=a,a=i+x|0,i=s,s=o,o=n,n=x+g|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(){oe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Ce=Sr(()=>new vo);function J(r,t="utf8"){let e=kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}function ge(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ut(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ui=Symbol.for("@achingbrain/uint8arraylist");function ci(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 Or(r){return!!r?.[ui]}var at=class r{bufs;length;[ui]=!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(Or(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(Or(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=ci(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ci(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(Or(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 ge(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ge(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(!Or(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=ut(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=Vt(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=Vt(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=Vt(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=ut(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=Vt(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=Vt(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=Vt(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=Vt(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=Vt(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(!At(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 Vu=parseInt("11111",2),Bo=parseInt("10000000",2),Fu=parseInt("01111111",2),fi={2:Gu,3:Wu,5:Yu,6:Zu,16:Ao,22:Ao,48:Ao};function Je(r,t={offset:0}){let e=r[t.offset]&Vu;if(t.offset++,fi[e]!=null)return fi[e](r,t);throw new Error("No decoder for tag "+e)}function Kr(r,t){let e=0;if((r[t.offset]&Bo)===Bo){let n=r[t.offset]&Fu,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 Ao(r,t){Kr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Je(r,t);if(n===null)break;e.push(n)}return e}function Gu(r,t){let e=Kr(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 Zu(r,t){let e=Kr(r,t);return t.offset+=e,["oid-unimplemented"]}function Yu(r,t){return t.offset++,null}function Wu(r,t){let e=Kr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return Je(o,{offset:0})}function Xu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new at;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Io(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Xu(r.byteLength);return new at(Uint8Array.from([t.byteLength|Bo]),t)}function It(r){let t=new at,e=parseInt("10000000",2);return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new at(Uint8Array.from([2]),Io(t),t)}function li(r){let t=Uint8Array.from([0]),e=new at(t,r);return new at(Uint8Array.from([3]),Io(e),e)}function qr(r){let t=new at;for(let e of r)t.append(e);return new at(Uint8Array.from([48]),Io(t),t)}function Hr(r){if(isNaN(r)||r<=0)throw new tt("random bytes length must be a Number bigger than 0");return Re(r)}var Qe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var hi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new zr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var se=hi;async function di(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 $u(t);return{privateKey:e[0],publicKey:e[1]}}async function pi(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 mi(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 $u(r){if(r.privateKey==null||r.publicKey==null)throw new tt("Private and public key are required");return Promise.all([se.get().subtle.exportKey("jwk",r.privateKey),se.get().subtle.exportKey("jwk",r.publicKey)])}function bi(r){if(r.kty!=="RSA")throw new tt("invalid key type");if(r.n==null)throw new tt("invalid key modulus");return W(r.n,"base64url").length*8}var Me=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=tr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return gt.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:At(this.raw,t.raw)}verify(t,e){return mi(this._key,e,t)}},er=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=tr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:At(this.raw,t.raw)}sign(t){return pi(this._key,t)}};var Lo=8192,To=18,ju=1062,Ju=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function gi(r){let t=Je(r);return{n:J(t[1],"base64url"),e:J(t[2],"base64url"),d:J(t[3],"base64url"),p:J(t[4],"base64url"),q:J(t[5],"base64url"),dp:J(t[6],"base64url"),dq:J(t[7],"base64url"),qi:J(t[8],"base64url"),kty:"RSA"}}function Qu(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new tt("JWK was missing components");return qr([It(Uint8Array.from([0])),It(W(r.n,"base64url")),It(W(r.e,"base64url")),It(W(r.d,"base64url")),It(W(r.p,"base64url")),It(W(r.q,"base64url")),It(W(r.dp,"base64url")),It(W(r.dq,"base64url")),It(W(r.qi,"base64url"))]).subarray()}function yi(r){let t=Je(r,{offset:0});return{kty:"RSA",n:J(t[1][0],"base64url"),e:J(t[1][1],"base64url")}}function _o(r){if(r.n==null||r.e==null)throw new tt("JWK was missing components");return qr([Ju,li(qr([It(W(r.n,"base64url")),It(W(r.e,"base64url"))]))]).subarray()}function xi(r){let t=gi(r);return wi(t)}function Do(r,t){if(r.byteLength>=ju)throw new Se("Key size is too large");let e=yi(r);if(t==null){let n=Ce(kt.encode({Type:rt.RSA,Data:r}));t=Lt(To,n)}return new Me(e,t)}function wi(r){if(bi(r)>Lo)throw new tt("Key size is too large");let t=Si(r),e=Ce(kt.encode({Type:rt.RSA,Data:_o(t.publicKey)})),n=Lt(To,e);return new er(t.privateKey,new Me(t.publicKey,n))}async function Ei(r){if(r>Lo)throw new tt("Key size is too large");let t=await di(r),e=Ce(kt.encode({Type:rt.RSA,Data:_o(t.publicKey)})),n=Lt(To,e);return new er(t.privateKey,new Me(t.publicKey,n))}function Si(r){if(r==null)throw new tt("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var Vr=class extends Ne{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ss(t);let n=Ze(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 De(this),this.iHash.update(t),this}digestInto(t){De(this),_e(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()}},No=(r,t,e)=>new Vr(r,t).update(e).digest();No.create=(r,t)=>new Vr(r,t);function vi(r){r.lowS!==void 0&&_t("lowS",r.lowS),r.prehash!==void 0&&_t("prehash",r.prehash)}function tf(r){let t=Xe(r);Pt(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:ef,hexToBytes:rf}=Ir,Ro=class extends Error{constructor(t=""){super(t)}},Ft={Err:Ro,_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=ce(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ce(o.length/2|128):"";return ce(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=ce(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 ef(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Ft,o=typeof r=="string"?rf(r):r;Pe(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}=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),st=BigInt(1),gp=BigInt(2),Ai=BigInt(3),yp=BigInt(4);function nf(r){let t=tf(r),{Fp:e}=t,n=ee(t.n,t.nBitLength),o=t.toBytes||((g,h,y)=>{let S=h.toAffine();return zt(Uint8Array.from([4]),e.toBytes(S.x),e.toBytes(S.y))}),s=t.fromBytes||(g=>{let h=g.subarray(1),y=e.fromBytes(h.subarray(0,e.BYTES)),S=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:y,y:S}});function i(g){let{a:h,b:y}=t,S=e.sqr(g),m=e.mul(S,g);return e.add(e.add(m,e.mul(g,h)),y)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(g){return Ye(g,st,t.n)}function c(g){let{allowedPrivateKeyLengths:h,nByteLength:y,wrapPrivateKey:S,n:m}=t;if(h&&typeof g!="bigint"){if(Jt(g)&&(g=qt(g)),typeof g!="string"||!h.includes(g.length))throw new Error("invalid private key");g=g.padStart(y*2,"0")}let B;try{B=typeof g=="bigint"?g:Ht(Y("private key",g,y))}catch{throw new Error("invalid private key, expected hex or "+y+" bytes, got "+typeof g)}return S&&(B=z(B,m)),yt("private key",B,st,m),B}function f(g){if(!(g instanceof p))throw new Error("ProjectivePoint expected")}let u=le((g,h)=>{let{px:y,py:S,pz:m}=g;if(e.eql(m,e.ONE))return{x:y,y:S};let B=g.is0();h==null&&(h=B?e.ONE:e.inv(m));let D=e.mul(y,h),N=e.mul(S,h),I=e.mul(m,h);if(B)return{x:e.ZERO,y:e.ZERO};if(!e.eql(I,e.ONE))throw new Error("invZ was invalid");return{x:D,y:N}}),l=le(g=>{if(g.is0()){if(t.allowInfinityPoint&&!e.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:h,y}=g.toAffine();if(!e.isValid(h)||!e.isValid(y))throw new Error("bad point: x or y not FE");let S=e.sqr(y),m=i(h);if(!e.eql(S,m))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class p{constructor(h,y,S){if(this.px=h,this.py=y,this.pz=S,h==null||!e.isValid(h))throw new Error("x required");if(y==null||!e.isValid(y))throw new Error("y required");if(S==null||!e.isValid(S))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:y,y:S}=h||{};if(!h||!e.isValid(y)||!e.isValid(S))throw new Error("invalid affine point");if(h instanceof p)throw new Error("projective point not allowed");let m=B=>e.eql(B,e.ZERO);return m(y)&&m(S)?p.ZERO:new p(y,S,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let y=e.invertBatch(h.map(S=>S.pz));return h.map((S,m)=>S.toAffine(y[m])).map(p.fromAffine)}static fromHex(h){let y=p.fromAffine(s(Y("pointHex",h)));return y.assertValidity(),y}static fromPrivateKey(h){return p.BASE.multiply(c(h))}static msm(h,y){return Dr(p,n,h,y)}_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:y,py:S,pz:m}=this,{px:B,py:D,pz:N}=h,I=e.eql(e.mul(y,N),e.mul(B,m)),_=e.eql(e.mul(S,N),e.mul(D,m));return I&&_}negate(){return new p(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:y}=t,S=e.mul(y,Ai),{px:m,py:B,pz:D}=this,N=e.ZERO,I=e.ZERO,_=e.ZERO,L=e.mul(m,m),F=e.mul(B,B),K=e.mul(D,D),M=e.mul(m,B);return M=e.add(M,M),_=e.mul(m,D),_=e.add(_,_),N=e.mul(h,_),I=e.mul(S,K),I=e.add(N,I),N=e.sub(F,I),I=e.add(F,I),I=e.mul(N,I),N=e.mul(M,N),_=e.mul(S,_),K=e.mul(h,K),M=e.sub(L,K),M=e.mul(h,M),M=e.add(M,_),_=e.add(L,L),L=e.add(_,L),L=e.add(L,K),L=e.mul(L,M),I=e.add(I,L),K=e.mul(B,D),K=e.add(K,K),L=e.mul(K,M),N=e.sub(N,L),_=e.mul(K,F),_=e.add(_,_),_=e.add(_,_),new p(N,I,_)}add(h){f(h);let{px:y,py:S,pz:m}=this,{px:B,py:D,pz:N}=h,I=e.ZERO,_=e.ZERO,L=e.ZERO,F=t.a,K=e.mul(t.b,Ai),M=e.mul(y,B),Q=e.mul(S,D),v=e.mul(m,N),T=e.add(y,S),b=e.add(B,D);T=e.mul(T,b),b=e.add(M,Q),T=e.sub(T,b),b=e.add(y,m);let d=e.add(B,N);return b=e.mul(b,d),d=e.add(M,v),b=e.sub(b,d),d=e.add(S,m),I=e.add(D,N),d=e.mul(d,I),I=e.add(Q,v),d=e.sub(d,I),L=e.mul(F,b),I=e.mul(K,v),L=e.add(I,L),I=e.sub(Q,L),L=e.add(Q,L),_=e.mul(I,L),Q=e.add(M,M),Q=e.add(Q,M),v=e.mul(F,v),b=e.mul(K,b),Q=e.add(Q,v),v=e.sub(M,v),v=e.mul(F,v),b=e.add(b,v),M=e.mul(Q,b),_=e.add(_,M),M=e.mul(d,b),I=e.mul(T,I),I=e.sub(I,M),M=e.mul(T,Q),L=e.mul(d,L),L=e.add(L,M),new p(I,_,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:y,n:S}=t;yt("scalar",h,Gt,S);let m=p.ZERO;if(h===Gt)return m;if(this.is0()||h===st)return this;if(!y||E.hasPrecomputes(this))return E.wNAFCachedUnsafe(this,h,p.normalizeZ);let{k1neg:B,k1:D,k2neg:N,k2:I}=y.splitScalar(h),_=m,L=m,F=this;for(;D>Gt||I>Gt;)D&st&&(_=_.add(F)),I&st&&(L=L.add(F)),F=F.double(),D>>=st,I>>=st;return B&&(_=_.negate()),N&&(L=L.negate()),L=new p(e.mul(L.px,y.beta),L.py,L.pz),_.add(L)}multiply(h){let{endo:y,n:S}=t;yt("scalar",h,st,S);let m,B;if(y){let{k1neg:D,k1:N,k2neg:I,k2:_}=y.splitScalar(h),{p:L,f:F}=this.wNAF(N),{p:K,f:M}=this.wNAF(_);L=E.constTimeNegate(D,L),K=E.constTimeNegate(I,K),K=new p(e.mul(K.px,y.beta),K.py,K.pz),m=L.add(K),B=F.add(M)}else{let{p:D,f:N}=this.wNAF(h);m=D,B=N}return p.normalizeZ([m,B])[0]}multiplyAndAddUnsafe(h,y,S){let m=p.BASE,B=(N,I)=>I===Gt||I===st||!N.equals(m)?N.multiplyUnsafe(I):N.multiply(I),D=B(this,y).add(B(h,S));return D.is0()?void 0:D}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:y}=t;if(h===st)return!0;if(y)return y(p,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:y}=t;return h===st?this:y?y(p,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return _t("isCompressed",h),this.assertValidity(),o(p,this,h)}toHex(h=!0){return _t("isCompressed",h),qt(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=_r(p,t.endo?Math.ceil(x/2):x);return{CURVE:t,ProjectivePoint:p,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function of(r){let t=Xe(r);return Pt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Bi(r){let t=of(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(v){return z(v,n)}function a(v){return Lr(v,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=nf({...t,toBytes(v,T,b){let d=T.toAffine(),w=e.toBytes(d.x),A=zt;return _t("isCompressed",b),b?A(Uint8Array.from([T.hasEvenY()?2:3]),w):A(Uint8Array.from([4]),w,e.toBytes(d.y))},fromBytes(v){let T=v.length,b=v[0],d=v.subarray(1);if(T===o&&(b===2||b===3)){let w=Ht(d);if(!Ye(w,st,e.ORDER))throw new Error("Point is not on curve");let A=u(w),R;try{R=e.sqrt(A)}catch(O){let P=O instanceof Error?": "+O.message:"";throw new Error("Point is not on curve"+P)}let U=(R&st)===st;return(b&1)===1!==U&&(R=e.neg(R)),{x:w,y:R}}else if(T===s&&b===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 "+T)}}}),p=v=>qt(te(v,t.nByteLength));function x(v){let T=n>>st;return v>T}function E(v){return x(v)?i(-v):v}let g=(v,T,b)=>Ht(v.slice(T,b));class h{constructor(T,b,d){this.r=T,this.s=b,this.recovery=d,this.assertValidity()}static fromCompact(T){let b=t.nByteLength;return T=Y("compactSignature",T,b*2),new h(g(T,0,b),g(T,b,2*b))}static fromDER(T){let{r:b,s:d}=Ft.toSig(Y("DER",T));return new h(b,d)}assertValidity(){yt("r",this.r,st,n),yt("s",this.s,st,n)}addRecoveryBit(T){return new h(this.r,this.s,T)}recoverPublicKey(T){let{r:b,s:d,recovery:w}=this,A=N(Y("msgHash",T));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let R=w===2||w===3?b+t.n:b;if(R>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let U=(w&1)===0?"02":"03",C=c.fromHex(U+p(R)),O=a(R),P=i(-A*O),H=i(d*O),V=c.BASE.multiplyAndAddUnsafe(C,P,H);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 ue(this.toDERHex())}toDERHex(){return Ft.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ue(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}let y={isValidPrivateKey(v){try{return f(v),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let v=Cn(t.n);return ks(t.randomBytes(v),t.n)},precompute(v=8,T=c.BASE){return T._setWindowSize(v),T.multiply(BigInt(3)),T}};function S(v,T=!0){return c.fromPrivateKey(v).toRawBytes(T)}function m(v){let T=Jt(v),b=typeof v=="string",d=(T||b)&&v.length;return T?d===o||d===s:b?d===2*o||d===2*s:v instanceof c}function B(v,T,b=!0){if(m(v))throw new Error("first arg must be private key");if(!m(T))throw new Error("second arg must be public key");return c.fromHex(T).multiply(f(v)).toRawBytes(b)}let D=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let T=Ht(v),b=v.length*8-t.nBitLength;return b>0?T>>BigInt(b):T},N=t.bits2int_modN||function(v){return i(D(v))},I=We(t.nBitLength);function _(v){return yt("num < 2^"+t.nBitLength,v,Gt,I),te(v,t.nByteLength)}function L(v,T,b=F){if(["recovered","canonical"].some(ot=>ot in b))throw new Error("sign() legacy options not supported");let{hash:d,randomBytes:w}=t,{lowS:A,prehash:R,extraEntropy:U}=b;A==null&&(A=!0),v=Y("msgHash",v),vi(b),R&&(v=Y("prehashed msgHash",d(v)));let C=N(v),O=f(T),P=[_(O),_(C)];if(U!=null&&U!==!1){let ot=U===!0?w(e.BYTES):U;P.push(Y("extraEntropy",ot))}let H=zt(...P),V=C;function nt(ot){let it=D(ot);if(!l(it))return;let ct=a(it),bt=c.BASE.multiply(it).toAffine(),dt=i(bt.x);if(dt===Gt)return;let Ut=i(ct*i(V+dt*O));if(Ut===Gt)return;let Ct=(bt.x===dt?0:2)|Number(bt.y&st),qe=Ut;return A&&x(Ut)&&(qe=E(Ut),Ct^=1),new h(dt,qe,Ct)}return{seed:H,k2sig:nt}}let F={lowS:t.lowS,prehash:!1},K={lowS:t.lowS,prehash:!1};function M(v,T,b=F){let{seed:d,k2sig:w}=L(v,T,b),A=t;return Rn(A.hash.outputLen,A.nByteLength,A.hmac)(d,w)}c.BASE._setWindowSize(8);function Q(v,T,b,d=K){let w=v;T=Y("msgHash",T),b=Y("publicKey",b);let{lowS:A,prehash:R,format:U}=d;if(vi(d),"strict"in d)throw new Error("options.strict was renamed to lowS");if(U!==void 0&&U!=="compact"&&U!=="der")throw new Error("format must be compact or der");let C=typeof w=="string"||Jt(w),O=!C&&!U&&typeof w=="object"&&w!==null&&typeof w.r=="bigint"&&typeof w.s=="bigint";if(!C&&!O)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let P,H;try{if(O&&(P=new h(w.r,w.s)),C){try{U!=="compact"&&(P=h.fromDER(w))}catch(Ct){if(!(Ct instanceof Ft.Err))throw Ct}!P&&U!=="der"&&(P=h.fromCompact(w))}H=c.fromHex(b)}catch{return!1}if(!P||A&&P.hasHighS())return!1;R&&(T=t.hash(T));let{r:V,s:nt}=P,ot=N(T),it=a(nt),ct=i(ot*it),bt=i(V*it),dt=c.BASE.multiplyAndAddUnsafe(H,ct,bt)?.toAffine();return dt?i(dt.x)===V:!1}return{CURVE:t,getPublicKey:S,getSharedSecret:B,sign:M,verify:Q,ProjectivePoint:c,Signature:h,utils:y}}function sf(r){return{hash:r,hmac:(t,...e)=>No(r,t,Bn(...e)),randomBytes:Re}}function Ii(r,t){let e=n=>Bi({...r,...sf(n)});return{...e(t),create:e}}var _i=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Li=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),af=BigInt(1),Uo=BigInt(2),Ti=(r,t)=>(r+t/Uo)/t;function cf(r){let t=_i,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=Z(u,e,t)*u%t,p=Z(l,e,t)*u%t,x=Z(p,Uo,t)*f%t,E=Z(x,o,t)*x%t,g=Z(E,s,t)*E%t,h=Z(g,a,t)*g%t,y=Z(h,c,t)*h%t,S=Z(y,a,t)*g%t,m=Z(S,e,t)*u%t,B=Z(m,i,t)*E%t,D=Z(B,n,t)*f%t,N=Z(D,Uo,t);if(!Po.eql(Po.sqr(N),r))throw new Error("Cannot find square root");return N}var Po=ee(_i,void 0,void 0,{sqrt:cf}),ye=Ii({a:BigInt(0),b:BigInt(7),Fp:Po,n:Li,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Li,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-af*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=Ti(s*r,t),c=Ti(-n*r,t),f=z(r-a*e-c*o,t),u=z(-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}}}},Ce),Lp=BigInt(0);var Tp=ye.ProjectivePoint;function Di(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Ni(r,t,e){let n=me.digest(e instanceof Uint8Array?e:e.subarray());if(Di(n))return n.then(({digest:o})=>ye.verify(t,o,r)).catch(o=>{throw new Qe(String(o))});try{return ye.verify(t,n.digest,r)}catch(o){throw new Qe(String(o))}}var Fr=class{type="secp256k1";raw;_key;constructor(t){this._key=Ui(t),this.raw=Ri(this._key)}toMultihash(){return Ot.digest(de(this))}toCID(){return gt.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:At(this.raw,t.raw)}verify(t,e){return Ni(this._key,e,t)}};function ko(r){return new Fr(r)}function Ri(r){return ye.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Ui(r){try{return ye.ProjectivePoint.fromHex(r),r}catch(t){throw new Se(String(t))}}function Co(r,t){let{Type:e,Data:n}=kt.decode(r),o=n??new Uint8Array;switch(e){case rt.RSA:return Do(o,t);case rt.Ed25519:return Vn(o);case rt.secp256k1:return ko(o);default:throw new ie}}function Pi(r){let{Type:t,Data:e}=kt.decode(r.digest),n=e??new Uint8Array;switch(t){case rt.Ed25519:return Vn(n);case rt.secp256k1:return ko(n);default:throw new ie}}function de(r){return kt.encode({Type:rt[r.type],Data:r.raw})}var ki=Symbol.for("nodejs.util.inspect.custom"),uf=114,rr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[pn]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return gt.createV1(uf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return At(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return At(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ki](){return`PeerId(${this.toString()})`}},nr=class extends rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},or=class extends rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},sr=class extends rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ff=2336,Gr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ot.digest(W(this.url))}[ki](){return`PeerId(${this.url})`}[pn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return gt.createV1(ff,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=J(t)),t.toString()===this.toString())}};function Mo(r){if(r.type==="Ed25519")return new or({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new sr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new nr({multihash:r.toCID().multihash,publicKey:r});throw new ie}function Ci(r){return Mo(r.publicKey)}function ir(r){if(hf(r))return new nr({multihash:r});if(lf(r))try{let t=Pi(r);if(t.type==="Ed25519")return new or({multihash:r,publicKey:t});if(t.type==="secp256k1")return new sr({multihash:r,publicKey:t})}catch{let e=J(r.digest);return new Gr(new URL(e))}throw new yr("Supplied PeerID Multihash is invalid")}function lf(r){return r.code===Ot.code}function hf(r){return r.code===me.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 ir(t)}var ar=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return 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 cr=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return 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 Yr=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 Yr(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 Yr(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Oo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Wr(r={}){return df(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 df(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,y)=>{s=S=>{s=null,n.push(S);try{h(r(n))}catch(m){y(m)}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})},p=h=>i?o:(i=!0,h!=null?u(h):f({done:!0})),x=()=>(n=new Oe,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 y=h?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let S,m;y!=null&&(S=new Promise((B,D)=>{m=()=>{D(new Oo)},y.addEventListener("abort",m)}));try{await Promise.race([a.promise,S])}finally{m!=null&&y!=null&&y?.removeEventListener("abort",m)}}},e==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(h){return g.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return g.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(h){return g.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return g.readableLength},onEmpty:h=>g.onEmpty(h)},o}var Xr=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 Mi(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Xr(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Xr(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 Ko=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 Mi(this.readNext.promise,e?.signal,e)}};function Oi(){return new Ko}function pf(r){return r[Symbol.asyncIterator]!=null}async function mf(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=Oi();mf(r,t).catch(()=>{}),yield*t}function*gf(r){for(let t of r)yield*t}function yf(...r){let t=[];for(let e of r)pf(e)||t.push(e);return t.length===r.length?gf(t):bf(r)}var Ki=yf;function ur(r,...t){if(r==null)throw new Error("Empty pipeline");if(qo(r)){let n=r;r=()=>n.source}else if(Hi(r)||qi(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&qo(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)qo(e[n])&&(e[n]=wf(e[n]));return xf(...e)}var xf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},qi=r=>r?.[Symbol.asyncIterator]!=null,Hi=r=>r?.[Symbol.iterator]!=null,qo=r=>r==null?!1:r.sink!=null&&r.source!=null,wf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Wr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(qi(s))o=async function*(){yield*s,n.end()};else if(Hi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Ki(n,o())}return r.source};var zo=ya(Vi(),1);var lr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Vo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Fi=r=>globalThis.DOMException===void 0?new Vo(r):new DOMException(r),Gi=r=>{let t=r.reason===void 0?Fi("This operation was aborted."):r.reason;return t instanceof Error?t:Fi(t)};function Fo(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(Gi(x)),a=()=>{l(Gi(x))},x.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,l);return}let p=new lr;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 Go(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var hr=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let o=Go(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var dr=class extends zo.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#b;#x=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:hr,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#b=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.#y(),this.#g(),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.#g(),!0):!1}}return!1}#g(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#y()},this.#a),this.#p=Date.now()+this.#a)}#y(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#B(t){return new Promise((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.#b,...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=Fo(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#B(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof lr&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function Zi(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 Yi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Wi(r,t){let e=Zi(r).return?.();Yi(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var jr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ke=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Jr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},pr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Qr(r){return r[Symbol.asyncIterator]!=null}function Xi(r,t){if(r.byteLength>t)throw new Ke("Message length too long")}var en=r=>{let t=Nt(r),e=ut(t);return Gs(r,e),en.bytes=t,e};en.bytes=0;function rn(r,t){t=t??{};let e=t.lengthEncoder??en,n=t?.maxDataLength??4194304;function*o(s){Xi(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return Qr(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}rn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??en,n=t?.maxDataLength??4194304;return Xi(r,n),new at(e(r.byteLength),r)};var we;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(we||(we={}));var Zo=r=>{let t=Zs(r);return Zo.bytes=Nt(t),t};Zo.bytes=0;function mr(r,t){let e=new at,n=we.LENGTH,o=-1,s=t?.lengthDecoder??Zo,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 jr("Invalid message length");if(o>a)throw new Ke("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 Jr("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 Qr(r)?async function*(){for await(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new pr("Unexpected end of input")}():function*(){for(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new pr("Unexpected end of input")}()}mr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return mr(n,{...t??{},onLength:s=>{e=s}})};var nn=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 at(t):t)}attachInboundStream(t,e){let n=()=>{Wi(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=ur(this._rawInboundStream,o=>mr(o,e)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let e=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=Wr({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),ur(this.outboundStream,n=>rn(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 $i(){return BigInt(`0x${J(Hr(8),"base16")}`)}var ji=(r,t)=>{let e=W(t.toString(16).padStart(16,"0"),"base16"),n=de(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},Ji=r=>me.encode(r);var Qi=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=ir(Wt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return Mo(Co(e)).equals(t)}return!1},ta=async r=>{if(r.from==null)throw new $("RPC message was missing from");if(!await Bf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=ir(Wt(r.from)),e=r.key??t.publicKey;if(e==null)throw new $("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:Lf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?Co(e):e}},br=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:If(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?de(r.key):void 0}:{data:r.data,topic:r.topic},If=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),W(t,"base16")},Lf=r=>BigInt(`0x${J(r,"base16")}`);var ea=W("libp2p-pubsub:");async function ra(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Ci(r)},o=ge([ea,e(br(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function na(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=ge([ea,t({...br(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 on=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=Qi(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new ar,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new dr({concurrency:a}),this.maxInboundStreams=c,this.maxOutboundStreams=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 nn(this.components,{id:t,protocol:e});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return e}}async processMessages(t,e,n){try{await ur(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),a=[];for(let c of i.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,e,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.id,subscriptions:o.map(({topic:i,subscribe:a})=>({topic:`${i??""}`,subscribe:!!a}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let a=await ta(i);await this.processMessage(t,a)}catch(a){this.log.error(a)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new cr,this.topics.set(n,o)),e.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,e){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,e)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new $('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new $("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new $("Need key when signature policy is StrictSign but it was missing");return ji(t.key,t.sequenceNumber);case"StrictNoSign":return Ji(t.data);default:throw new $("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,e){let{messages:n,subscriptions:o,subscribe:s}=e;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(br)})}sendRpc(t,e){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(e))}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new $('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new $("StrictNoSigning: signature should not be present");if(e.key!=null)throw new $("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new $("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new $('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new $("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new $("StrictSigning: Signing required and no sequenceNumber was present");if(!await na(e,this.encodeMessage.bind(this)))throw new $("StrictSigning: Invalid message signature");break;default:throw new $("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===He.Reject||s===He.Ignore)throw new $("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return ra(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new $("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new xr("not started yet");if(t==null)throw new tt("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:$i()};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 sn=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 Yo="/floodsub/1.0.0";var Ee;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=St((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.subscribe!=null&&(a.uint32(8),a.bool(i.subscribe)),i.topic!=null&&(a.uint32(18),a.string(i.topic)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let 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=>Et(i,o.codec()),o.decode=(i,a)=>wt(i,o.codec(),a)})(t=r.SubOpts||(r.SubOpts={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=St((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.from!=null&&(a.uint32(10),a.bytes(i.from)),i.data!=null&&(a.uint32(18),a.bytes(i.data)),i.sequenceNumber!=null&&(a.uint32(26),a.bytes(i.sequenceNumber)),i.topic!=null&&(a.uint32(34),a.string(i.topic)),i.signature!=null&&(a.uint32(42),a.bytes(i.signature)),i.key!=null&&(a.uint32(50),a.bytes(i.key)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let 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=>Et(i,o.codec()),o.decode=(i,a)=>wt(i,o.codec(),a)})(e=r.Message||(r.Message={}));let n;r.codec=()=>(n==null&&(n=St((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.subscriptions!=null)for(let a of o.subscriptions)s.uint32(10),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),an.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=an.codec().decode(o,o.uint32(),{limits:i.limits?.control});break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Et(o,r.codec()),r.decode=(o,s)=>wt(o,r.codec(),s)})(Ee||(Ee={}));var an;(function(r){let t;r.codec=()=>(t==null&&(t=St((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.ihave!=null)for(let s of e.ihave)n.uint32(10),cn.codec().encode(s,n);if(e.iwant!=null)for(let s of e.iwant)n.uint32(18),un.codec().encode(s,n);if(e.graft!=null)for(let s of e.graft)n.uint32(26),fn.codec().encode(s,n);if(e.prune!=null)for(let s of e.prune)n.uint32(34),ln.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(cn.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(un.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(fn.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(ln.codec().decode(e,e.uint32(),{limits:o.limits?.prune$}));break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(an||(an={}));var cn;(function(r){let t;r.codec=()=>(t==null&&(t=St((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=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(cn||(cn={}));var un;(function(r){let t;r.codec=()=>(t==null&&(t=St((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=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(un||(un={}));var fn;(function(r){let t;r.codec=()=>(t==null&&(t=St((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=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(fn||(fn={}));var ln;(function(r){let t;r.codec=()=>(t==null&&(t=St((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),hn.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(hn.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=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(ln||(ln={}));var hn;(function(r){let t;r.codec=()=>(t==null&&(t=St((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=>Et(e,r.codec()),r.decode=(e,n)=>wt(e,r.codec(),n)})(hn||(hn={}));var Wo=class extends on{seenCache;constructor(t,e){super(t,{...e,canRelayMessage:!0,multicodecs:[Yo]}),this.log=t.logger.forComponent("libp2p:floodsub"),this.seenCache=new sn({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=J(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 _f(r={}){return t=>new Wo(t,r)}return xa(Df);})();
|
|
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.31-071267286",
|
|
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": "
|
|
64
|
-
"@libp2p/pubsub": "
|
|
63
|
+
"@libp2p/interface": "2.7.0-071267286",
|
|
64
|
+
"@libp2p/pubsub": "10.1.8-071267286",
|
|
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": "
|
|
71
|
-
"@libp2p/interface-compliance-tests": "
|
|
72
|
-
"@libp2p/logger": "
|
|
73
|
-
"@libp2p/peer-collections": "
|
|
74
|
-
"@libp2p/peer-id": "
|
|
70
|
+
"@libp2p/crypto": "5.0.15-071267286",
|
|
71
|
+
"@libp2p/interface-compliance-tests": "6.4.2-071267286",
|
|
72
|
+
"@libp2p/logger": "5.1.13-071267286",
|
|
73
|
+
"@libp2p/peer-collections": "6.0.25-071267286",
|
|
74
|
+
"@libp2p/peer-id": "5.1.0-071267286",
|
|
75
75
|
"@multiformats/multiaddr": "^12.3.3",
|
|
76
76
|
"@types/sinon": "^17.0.3",
|
|
77
77
|
"aegir": "^45.1.1",
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"FloodSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.FloodSubComponents.html",
|
|
3
|
-
".:FloodSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.FloodSubComponents.html",
|
|
4
|
-
"FloodSubInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.FloodSubInit.html",
|
|
5
|
-
".:FloodSubInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.FloodSubInit.html",
|
|
6
|
-
"multicodec": "https://libp2p.github.io/js-libp2p/variables/_libp2p_floodsub.multicodec.html",
|
|
7
|
-
"floodsub": "https://libp2p.github.io/js-libp2p/functions/_libp2p_floodsub.floodsub.html",
|
|
8
|
-
".:floodsub": "https://libp2p.github.io/js-libp2p/functions/_libp2p_floodsub.floodsub.html"
|
|
9
|
-
}
|