@libp2p/pubsub 10.1.17-cb1c14e62 → 10.1.17-cf9aab5c8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPubsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PPubsub=(()=>{var Ta=Object.create;var Dr=Object.defineProperty;var Da=Object.getOwnPropertyDescriptor;var Pa=Object.getOwnPropertyNames;var Ca=Object.getPrototypeOf,Ra=Object.prototype.hasOwnProperty;var Ka=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ht=(r,t)=>{for(var e in t)Dr(r,e,{get:t[e],enumerable:!0})},ps=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pa(t))!Ra.call(r,o)&&o!==e&&Dr(r,o,{get:()=>t[o],enumerable:!(n=Da(t,o))||n.enumerable});return r};var Na=(r,t,e)=>(e=r!=null?Ta(Ca(r)):{},ps(t||!r||!r.__esModule?Dr(e,"default",{value:r,enumerable:!0}):e,r)),Ua=r=>ps(Dr({},"__esModule",{value:!0}),r);var pa=Ka((ym,ss)=>{"use strict";var Pf=Object.prototype.hasOwnProperty,lt="~";function vr(){}Object.create&&(vr.prototype=Object.create(null),new vr().__proto__||(lt=!1));function Cf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function da(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new Cf(e,n||r,o),i=lt?lt+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function dn(r,t){--r._eventsCount===0?r._events=new vr:delete r._events[t]}function ut(){this._events=new vr,this._eventsCount=0}ut.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Pf.call(e,n)&&t.push(lt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};ut.prototype.listeners=function(t){var e=lt?lt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};ut.prototype.listenerCount=function(t){var e=lt?lt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};ut.prototype.emit=function(t,e,n,o,s,i){var a=lt?lt+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,d,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,d=new Array(f-1);l<f;l++)d[l-1]=arguments[l];c.fn.apply(c.context,d)}else{var u=c.length,h;for(l=0;l<u;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(!d)for(h=1,d=new Array(f-1);h<f;h++)d[h-1]=arguments[h];c[l].fn.apply(c[l].context,d)}}return!0};ut.prototype.on=function(t,e,n){return da(this,t,e,n,!1)};ut.prototype.once=function(t,e,n){return da(this,t,e,n,!0)};ut.prototype.removeListener=function(t,e,n,o){var s=lt?lt+t:t;if(!this._events[s])return this;if(!e)return dn(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&dn(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:dn(this,s)}return this};ut.prototype.removeAllListeners=function(t){var e;return t?(e=lt?lt+t:t,this._events[e]&&dn(this,e)):(this._events=new vr,this._eventsCount=0),this};ut.prototype.off=ut.prototype.removeListener;ut.prototype.addListener=ut.prototype.on;ut.prefixed=lt;ut.EventEmitter=ut;typeof ss<"u"&&(ss.exports=ut)});var Mf={};ht(Mf,{PubSubBaseProtocol:()=>ls});var En=Symbol.for("@libp2p/peer-id");var Ye;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ye||(Ye={}));var Vf=Symbol.for("@libp2p/pubsub");var j=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ae=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Pr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var J=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Cr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ce=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Ie=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Bn={};ht(Bn,{base58btc:()=>Y,base58flickr:()=>Fa});var Zf=new Uint8Array(0);function ms(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 Pt(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 ys(r){return new TextEncoder().encode(r)}function bs(r){return new TextDecoder().decode(r)}function ka(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),d=Math.log(256)/Math.log(a);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var w=0,p=0,S=0,B=g.length;S!==B&&g[S]===0;)S++,w++;for(var v=(B-S)*d+1>>>0,T=new Uint8Array(v);S!==B;){for(var R=g[S],_=0,U=v-1;(R!==0||_<p)&&U!==-1;U--,_++)R+=256*T[U]>>>0,T[U]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");p=_,S++}for(var k=v-p;k!==v&&T[k]===0;)k++;for(var D=c.repeat(w);k<v;++k)D+=r.charAt(T[k]);return D}function u(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var w=0;if(g[w]!==" "){for(var p=0,S=0;g[w]===c;)p++,w++;for(var B=(g.length-w)*f+1>>>0,v=new Uint8Array(B);g[w];){var T=e[g.charCodeAt(w)];if(T===255)return;for(var R=0,_=B-1;(T!==0||R<S)&&_!==-1;_--,R++)T+=a*v[_]>>>0,v[_]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");S=R,w++}if(g[w]!==" "){for(var U=B-S;U!==B&&v[U]===0;)U++;for(var k=new Uint8Array(p+(B-U)),D=p;U!==B;)k[D++]=v[U++];return k}}}function h(g){var w=u(g);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:u,decode:h}}var Oa=ka,Ma=Oa,ws=Ma;var Sn=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")}},vn=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 xs(this,t)}},An=class{decoders;constructor(t){this.decoders=t}or(t){return xs(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 xs(r,t){return new An({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var In=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 Sn(t,e,n),this.decoder=new vn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Be({name:r,prefix:t,encode:e,decode:n}){return new In(r,t,e,n)}function Xt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ws(e,r);return Be({prefix:t,name:r,encode:n,decode:s=>Pt(o(s))})}function qa(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let d=t[r[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ha(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Va(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function X({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Va(n);return Be({prefix:t,name:r,encode(s){return Ha(s,n,e)},decode(s){return qa(s,o,e,r)}})}var Y=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Fa=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _n={};ht(_n,{base32:()=>_e,base32hex:()=>ja,base32hexpad:()=>Xa,base32hexpadupper:()=>$a,base32hexupper:()=>Ya,base32pad:()=>Ga,base32padupper:()=>Za,base32upper:()=>za,base32z:()=>Wa});var _e=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),za=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ga=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Za=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ja=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ya=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Xa=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),$a=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Wa=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ln={};ht(Ln,{base36:()=>Xe,base36upper:()=>Ja});var Xe=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ja=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Qa=vs,Es=128,tc=127,ec=~tc,rc=Math.pow(2,31);function vs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=rc;)t[e++]=r&255|Es,r/=128;for(;r&ec;)t[e++]=r&255|Es,r>>>=7;return t[e]=r|0,vs.bytes=e-n+1,t}var nc=Tn,oc=128,Ss=127;function Tn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Tn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Ss)<<o:(i&Ss)*Math.pow(2,o),o+=7}while(i>=oc);return Tn.bytes=s-n,e}var sc=Math.pow(2,7),ic=Math.pow(2,14),ac=Math.pow(2,21),cc=Math.pow(2,28),uc=Math.pow(2,35),fc=Math.pow(2,42),lc=Math.pow(2,49),hc=Math.pow(2,56),dc=Math.pow(2,63),pc=function(r){return r<sc?1:r<ic?2:r<ac?3:r<cc?4:r<uc?5:r<fc?6:r<lc?7:r<hc?8:r<dc?9:10},mc={encode:Qa,decode:nc,encodingLength:pc},yc=mc,$e=yc;function We(r,t=0){return[$e.decode(r,t),$e.decode.bytes]}function Le(r,t,e=0){return $e.encode(r,t,e),t}function Te(r){return $e.encodingLength(r)}function vt(r,t){let e=t.byteLength,n=Te(r),o=n+Te(e),s=new Uint8Array(o+e);return Le(r,s,0),Le(e,s,n),s.set(t,o),new De(r,e,t,s)}function $t(r){let t=Pt(r),[e,n]=We(t),[o,s]=We(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new De(e,o,i,t)}function As(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ms(r.bytes,e.bytes)}}var De=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Is(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return gc(e,Dn(r),t??Y.encoder);default:return wc(e,Dn(r),t??_e.encoder)}}var Bs=new WeakMap;function Dn(r){let t=Bs.get(r);if(t==null){let e=new Map;return Bs.set(r,e),e}return t}var st=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Je)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==xc)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=vt(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&&As(t.multihash,n.multihash)}toString(t){return Is(this,t)}toJSON(){return{"/":Is(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??_s(n,o,s.bytes))}else if(e[Ec]===!0){let{version:n,multihash:o,code:s}=e,i=$t(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Je)throw new Error(`Version 0 CID must use dag-pb (code: ${Je}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=_s(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Je,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Pt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new De(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,u]=We(t.subarray(e));return e+=u,l},o=n(),s=Je;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,d=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,e){let[n,o]=bc(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 Dn(s).set(n,t),s}};function bc(r,t){switch(r[0]){case"Q":{let e=t??Y;return[Y.prefix,e.decode(`${Y.prefix}${r}`)]}case Y.prefix:{let e=t??Y;return[Y.prefix,e.decode(r)]}case _e.prefix:{let e=t??_e;return[_e.prefix,e.decode(r)]}case Xe.prefix:{let e=t??Xe;return[Xe.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 gc(r,t,e){let{prefix:n}=e;if(n!==Y.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 wc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Je=112,xc=18;function _s(r,t,e){let n=Te(r),o=n+Te(t),s=new Uint8Array(o+e.byteLength);return Le(r,s,0),Le(t,s,n),s.set(e,o),s}var Ec=Symbol.for("@ipld/js-cid/CID");var Pn={};ht(Pn,{identity:()=>At});var Ls=0,Sc="identity",Ts=Pt;function vc(r){return vt(Ls,Ts(r))}var At={code:Ls,name:Sc,encode:Ts,digest:vc};function dt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ct(r=0){return new Uint8Array(r)}function it(r=0){return new Uint8Array(r)}function ue(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=it(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Ps=Symbol.for("@achingbrain/uint8arraylist");function Ds(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 Kr(r){return!!r?.[Ps]}var et=class r{bufs;length;[Ps]=!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(Kr(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(Kr(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=Ds(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ds(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(Kr(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 ue(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ue(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,d=e>a&&e<=c;if(f&&d){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(d){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(!Kr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(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,d;for(let l=e;l<=c;l+=d){d=0;for(let u=f;u>=0;u--){let h=this.get(l+u);if(n[u]!==h){d=Math.max(1,u-a[h]);break}}if(d===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=it(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=Ct(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=Ct(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=Ct(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=it(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=Ct(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=Ct(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=Ct(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=Ct(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=Ct(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!dt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Cn={};ht(Cn,{base10:()=>Ac});var Ac=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var Rn={};ht(Rn,{base16:()=>Ic,base16upper:()=>Bc});var Ic=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bc=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Kn={};ht(Kn,{base2:()=>_c});var _c=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Nn={};ht(Nn,{base256emoji:()=>Cc});var Cs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Lc=Cs.reduce((r,t,e)=>(r[e]=t,r),[]),Tc=Cs.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Dc(r){return r.reduce((t,e)=>(t+=Lc[e],t),"")}function Pc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Tc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Cc=Be({prefix:"\u{1F680}",name:"base256emoji",encode:Dc,decode:Pc});var Un={};ht(Un,{base64:()=>Rc,base64pad:()=>Kc,base64url:()=>Nc,base64urlpad:()=>Uc});var Rc=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Kc=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Nc=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Uc=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var kn={};ht(kn,{base8:()=>kc});var kc=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var On={};ht(On,{identity:()=>Oc});var Oc=Be({prefix:"\0",name:"identity",encode:r=>bs(r),decode:r=>ys(r)});var Tl=new TextEncoder,Dl=new TextDecoder;var Hn={};ht(Hn,{sha256:()=>fe,sha512:()=>Hc});function qn({name:r,code:t,encode:e}){return new Mn(r,t,e)}var Mn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?vt(this.code,e):e.then(n=>vt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ks(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var fe=qn({name:"sha2-256",code:18,encode:Ks("SHA-256")}),Hc=qn({name:"sha2-512",code:19,encode:Ks("SHA-512")});var Vn={...On,...Kn,...kn,...Cn,...Rn,..._n,...Ln,...Bn,...Un,...Nn},Vl={...Hn,...Pn};function Us(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ns=Us("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Fn=Us("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=it(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Vc={utf8:Ns,"utf-8":Ns,hex:Vn.base16,latin1:Fn,ascii:Fn,binary:Fn,...Vn},Nr=Vc;function F(r,t="utf8"){let e=Nr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function z(r,t="utf8"){let e=Nr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Fc=parseInt("11111",2),zn=parseInt("10000000",2),zc=parseInt("01111111",2),ks={0:Qe,1:Qe,2:Gc,3:Yc,4:Xc,5:jc,6:Zc,16:Qe,22:Qe,48:Qe};function Rt(r,t={offset:0}){let e=r[t.offset]&Fc;if(t.offset++,ks[e]!=null)return ks[e](r,t);throw new Error("No decoder for tag "+e)}function tr(r,t){let e=0;if((r[t.offset]&zn)===zn){let n=r[t.offset]&zc,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 Qe(r,t){tr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Rt(r,t);if(n===null)break;e.push(n)}return e}function Gc(r,t){let e=tr(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 Zc(r,t){let e=tr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let d=0;for(let l=0;l<c.length;l++)d+=c[l]<<l*7;a+=`.${d}`,c=[]}}return a}function jc(r,t){return t.offset++,null}function Yc(r,t){let e=tr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Xc(r,t){let e=tr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function $c(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new et;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Gn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=$c(r.byteLength);return new et(Uint8Array.from([t.byteLength|zn]),t)}function pt(r){let t=new et,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new et(Uint8Array.from([2]),Gn(t),t)}function Ur(r){let t=Uint8Array.from([0]),e=new et(t,r);return new et(Uint8Array.from([3]),Gn(e),e)}function Jt(r,t=48){let e=new et;for(let n of r)e.append(n);return new et(Uint8Array.from([t]),Gn(e),e)}async function Os(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Wc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Jc=Uint8Array.from([6,5,43,129,4,0,34]),Qc=Uint8Array.from([6,5,43,129,4,0,35]),tu={ext:!0,kty:"EC",crv:"P-256"},eu={ext:!0,kty:"EC",crv:"P-384"},ru={ext:!0,kty:"EC",crv:"P-521"},Zn=32,jn=48,Yn=66;function Xn(r){let t=Rt(r);return Ms(t)}function Ms(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Zn*2+1)return n=z(t.subarray(e,e+Zn),"base64url"),o=z(t.subarray(e+Zn),"base64url"),new Pe({...tu,key_ops:["verify"],x:n,y:o});if(t.byteLength===jn*2+1)return n=z(t.subarray(e,e+jn),"base64url"),o=z(t.subarray(e+jn),"base64url"),new Pe({...eu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Yn*2+1)return n=z(t.subarray(e,e+Yn),"base64url"),o=z(t.subarray(e+Yn),"base64url"),new Pe({...ru,key_ops:["verify"],x:n,y:o});throw new j(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function qs(r){return Jt([pt(Uint8Array.from([1])),Jt([nu(r.crv)],160),Jt([Ur(new et(Uint8Array.from([4]),F(r.x??"","base64url"),F(r.y??"","base64url")))],161)]).subarray()}function nu(r){if(r==="P-256")return Wc;if(r==="P-384")return Jc;if(r==="P-521")return Qc;throw new j(`Invalid curve ${r}`)}var Pe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=qs(this.jwk)),this._raw}toMultihash(){return At.digest(Kt(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}async verify(t,e,n){return Os(this.jwk,e,t,n)}};var le=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function he(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function er(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function $(r,...t){if(!he(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 kr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");er(r.outputLen),er(r.blockLen)}function Re(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Vs(r,t){$(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Ut(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Or(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function It(r,t){return r<<32-t|r>>>t}var Fs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ou=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Et(r){if($(r),Fs)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=ou[r[e]];return t}var Nt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Hs(r){if(r>=Nt._0&&r<=Nt._9)return r-Nt._0;if(r>=Nt.A&&r<=Nt.F)return r-(Nt.A-10);if(r>=Nt.a&&r<=Nt.f)return r-(Nt.a-10)}function de(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Fs)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Hs(r.charCodeAt(s)),a=Hs(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 $n(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function rr(r){return typeof r=="string"&&(r=$n(r)),$(r),r}function mt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];$(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Ce=class{};function Wn(r){let t=n=>r().update(rr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function pe(r=32){if(le&&typeof le.getRandomValues=="function")return le.getRandomValues(new Uint8Array(r));if(le&&typeof le.randomBytes=="function")return Uint8Array.from(le.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function su(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,f=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+f,a,n)}function zs(r,t,e){return r&t^~r&e}function Gs(r,t,e){return r&t^r&e^t&e}var nr=class extends Ce{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Or(this.buffer)}update(t){Re(this),t=rr(t),$(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Or(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),Vs(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Ut(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;su(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Or(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,d=this.get();if(f>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,d[l],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},kt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Mr=BigInt(4294967295),Zs=BigInt(32);function iu(r,t=!1){return t?{h:Number(r&Mr),l:Number(r>>Zs&Mr)}:{h:Number(r>>Zs&Mr)|0,l:Number(r&Mr)|0}}function js(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=iu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Jn=(r,t,e)=>r>>>e,Qn=(r,t,e)=>r<<32-e|t>>>e,me=(r,t,e)=>r>>>e|t<<32-e,ye=(r,t,e)=>r<<32-e|t>>>e,or=(r,t,e)=>r<<64-e|t>>>e-32,sr=(r,t,e)=>r>>>e-32|t<<64-e;function Lt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ys=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Xs=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,$s=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Ws=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Js=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Qs=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var cu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Qt=new Uint32Array(64),qr=class extends nr{constructor(t=32){super(64,t,8,!1),this.A=kt[0]|0,this.B=kt[1]|0,this.C=kt[2]|0,this.D=kt[3]|0,this.E=kt[4]|0,this.F=kt[5]|0,this.G=kt[6]|0,this.H=kt[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)Qt[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let u=Qt[l-15],h=Qt[l-2],g=It(u,7)^It(u,18)^u>>>3,w=It(h,17)^It(h,19)^h>>>10;Qt[l]=w+Qt[l-7]+g+Qt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:d}=this;for(let l=0;l<64;l++){let u=It(a,6)^It(a,11)^It(a,25),h=d+u+zs(a,c,f)+cu[l]+Qt[l]|0,w=(It(n,2)^It(n,13)^It(n,22))+Gs(n,o,s)|0;d=f,f=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+w|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,d=d+this.H|0,this.set(n,o,s,i,a,c,f,d)}roundClean(){Ut(Qt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}};var ti=js(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),uu=ti[0],fu=ti[1],te=new Uint32Array(80),ee=new Uint32Array(80),to=class extends nr{constructor(t=64){super(128,t,16,!1),this.Ah=ot[0]|0,this.Al=ot[1]|0,this.Bh=ot[2]|0,this.Bl=ot[3]|0,this.Ch=ot[4]|0,this.Cl=ot[5]|0,this.Dh=ot[6]|0,this.Dl=ot[7]|0,this.Eh=ot[8]|0,this.El=ot[9]|0,this.Fh=ot[10]|0,this.Fl=ot[11]|0,this.Gh=ot[12]|0,this.Gl=ot[13]|0,this.Hh=ot[14]|0,this.Hl=ot[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:d,Fh:l,Fl:u,Gh:h,Gl:g,Hh:w,Hl:p}=this;return[t,e,n,o,s,i,a,c,f,d,l,u,h,g,w,p]}set(t,e,n,o,s,i,a,c,f,d,l,u,h,g,w,p){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=d|0,this.Fh=l|0,this.Fl=u|0,this.Gh=h|0,this.Gl=g|0,this.Hh=w|0,this.Hl=p|0}process(t,e){for(let v=0;v<16;v++,e+=4)te[v]=t.getUint32(e),ee[v]=t.getUint32(e+=4);for(let v=16;v<80;v++){let T=te[v-15]|0,R=ee[v-15]|0,_=me(T,R,1)^me(T,R,8)^Jn(T,R,7),U=ye(T,R,1)^ye(T,R,8)^Qn(T,R,7),k=te[v-2]|0,D=ee[v-2]|0,y=me(k,D,19)^or(k,D,61)^Jn(k,D,6),m=ye(k,D,19)^sr(k,D,61)^Qn(k,D,6),E=$s(U,m,ee[v-7],ee[v-16]),A=Ws(E,_,y,te[v-7],te[v-16]);te[v]=A|0,ee[v]=E|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:d,Eh:l,El:u,Fh:h,Fl:g,Gh:w,Gl:p,Hh:S,Hl:B}=this;for(let v=0;v<80;v++){let T=me(l,u,14)^me(l,u,18)^or(l,u,41),R=ye(l,u,14)^ye(l,u,18)^sr(l,u,41),_=l&h^~l&w,U=u&g^~u&p,k=Js(B,R,U,fu[v],ee[v]),D=Qs(k,S,T,_,uu[v],te[v]),y=k|0,m=me(n,o,28)^or(n,o,34)^or(n,o,39),E=ye(n,o,28)^sr(n,o,34)^sr(n,o,39),A=n&s^n&a^s&a,P=o&i^o&c^i&c;S=w|0,B=p|0,w=h|0,p=g|0,h=l|0,g=u|0,{h:l,l:u}=Lt(f|0,d|0,D|0,y|0),f=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let C=Ys(y,E,P);n=Xs(C,D,m,A),o=C|0}({h:n,l:o}=Lt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Lt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Lt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:d}=Lt(this.Dh|0,this.Dl|0,f|0,d|0),{h:l,l:u}=Lt(this.Eh|0,this.El|0,l|0,u|0),{h,l:g}=Lt(this.Fh|0,this.Fl|0,h|0,g|0),{h:w,l:p}=Lt(this.Gh|0,this.Gl|0,w|0,p|0),{h:S,l:B}=Lt(this.Hh|0,this.Hl|0,S|0,B|0),this.set(n,o,s,i,a,c,f,d,l,u,h,g,w,p,S,B)}roundClean(){Ut(te,ee)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Hr=Wn(()=>new qr);var ei=Wn(()=>new to);var no=BigInt(0),ro=BigInt(1);function Ot(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function ir(r){let t=r.toString(16);return t.length&1?"0"+t:t}function ri(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?no:BigInt("0x"+r)}function Ke(r){return ri(Et(r))}function Mt(r){return $(r),ri(Et(Uint8Array.from(r).reverse()))}function Vr(r,t){return de(r.toString(16).padStart(t*2,"0"))}function qt(r,t){return Vr(r,t).reverse()}function H(r,t,e){let n;if(typeof t=="string")try{n=de(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(he(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 ni(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}var eo=r=>typeof r=="bigint"&&no<=r;function oi(r,t,e){return eo(r)&&eo(t)&&eo(e)&&t<=r&&r<e}function re(r,t,e,n){if(!oi(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Fr(r){let t;for(t=0;r>no;r>>=ro,t+=1);return t}var ne=r=>(ro<<BigInt(r))-ro;function si(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=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},f=(...h)=>e(i,s,...h),d=(h=n(0))=>{i=f(o(0),h),s=f(),h.length!==0&&(i=f(o(1),h),s=f())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,g=[];for(;h<t;){s=f();let w=s.slice();g.push(w),h+=s.length}return mt(...g)};return(h,g)=>{c(),d(h);let w;for(;!(w=g(l()));)d();return c(),w}}function oe(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function Ne(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 ft=BigInt(0),nt=BigInt(1),be=BigInt(2),ci=BigInt(3),ui=BigInt(4),fi=BigInt(5),lu=BigInt(7),li=BigInt(8),hu=BigInt(9),hi=BigInt(16);function W(r,t){let e=r%t;return e>=ft?e:t+e}function Z(r,t,e){let n=r;for(;t-- >ft;)n*=n,n%=e;return n}function ii(r,t){if(r===ft)throw new Error("invert: expected non-zero number");if(t<=ft)throw new Error("invert: expected positive modulus, got "+t);let e=W(r,t),n=t,o=ft,s=nt,i=nt,a=ft;for(;e!==ft;){let f=n/e,d=n%e,l=o-i*f,u=s-a*f;n=e,e=d,o=i,s=a,i=l,a=u}if(n!==nt)throw new Error("invert: does not exist");return W(o,t)}function oo(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function di(r,t){let e=(r.ORDER+nt)/ui,n=r.pow(t,e);return oo(r,n,t),n}function du(r,t){let e=(r.ORDER-fi)/li,n=r.mul(t,be),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,be),o),a=r.mul(s,r.sub(i,r.ONE));return oo(r,a,t),a}function pu(r){let t=gt(r),e=pi(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+lu)/hi;return(a,c)=>{let f=a.pow(c,i),d=a.mul(f,n),l=a.mul(f,o),u=a.mul(f,s),h=a.eql(a.sqr(d),c),g=a.eql(a.sqr(l),c);f=a.cmov(f,d,h),d=a.cmov(u,l,g);let w=a.eql(a.sqr(d),c),p=a.cmov(f,d,w);return oo(a,p,c),p}}function pi(r){if(r<ci)throw new Error("sqrt is not defined for small field");let t=r-nt,e=0;for(;t%be===ft;)t/=be,e++;let n=be,o=gt(r);for(;ai(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return di;let s=o.pow(n,t),i=(t+nt)/be;return function(c,f){if(c.is0(f))return f;if(ai(c,f)!==1)throw new Error("Cannot find square root");let d=e,l=c.mul(c.ONE,s),u=c.pow(f,t),h=c.pow(f,i);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let g=1,w=c.sqr(u);for(;!c.eql(w,c.ONE);)if(g++,w=c.sqr(w),g===d)throw new Error("Cannot find square root");let p=nt<<BigInt(d-g-1),S=c.pow(l,p);d=g,l=c.sqr(S),u=c.mul(u,l),h=c.mul(h,S)}return h}}function mu(r){return r%ui===ci?di:r%li===fi?du:r%hi===hu?pu(r):pi(r)}var Ht=(r,t)=>(W(r,t)&nt)===nt,yu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function so(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=yu.reduce((n,o)=>(n[o]="function",n),t);return oe(r,e),r}function bu(r,t,e){if(e<ft)throw new Error("invalid exponent, negatives unsupported");if(e===ft)return r.ONE;if(e===nt)return t;let n=r.ONE,o=t;for(;e>ft;)e&nt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=nt;return n}function ar(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function ai(r,t){let e=(r.ORDER-nt)/be,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function mi(r,t){t!==void 0&&er(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function gt(r,t,e=!1,n={}){if(r<=ft)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(e=u.isLE),typeof u.modOnDecode=="boolean"&&(i=u.modOnDecode),a=u.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:f}=mi(r,o);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,l=Object.freeze({ORDER:r,isLE:e,BITS:c,BYTES:f,MASK:ne(c),ZERO:ft,ONE:nt,allowedLengths:a,create:u=>W(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return ft<=u&&u<r},is0:u=>u===ft,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&nt)===nt,neg:u=>W(-u,r),eql:(u,h)=>u===h,sqr:u=>W(u*u,r),add:(u,h)=>W(u+h,r),sub:(u,h)=>W(u-h,r),mul:(u,h)=>W(u*h,r),pow:(u,h)=>bu(l,u,h),div:(u,h)=>W(u*ii(h,r),r),sqrN:u=>u*u,addN:(u,h)=>u+h,subN:(u,h)=>u-h,mulN:(u,h)=>u*h,inv:u=>ii(u,r),sqrt:s||(u=>(d||(d=mu(r)),d(l,u))),toBytes:u=>e?qt(u,f):Vr(u,f),fromBytes:(u,h=!0)=>{if(a){if(!a.includes(u.length)||u.length>f)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);let w=new Uint8Array(f);w.set(u,e?0:w.length-u.length),u=w}if(u.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+u.length);let g=e?Mt(u):Ke(u);if(i&&(g=W(g,r)),!h&&!l.isValid(g))throw new Error("invalid field element: outside of range 0..ORDER");return g},invertBatch:u=>ar(l,u),cmov:(u,h,g)=>g?h:u});return Object.freeze(l)}function yi(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function io(r){let t=yi(r);return t+Math.ceil(t/2)}function ao(r,t,e=!1){let n=r.length,o=yi(t),s=io(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Mt(r):Ke(r),a=W(i,t-nt)+nt;return e?qt(a,o):Vr(a,o)}var Ue=BigInt(0),ge=BigInt(1);function cr(r,t){let e=t.negate();return r?e:t}function Vt(r,t){let e=ar(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function xi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function co(r,t){xi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ne(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function bi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ge);let f=t*n,d=f+Math.abs(a)-1,l=a===0,u=a<0,h=t%2!==0;return{nextN:c,offset:d,isZero:l,isNeg:u,isNegF:h,offsetF:f}}function gu(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 wu(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 uo=new WeakMap,Ei=new WeakMap;function fo(r){return Ei.get(r)||1}function gi(r){if(r!==Ue)throw new Error("invalid wNAF")}var ke=class{constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>Ue;)e&ge&&(n=n.add(o)),o=o.double(),e>>=ge;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=co(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=co(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:d,isNeg:l,isNegF:u,offsetF:h}=bi(n,a,i);n=c,d?s=s.add(cr(u,e[h])):o=o.add(cr(l,e[f]))}return gi(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=co(t,this.bits);for(let i=0;i<s.windows&&n!==Ue;i++){let{nextN:a,offset:c,isZero:f,isNeg:d}=bi(n,i,s);if(n=a,!f){let l=e[c];o=o.add(d?l.negate():l)}}return gi(n),o}getPrecomputes(t,e,n){let o=uo.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),uo.set(e,o))),o}cached(t,e,n){let o=fo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=fo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){xi(e,this.bits),Ei.set(t,e),uo.delete(t)}hasCache(t){return fo(t)!==1}};function Si(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Ue||n>Ue;)e&ge&&(s=s.add(o)),n&ge&&(i=i.add(o)),o=o.double(),e>>=ge,n>>=ge;return{p1:s,p2:i}}function Oe(r,t,e,n){gu(e,r),wu(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=Fr(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=ne(c),d=new Array(Number(f)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,u=i;for(let h=l;h>=0;h-=c){d.fill(i);for(let w=0;w<s;w++){let p=n[w],S=Number(p>>BigInt(h)&f);d[S]=d[S].add(e[w])}let g=i;for(let w=d.length-1,p=i;w>0;w--)p=p.add(d[w]),g=g.add(p);if(u=u.add(g),h!==0)for(let w=0;w<c;w++)u=u.double()}return u}function wi(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return so(t),t}else return gt(r)}function zr(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Ue))throw new Error(`CURVE.${a} must be positive bigint`)}let n=wi(t.p,e.Fp),o=wi(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Tt=BigInt(0),rt=BigInt(1),lo=BigInt(2),xu=BigInt(8);function Eu(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Su(r,t={}){let{Fp:e,Fn:n}=zr("edwards",r,t),{h:o,n:s}=r;oe(t,{},{uvRatio:"function"});let i=lo<<BigInt(n.BYTES*8)-rt,a=w=>e.create(w),c=t.uvRatio||((w,p)=>{try{return{isValid:!0,value:e.sqrt(e.div(w,p))}}catch{return{isValid:!1,value:Tt}}});if(!Eu(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function f(w,p,S=!1){let B=S?rt:Tt;return re("coordinate "+w,p,B,i),p}function d(w){if(!(w instanceof h))throw new Error("ExtendedPoint expected")}let l=Ne((w,p)=>{let{X:S,Y:B,Z:v}=w,T=w.is0();p==null&&(p=T?xu:e.inv(v));let R=a(S*p),_=a(B*p),U=e.mul(v,p);if(T)return{x:Tt,y:rt};if(U!==rt)throw new Error("invZ was invalid");return{x:R,y:_}}),u=Ne(w=>{let{a:p,d:S}=r;if(w.is0())throw new Error("bad point: ZERO");let{X:B,Y:v,Z:T,T:R}=w,_=a(B*B),U=a(v*v),k=a(T*T),D=a(k*k),y=a(_*p),m=a(k*a(y+U)),E=a(D+a(S*a(_*U)));if(m!==E)throw new Error("bad point: equation left != right (1)");let A=a(B*v),P=a(T*R);if(A!==P)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(p,S,B,v){this.X=f("x",p),this.Y=f("y",S),this.Z=f("z",B,!0),this.T=f("t",v),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(p){return Vt(h,p)}static msm(p,S){return Oe(h,n,p,S)}_setWindowSize(p){this.precompute(p)}static fromAffine(p){if(p instanceof h)throw new Error("extended point not allowed");let{x:S,y:B}=p||{};return f("x",S),f("y",B),new h(S,B,rt,a(S*B))}precompute(p=8,S=!0){return g.createCache(this,p),S||this.multiply(lo),this}assertValidity(){u(this)}equals(p){d(p);let{X:S,Y:B,Z:v}=this,{X:T,Y:R,Z:_}=p,U=a(S*_),k=a(T*v),D=a(B*_),y=a(R*v);return U===k&&D===y}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:p}=r,{X:S,Y:B,Z:v}=this,T=a(S*S),R=a(B*B),_=a(lo*a(v*v)),U=a(p*T),k=S+B,D=a(a(k*k)-T-R),y=U+R,m=y-_,E=U-R,A=a(D*m),P=a(y*E),C=a(D*E),x=a(m*y);return new h(A,P,x,C)}add(p){d(p);let{a:S,d:B}=r,{X:v,Y:T,Z:R,T:_}=this,{X:U,Y:k,Z:D,T:y}=p,m=a(v*U),E=a(T*k),A=a(_*B*y),P=a(R*D),C=a((v+T)*(U+k)-m-E),x=P-A,b=P+A,I=a(E-S*m),L=a(C*x),K=a(b*I),N=a(C*I),O=a(x*b);return new h(L,K,O,N)}subtract(p){return this.add(p.negate())}multiply(p){let S=p;re("scalar",S,rt,s);let{p:B,f:v}=g.cached(this,S,T=>Vt(h,T));return Vt(h,[B,v])[0]}multiplyUnsafe(p,S=h.ZERO){let B=p;return re("scalar",B,Tt,s),B===Tt?h.ZERO:this.is0()||B===rt?this:g.unsafe(this,B,v=>Vt(h,v),S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return g.unsafe(this,s).is0()}toAffine(p){return l(this,p)}clearCofactor(){return o===rt?this:this.multiplyUnsafe(o)}static fromBytes(p,S=!1){return $(p),h.fromHex(p,S)}static fromHex(p,S=!1){let{d:B,a:v}=r,T=e.BYTES;p=H("pointHex",p,T),Ot("zip215",S);let R=p.slice(),_=p[T-1];R[T-1]=_&-129;let U=Mt(R),k=S?i:e.ORDER;re("pointHex.y",U,Tt,k);let D=a(U*U),y=a(D-rt),m=a(B*D-v),{isValid:E,value:A}=c(y,m);if(!E)throw new Error("Point.fromHex: invalid y coordinate");let P=(A&rt)===rt,C=(_&128)!==0;if(!S&&A===Tt&&C)throw new Error("Point.fromHex: x=0 and x_0=1");return C!==P&&(A=a(-A)),h.fromAffine({x:A,y:U})}toBytes(){let{x:p,y:S}=this.toAffine(),B=qt(S,e.BYTES);return B[B.length-1]|=p&rt?128:0,B}toRawBytes(){return this.toBytes()}toHex(){return Et(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}h.BASE=new h(r.Gx,r.Gy,rt,a(r.Gx*r.Gy)),h.ZERO=new h(Tt,rt,rt,Tt),h.Fp=e,h.Fn=n;let g=new ke(h,n.BYTES*8);return h}var Gr=class{constructor(t){this.ep=t}static fromBytes(t){throw new Error("fromBytes must be implemented by subclass")}static fromHex(t){throw new Error("fromHex must be implemented by subclass")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toRawBytes(){return this.toBytes()}toHex(){return Et(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,e){return this.init(this.ep.precompute(t,e))}};function vu(r,t,e){if(typeof t!="function")throw new Error('"hash" function param is required');oe(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,c=e.randomBytes||pe,f=e.adjustScalarBytes||(m=>m),d=e.domain||((m,E,A)=>{if(Ot("phflag",A),E.length||A)throw new Error("Contexts/pre-hash are not supported");return m});function l(m){return i.create(m)}function u(m){return l(Mt(m))}function h(m){let E=s.BYTES;m=H("private key",m,E);let A=H("hashed private key",t(m),2*E),P=f(A.slice(0,E)),C=A.slice(E,2*E),x=u(P);return{head:P,prefix:C,scalar:x}}function g(m){let{head:E,prefix:A,scalar:P}=h(m),C=o.multiply(P),x=C.toBytes();return{head:E,prefix:A,scalar:P,point:C,pointBytes:x}}function w(m){return g(m).pointBytes}function p(m=Uint8Array.of(),...E){let A=mt(...E);return u(t(d(A,H("context",m),!!n)))}function S(m,E,A={}){m=H("message",m),n&&(m=n(m));let{prefix:P,scalar:C,pointBytes:x}=g(E),b=p(A.context,P,m),I=o.multiply(b).toBytes(),L=p(A.context,I,x,m),K=l(b+L*C);re("signature.s",K,Tt,a);let N=s.BYTES,O=mt(I,qt(K,N));return H("result",O,N*2)}let B={zip215:!0};function v(m,E,A,P=B){let{context:C,zip215:x}=P,b=s.BYTES;m=H("signature",m,2*b),E=H("message",E),A=H("publicKey",A,b),x!==void 0&&Ot("zip215",x),n&&(E=n(E));let I=Mt(m.slice(b,2*b)),L,K,N;try{L=r.fromHex(A,x),K=r.fromHex(m.slice(0,b),x),N=o.multiplyUnsafe(I)}catch{return!1}if(!x&&L.isSmallOrder())return!1;let O=p(C,K.toBytes(),L.toBytes(),E);return K.add(L.multiplyUnsafe(O)).subtract(N).clearCofactor().is0()}o.precompute(8);let T=s.BYTES,R={secret:T,public:T,signature:2*T,seed:T};function _(m=c(R.seed)){return m}let U={getExtendedPublicKey:g,randomSecretKey:_,isValidSecretKey:D,isValidPublicKey:y,randomPrivateKey:_,toMontgomery(m){let{y:E}=r.fromBytes(m),A=T===32;if(!A&&T!==57)throw new Error("only defined for 25519 and 448");let P=A?s.div(rt+E,rt-E):s.div(E-rt,E+rt);return s.toBytes(P)},toMontgomeryPriv(m){$(m,T);let E=t(m.subarray(0,T));return f(E).subarray(0,T)},precompute(m=8,E=r.BASE){return E.precompute(m,!1)}};function k(m){let E=U.randomSecretKey(m);return{secretKey:E,publicKey:w(E)}}function D(m){try{return!!i.fromBytes(m,!1)}catch{return!1}}function y(m,E){try{return!!r.fromBytes(m,E)}catch{return!1}}return Object.freeze({keygen:k,getPublicKey:w,sign:S,verify:v,utils:U,Point:r,info:{type:"edwards",lengths:R}})}function Au(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=gt(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,hash:r.hash,eddsaOpts:s}}function Iu(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function vi(r){let{CURVE:t,curveOpts:e,hash:n,eddsaOpts:o}=Au(r),s=Su(t,e),i=vu(s,n,o);return Iu(r,i)}var Bu=BigInt(0),Ft=BigInt(1),Ai=BigInt(2),$h=BigInt(3),_u=BigInt(5),Lu=BigInt(8),ur={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Lu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Tu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=ur.p,a=r*r%s*r%s,c=Z(a,Ai,s)*a%s,f=Z(c,Ft,s)*r%s,d=Z(f,_u,s)*f%s,l=Z(d,t,s)*d%s,u=Z(l,e,s)*l%s,h=Z(u,n,s)*u%s,g=Z(h,o,s)*h%s,w=Z(g,o,s)*h%s,p=Z(w,t,s)*d%s;return{pow_p_5_8:Z(p,Ai,s)*r%s,b2:a}}function Du(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ho=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function yo(r,t){let e=ur.p,n=W(t*t*t,e),o=W(n*n*t,e),s=Tu(r*o).pow_p_5_8,i=W(r*n*s,e),a=W(t*i*i,e),c=i,f=W(i*ho,e),d=a===r,l=a===W(-r,e),u=a===W(-r*ho,e);return d&&(i=c),(l||u)&&(i=f),Ht(i,e)&&(i=W(-i,e)),{isValid:d||l,value:i}}var we=gt(ur.p,{isLE:!0}),Pu=gt(ur.n,{isLE:!0}),Cu={...ur,Fp:we,hash:ei,adjustScalarBytes:Du,uvRatio:yo},wt=vi(Cu);var po=ho,Ru=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Ku=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Nu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Uu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ii=r=>yo(Ft,r),ku=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),mo=r=>wt.CURVE.Fp.create(Mt(r)&ku);function Bi(r){let{d:t}=wt.CURVE,e=wt.CURVE.Fp.ORDER,n=wt.CURVE.Fp.create,o=n(po*r*r),s=n((o+Ft)*Nu),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:f}=yo(s,a),d=n(f*r);Ht(d,e)||(d=n(-d)),c||(f=d),c||(i=o);let l=n(i*(o-Ft)*Uu-a),u=f*f,h=n((f+f)*a),g=n(l*Ru),w=n(Ft-u),p=n(Ft+u);return new wt.Point(n(h*p),n(w*g),n(g*p),n(h*w))}function Ou(r){$(r,64);let t=mo(r.subarray(0,32)),e=Bi(t),n=mo(r.subarray(32,64)),o=Bi(n);return new zt(e.add(o))}var zt=class r extends Gr{constructor(t){super(t)}static fromAffine(t){return new r(wt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static hashToCurve(t){return Ou(H("ristrettoHash",t,64))}static fromBytes(t){$(t,32);let{a:e,d:n}=wt.CURVE,o=we.ORDER,s=we.create,i=mo(t);if(!ni(qt(i,32),t)||Ht(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Ft+e*a),f=s(Ft-e*a),d=s(c*c),l=s(f*f),u=s(e*n*d-l),{isValid:h,value:g}=Ii(s(u*l)),w=s(g*f),p=s(g*w*u),S=s((i+i)*w);Ht(S,o)&&(S=s(-S));let B=s(c*p),v=s(S*B);if(!h||Ht(v,o)||B===Bu)throw new Error("invalid ristretto255 encoding 2");return new r(new wt.Point(S,B,Ft,v))}static fromHex(t){return r.fromBytes(H("ristrettoHex",t,32))}static msm(t,e){return Oe(r,wt.Point.Fn,t,e)}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=we.ORDER,i=we.create,a=i(i(n+e)*i(n-e)),c=i(t*e),f=i(c*c),{value:d}=Ii(i(a*f)),l=i(d*a),u=i(d*c),h=i(l*u*o),g;if(Ht(o*h,s)){let p=i(e*po),S=i(t*po);t=p,e=S,g=i(l*Ku)}else g=u;Ht(t*h,s)&&(e=i(-e));let w=i((n-e)*g);return Ht(w,s)&&(w=i(-w)),qt(w,32)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=we.create,a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};zt.BASE=new zt(wt.Point.BASE);zt.ZERO=new zt(wt.Point.ZERO);zt.Fp=we;zt.Fn=Pu;var fr=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 _i={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 St=_i;var jr=32;var bo,Mu=(async()=>{try{return await St.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function qu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await St.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await St.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Hu(r,t,e){return wt.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Li(r,t,e){return bo==null&&(bo=await Mu),bo?qu(r,t,e):Hu(r,t,e)}function Yr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Xr=class{type="Ed25519";raw;constructor(t){this.raw=go(t,jr)}toMultihash(){return At.digest(Kt(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Li(this.raw,e,t);return Yr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function wo(r){return r=go(r,jr),new Xr(r)}function go(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new j(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Fu=Math.pow(2,7),zu=Math.pow(2,14),Gu=Math.pow(2,21),xo=Math.pow(2,28),Eo=Math.pow(2,35),So=Math.pow(2,42),vo=Math.pow(2,49),M=128,at=127;function Bt(r){if(r<Fu)return 1;if(r<zu)return 2;if(r<Gu)return 3;if(r<xo)return 4;if(r<Eo)return 5;if(r<So)return 6;if(r<vo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ao(r,t,e=0){switch(Bt(r)){case 8:t[e++]=r&255|M,r/=128;case 7:t[e++]=r&255|M,r/=128;case 6:t[e++]=r&255|M,r/=128;case 5:t[e++]=r&255|M,r/=128;case 4:t[e++]=r&255|M,r>>>=7;case 3:t[e++]=r&255|M,r>>>=7;case 2:t[e++]=r&255|M,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Zu(r,t,e=0){switch(Bt(r)){case 8:t.set(e++,r&255|M),r/=128;case 7:t.set(e++,r&255|M),r/=128;case 6:t.set(e++,r&255|M),r/=128;case 5:t.set(e++,r&255|M),r/=128;case 4:t.set(e++,r&255|M),r>>>=7;case 3:t.set(e++,r&255|M),r>>>=7;case 2:t.set(e++,r&255|M),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Io(r,t){let e=r[t],n=0;if(n+=e&at,e<M||(e=r[t+1],n+=(e&at)<<7,e<M)||(e=r[t+2],n+=(e&at)<<14,e<M)||(e=r[t+3],n+=(e&at)<<21,e<M)||(e=r[t+4],n+=(e&at)*xo,e<M)||(e=r[t+5],n+=(e&at)*Eo,e<M)||(e=r[t+6],n+=(e&at)*So,e<M)||(e=r[t+7],n+=(e&at)*vo,e<M))return n;throw new RangeError("Could not decode varint")}function ju(r,t){let e=r.get(t),n=0;if(n+=e&at,e<M||(e=r.get(t+1),n+=(e&at)<<7,e<M)||(e=r.get(t+2),n+=(e&at)<<14,e<M)||(e=r.get(t+3),n+=(e&at)<<21,e<M)||(e=r.get(t+4),n+=(e&at)*xo,e<M)||(e=r.get(t+5),n+=(e&at)*Eo,e<M)||(e=r.get(t+6),n+=(e&at)*So,e<M)||(e=r.get(t+7),n+=(e&at)*vo,e<M))return n;throw new RangeError("Could not decode varint")}function Di(r,t,e=0){return t==null&&(t=it(Bt(r))),t instanceof Uint8Array?Ao(r,t,e):Zu(r,t,e)}function Pi(r,t=0){return r instanceof Uint8Array?Io(r,t):ju(r,t)}var Bo=new Float32Array([-0]),se=new Uint8Array(Bo.buffer);function Ri(r,t,e){Bo[0]=r,t[e]=se[0],t[e+1]=se[1],t[e+2]=se[2],t[e+3]=se[3]}function Ki(r,t){return se[0]=r[t],se[1]=r[t+1],se[2]=r[t+2],se[3]=r[t+3],Bo[0]}var _o=new Float64Array([-0]),ct=new Uint8Array(_o.buffer);function Ni(r,t,e){_o[0]=r,t[e]=ct[0],t[e+1]=ct[1],t[e+2]=ct[2],t[e+3]=ct[3],t[e+4]=ct[4],t[e+5]=ct[5],t[e+6]=ct[6],t[e+7]=ct[7]}function Ui(r,t){return ct[0]=r[t],ct[1]=r[t+1],ct[2]=r[t+2],ct[3]=r[t+3],ct[4]=r[t+4],ct[5]=r[t+5],ct[6]=r[t+6],ct[7]=r[t+7],_o[0]}var Yu=BigInt(Number.MAX_SAFE_INTEGER),Xu=BigInt(Number.MIN_SAFE_INTEGER),xt=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 xe;if(t<Yu&&t>Xu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>ki&&(o=0n,++n>ki&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return xe;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):xe}},xe=new xt(0,0);xe.toBigInt=function(){return 0n};xe.zzEncode=xe.zzDecode=function(){return this};xe.length=function(){return 1};var ki=4294967296n;function Oi(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 Mi(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 Lo(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 _t(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function $r(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var To=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,_t(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 _t(this,4);return $r(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw _t(this,4);return $r(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw _t(this,4);let t=Ki(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw _t(this,4);let t=Ui(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw _t(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Mi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw _t(this,t);this.pos+=t}else do if(this.pos>=this.len)throw _t(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 xt(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 _t(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 _t(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 _t(this,8);let t=$r(this.buf,this.pos+=4),e=$r(this.buf,this.pos+=4);return new xt(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=Io(this.buf,this.pos);return this.pos+=Bt(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 Do(r){return new To(r instanceof Uint8Array?r:r.subarray())}function Wr(r,t,e){let n=Do(r);return t.decode(n,void 0,e)}function Po(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return it(i);o+i>t&&(n=it(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ee=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Co(){}var Ko=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},$u=Po();function Wu(r){return globalThis.Buffer!=null?it(r):$u(r)}var hr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ee(Co,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ee(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new No((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Jr,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=xt.fromBigInt(t);return this._push(Jr,e.length(),e)}uint64Number(t){return this._push(Ao,Bt(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=xt.fromBigInt(t).zzEncode();return this._push(Jr,e.length(),e)}sint64Number(t){let e=xt.fromNumber(t).zzEncode();return this._push(Jr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ro,1,t?1:0)}fixed32(t){return this._push(lr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=xt.fromBigInt(t);return this._push(lr,4,e.lo)._push(lr,4,e.hi)}fixed64Number(t){let e=xt.fromNumber(t);return this._push(lr,4,e.lo)._push(lr,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(Ri,4,t)}double(t){return this._push(Ni,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ro,1,0):this.uint32(e)._push(Qu,e,t)}string(t){let e=Oi(t);return e!==0?this.uint32(e)._push(Lo,e,t):this._push(Ro,1,0)}fork(){return this.states=new Ko(this),this.head=this.tail=new Ee(Co,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Ee(Co,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=Wu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ro(r,t,e){t[e]=r&255}function Ju(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var No=class extends Ee{next;constructor(t,e){super(Ju,t,e),this.next=void 0}};function Jr(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 lr(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 Qu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(hr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(tf,t,r),this},hr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ef,t,r),this});function tf(r,t,e){t.set(r,e)}function ef(r,t,e){r.length<40?Lo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(F(r),e)}function Uo(){return new hr}function Qr(r,t){let e=Uo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Me;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Me||(Me={}));function tn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ko(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 tn("enum",Me.VARINT,e,n)}function en(r,t){return tn("message",Me.LENGTH_DELIMITED,r,t)}var Q;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Q||(Q={}));var Oo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Oo||(Oo={}));(function(r){r.codec=()=>ko(Oo)})(Q||(Q={}));var Dt;(function(r){let t;r.codec=()=>(t==null&&(t=en((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Q.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=Q.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Qr(e,r.codec()),r.decode=(e,n)=>Wr(e,r.codec(),n)})(Dt||(Dt={}));var Mo;(function(r){let t;r.codec=()=>(t==null&&(t=en((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Q.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=Q.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Qr(e,r.codec()),r.decode=(e,n)=>Wr(e,r.codec(),n)})(Mo||(Mo={}));function rn(r){if(isNaN(r)||r<=0)throw new j("random bytes length must be a Number bigger than 0");return pe(r)}var pr={};ht(pr,{MAX_RSA_KEY_SIZE:()=>qo,generateRSAKeyPair:()=>Gi,jwkToJWKKeyPair:()=>Zi,jwkToPkcs1:()=>sf,jwkToPkix:()=>zo,jwkToRSAPrivateKey:()=>Yo,pkcs1MessageToJwk:()=>Vo,pkcs1MessageToRSAPrivateKey:()=>Go,pkcs1ToJwk:()=>of,pkcs1ToRSAPrivateKey:()=>zi,pkixMessageToJwk:()=>Fo,pkixMessageToRSAPublicKey:()=>jo,pkixToJwk:()=>af,pkixToRSAPublicKey:()=>Zo});var nn=Hr;var qe=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return st.createV1(114,this._multihash)}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return Fi(this.jwk,e,t,n)}},dr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}sign(t,e){return Vi(this.jwk,t,e)}};var qo=8192,Ho=18,rf=1062,nf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function of(r){let t=Rt(r);return Vo(t)}function Vo(r){return{n:z(r[1],"base64url"),e:z(r[2],"base64url"),d:z(r[3],"base64url"),p:z(r[4],"base64url"),q:z(r[5],"base64url"),dp:z(r[6],"base64url"),dq:z(r[7],"base64url"),qi:z(r[8],"base64url"),kty:"RSA"}}function sf(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 j("JWK was missing components");return Jt([pt(Uint8Array.from([0])),pt(F(r.n,"base64url")),pt(F(r.e,"base64url")),pt(F(r.d,"base64url")),pt(F(r.p,"base64url")),pt(F(r.q,"base64url")),pt(F(r.dp,"base64url")),pt(F(r.dq,"base64url")),pt(F(r.qi,"base64url"))]).subarray()}function af(r){let t=Rt(r,{offset:0});return Fo(t)}function Fo(r){let t=Rt(r[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function zo(r){if(r.n==null||r.e==null)throw new j("JWK was missing components");return Jt([nf,Ur(Jt([pt(F(r.n,"base64url")),pt(F(r.e,"base64url"))]))]).subarray()}function zi(r){let t=Rt(r);return Go(t)}function Go(r){let t=Vo(r);return Yo(t)}function Zo(r,t){if(r.byteLength>=rf)throw new Ae("Key size is too large");let e=Rt(r,{offset:0});return jo(e,r,t)}function jo(r,t,e){let n=Fo(r);if(e==null){let o=nn(Dt.encode({Type:Q.RSA,Data:t}));e=vt(Ho,o)}return new qe(n,e)}function Yo(r){if(Yi(r)>qo)throw new j("Key size is too large");let t=Zi(r),e=nn(Dt.encode({Type:Q.RSA,Data:zo(t.publicKey)})),n=vt(Ho,e);return new dr(t.privateKey,new qe(t.publicKey,n))}async function Gi(r){if(r>qo)throw new j("Key size is too large");let t=await ji(r),e=nn(Dt.encode({Type:Q.RSA,Data:zo(t.publicKey)})),n=vt(Ho,e);return new dr(t.privateKey,new qe(t.publicKey,n))}function Zi(r){if(r==null)throw new j("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function ji(r,t){let e=await St.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await cf(e,t);return{privateKey:n[0],publicKey:n[1]}}async function Vi(r,t,e){let n=await St.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await St.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Fi(r,t,e,n){let o=await St.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await St.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function cf(r,t){if(r.privateKey==null||r.publicKey==null)throw new j("Private and public key are required");let e=await Promise.all([St.get().subtle.exportKey("jwk",r.privateKey),St.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Yi(r){if(r.kty!=="RSA")throw new j("invalid key type");if(r.n==null)throw new j("invalid key modulus");return F(r.n,"base64url").length*8}var on=class extends Ce{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,kr(t);let n=rr(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),Ut(s)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(this),$(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Xo=(r,t,e)=>new on(r,t).update(e).digest();Xo.create=(r,t)=>new on(r,t);var Xi=(r,t)=>(r+(r>=0?t:-t)/Wi)/t;function uf(r,t,e){let[[n,o],[s,i]]=t,a=Xi(i*r,e),c=Xi(-o*r,e),f=r-a*n-c*s,d=-a*o-c*i,l=f<Zt,u=d<Zt;l&&(f=-f),u&&(d=-d);let h=ne(Math.ceil(Fr(e)/2))+Ve;if(f<Zt||f>=h||d<Zt||d>=h)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:l,k1:f,k2neg:u,k2:d}}function $i(r){r.lowS!==void 0&&Ot("lowS",r.lowS),r.prehash!==void 0&&Ot("prehash",r.prehash)}var $o=class extends Error{constructor(t=""){super(t)}},Gt={Err:$o,_tlv:{encode:(r,t)=>{let{Err:e}=Gt;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=ir(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ir(o.length/2|128):"";return ir(r)+s+o+t},decode(r,t){let{Err:e}=Gt,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 d of f)i=i<<8|d;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}=Gt;if(r<Zt)throw new t("integer: negative integers are not allowed");let e=ir(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}=Gt;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 Ke(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Gt,o=H("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:d}=n.decode(2,c);if(d.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}=Gt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Zt=BigInt(0),Ve=BigInt(1),Wi=BigInt(2),sn=BigInt(3),ff=BigInt(4);function lf(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function He(r,t){let{BYTES:e}=r,n;if(typeof t=="bigint")n=t;else{let o=H("private key",t);try{n=r.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${e}, got ${typeof t}`)}}if(!r.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function hf(r,t={}){let{Fp:e,Fn:n}=zr("weierstrass",r,t),{h:o,n:s}=r;oe(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||!Array.isArray(i.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(D,y,m){let{x:E,y:A}=y.toAffine(),P=e.toBytes(E);if(Ot("isCompressed",m),m){a();let C=!e.isOdd(A);return mt(Ji(C),P)}else return mt(Uint8Array.of(4),P,e.toBytes(A))}function f(D){$(D);let y=e.BYTES,m=y+1,E=2*y+1,A=D.length,P=D[0],C=D.subarray(1);if(A===m&&(P===2||P===3)){let x=e.fromBytes(C);if(!e.isValid(x))throw new Error("bad point: is not on curve, wrong x");let b=u(x),I;try{I=e.sqrt(b)}catch(N){let O=N instanceof Error?": "+N.message:"";throw new Error("bad point: is not on curve, sqrt error"+O)}a();let L=e.isOdd(I);return(P&1)===1!==L&&(I=e.neg(I)),{x,y:I}}else if(A===E&&P===4){let x=e.fromBytes(C.subarray(y*0,y*1)),b=e.fromBytes(C.subarray(y*1,y*2));if(!h(x,b))throw new Error("bad point: is not on curve");return{x,y:b}}else throw new Error(`bad point: got length ${A}, expected compressed=${m} or uncompressed=${E}`)}let d=t.toBytes||c,l=t.fromBytes||f,u=lf(e,r.a,r.b);function h(D,y){let m=e.sqr(y),E=u(D);return e.eql(m,E)}if(!h(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let g=e.mul(e.pow(r.a,sn),ff),w=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(g,w)))throw new Error("bad curve params: a or b");function p(D,y,m=!1){if(!e.isValid(y)||m&&e.is0(y))throw new Error(`bad point coordinate ${D}`);return y}function S(D){if(!(D instanceof _))throw new Error("ProjectivePoint expected")}function B(D){if(!i||!i.basises)throw new Error("no endo");return uf(D,i.basises,n.ORDER)}let v=Ne((D,y)=>{let{X:m,Y:E,Z:A}=D;if(e.eql(A,e.ONE))return{x:m,y:E};let P=D.is0();y==null&&(y=P?e.ONE:e.inv(A));let C=e.mul(m,y),x=e.mul(E,y),b=e.mul(A,y);if(P)return{x:e.ZERO,y:e.ZERO};if(!e.eql(b,e.ONE))throw new Error("invZ was invalid");return{x:C,y:x}}),T=Ne(D=>{if(D.is0()){if(t.allowInfinityPoint&&!e.is0(D.Y))return;throw new Error("bad point: ZERO")}let{x:y,y:m}=D.toAffine();if(!e.isValid(y)||!e.isValid(m))throw new Error("bad point: x or y not field elements");if(!h(y,m))throw new Error("bad point: equation left != right");if(!D.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(D,y,m,E,A){return m=new _(e.mul(m.X,D),m.Y,m.Z),y=cr(E,y),m=cr(A,m),y.add(m)}class _{constructor(y,m,E){this.X=p("x",y),this.Y=p("y",m,!0),this.Z=p("z",E),Object.freeze(this)}static fromAffine(y){let{x:m,y:E}=y||{};if(!y||!e.isValid(m)||!e.isValid(E))throw new Error("invalid affine point");if(y instanceof _)throw new Error("projective point not allowed");return e.is0(m)&&e.is0(E)?_.ZERO:new _(m,E,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}static normalizeZ(y){return Vt(_,y)}static fromBytes(y){return $(y),_.fromHex(y)}static fromHex(y){let m=_.fromAffine(l(H("pointHex",y)));return m.assertValidity(),m}static fromPrivateKey(y){return _.BASE.multiply(He(n,y))}static msm(y,m){return Oe(_,n,y,m)}_setWindowSize(y){this.precompute(y)}precompute(y=8,m=!0){return k.createCache(this,y),m||this.multiply(sn),this}assertValidity(){T(this)}hasEvenY(){let{y}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(y)}equals(y){S(y);let{X:m,Y:E,Z:A}=this,{X:P,Y:C,Z:x}=y,b=e.eql(e.mul(m,x),e.mul(P,A)),I=e.eql(e.mul(E,x),e.mul(C,A));return b&&I}negate(){return new _(this.X,e.neg(this.Y),this.Z)}double(){let{a:y,b:m}=r,E=e.mul(m,sn),{X:A,Y:P,Z:C}=this,x=e.ZERO,b=e.ZERO,I=e.ZERO,L=e.mul(A,A),K=e.mul(P,P),N=e.mul(C,C),O=e.mul(A,P);return O=e.add(O,O),I=e.mul(A,C),I=e.add(I,I),x=e.mul(y,I),b=e.mul(E,N),b=e.add(x,b),x=e.sub(K,b),b=e.add(K,b),b=e.mul(x,b),x=e.mul(O,x),I=e.mul(E,I),N=e.mul(y,N),O=e.sub(L,N),O=e.mul(y,O),O=e.add(O,I),I=e.add(L,L),L=e.add(I,L),L=e.add(L,N),L=e.mul(L,O),b=e.add(b,L),N=e.mul(P,C),N=e.add(N,N),L=e.mul(N,O),x=e.sub(x,L),I=e.mul(N,K),I=e.add(I,I),I=e.add(I,I),new _(x,b,I)}add(y){S(y);let{X:m,Y:E,Z:A}=this,{X:P,Y:C,Z:x}=y,b=e.ZERO,I=e.ZERO,L=e.ZERO,K=r.a,N=e.mul(r.b,sn),O=e.mul(m,P),G=e.mul(E,C),V=e.mul(A,x),yt=e.add(m,E),q=e.add(P,C);yt=e.mul(yt,q),q=e.add(O,G),yt=e.sub(yt,q),q=e.add(m,A);let tt=e.add(P,x);return q=e.mul(q,tt),tt=e.add(O,V),q=e.sub(q,tt),tt=e.add(E,A),b=e.add(C,x),tt=e.mul(tt,b),b=e.add(G,V),tt=e.sub(tt,b),L=e.mul(K,q),b=e.mul(N,V),L=e.add(b,L),b=e.sub(G,L),L=e.add(G,L),I=e.mul(b,L),G=e.add(O,O),G=e.add(G,O),V=e.mul(K,V),q=e.mul(N,q),G=e.add(G,V),V=e.sub(O,V),V=e.mul(K,V),q=e.add(q,V),O=e.mul(G,q),I=e.add(I,O),O=e.mul(tt,q),b=e.mul(yt,b),b=e.sub(b,O),O=e.mul(yt,G),L=e.mul(tt,L),L=e.add(L,O),new _(b,I,L)}subtract(y){return this.add(y.negate())}is0(){return this.equals(_.ZERO)}multiply(y){let{endo:m}=t;if(!n.isValidNot0(y))throw new Error("invalid scalar: out of range");let E,A,P=C=>k.cached(this,C,x=>Vt(_,x));if(m){let{k1neg:C,k1:x,k2neg:b,k2:I}=B(y),{p:L,f:K}=P(x),{p:N,f:O}=P(I);A=K.add(O),E=R(m.beta,L,N,C,b)}else{let{p:C,f:x}=P(y);E=C,A=x}return Vt(_,[E,A])[0]}multiplyUnsafe(y){let{endo:m}=t,E=this;if(!n.isValid(y))throw new Error("invalid scalar: out of range");if(y===Zt||E.is0())return _.ZERO;if(y===Ve)return E;if(k.hasCache(this))return this.multiply(y);if(m){let{k1neg:A,k1:P,k2neg:C,k2:x}=B(y),{p1:b,p2:I}=Si(_,E,P,x);return R(m.beta,b,I,A,C)}else return k.unsafe(E,y)}multiplyAndAddUnsafe(y,m,E){let A=this.multiplyUnsafe(m).add(y.multiplyUnsafe(E));return A.is0()?void 0:A}toAffine(y){return v(this,y)}isTorsionFree(){let{isTorsionFree:y}=t;return o===Ve?!0:y?y(_,this):k.unsafe(this,s).is0()}clearCofactor(){let{clearCofactor:y}=t;return o===Ve?this:y?y(_,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(y=!0){return Ot("isCompressed",y),this.assertValidity(),d(_,this,y)}toRawBytes(y=!0){return this.toBytes(y)}toHex(y=!0){return Et(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}_.BASE=new _(r.Gx,r.Gy,e.ONE),_.ZERO=new _(e.ZERO,e.ONE,e.ZERO),_.Fp=e,_.Fn=n;let U=n.BITS,k=new ke(_,t.endo?Math.ceil(U/2):U);return _}function Ji(r){return Uint8Array.of(r?2:3)}function df(r,t,e={}){kr(t),oe(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=e.randomBytes||pe,o=e.hmac||((x,...b)=>Xo(t,x,mt(...b))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,f=io(a),d={secret:i.BYTES,public:1+s.BYTES,publicUncompressed:1+2*s.BYTES,signature:2*i.BYTES,seed:f};function l(x){let b=a>>Ve;return x>b}function u(x){return l(x)?i.neg(x):x}function h(x,b){if(!i.isValidNot0(b))throw new Error(`invalid signature ${x}: out of range 1..CURVE.n`)}class g{constructor(b,I,L){h("r",b),h("s",I),this.r=b,this.s=I,L!=null&&(this.recovery=L),Object.freeze(this)}static fromBytes(b,I="compact"){if(I==="compact"){let L=i.BYTES;$(b,L*2);let K=b.subarray(0,L),N=b.subarray(L,L*2);return new g(i.fromBytes(K),i.fromBytes(N))}if(I==="der"){$(b);let{r:L,s:K}=Gt.toSig(b);return new g(L,K)}throw new Error("invalid format")}static fromHex(b,I){return this.fromBytes(de(b),I)}addRecoveryBit(b){return new g(this.r,this.s,b)}recoverPublicKey(b){let I=s.ORDER,{r:L,s:K,recovery:N}=this;if(N==null||![0,1,2,3].includes(N))throw new Error("recovery id invalid");if(a*Wi<I&&N>1)throw new Error("recovery id is ambiguous for h>1 curve");let G=N===2||N===3?L+a:L;if(!s.isValid(G))throw new Error("recovery id 2 or 3 invalid");let V=s.toBytes(G),yt=r.fromHex(mt(Ji((N&1)===0),V)),q=i.inv(G),tt=U(H("msgHash",b)),bt=i.create(-tt*q),Yt=i.create(K*q),ie=r.BASE.multiplyUnsafe(bt).add(yt.multiplyUnsafe(Yt));if(ie.is0())throw new Error("point at infinify");return ie.assertValidity(),ie}hasHighS(){return l(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,i.neg(this.s),this.recovery):this}toBytes(b="compact"){if(b==="compact")return mt(i.toBytes(this.r),i.toBytes(this.s));if(b==="der")return de(Gt.hexFromSig(this));throw new Error("invalid format")}toHex(b){return Et(this.toBytes(b))}assertValidity(){}static fromCompact(b){return g.fromBytes(H("sig",b),"compact")}static fromDER(b){return g.fromBytes(H("sig",b),"der")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Et(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Et(this.toBytes("compact"))}}function w(x){try{return!!He(i,x)}catch{return!1}}function p(x,b){try{let I=x.length;return b===!0&&I!==d.public||b===!1&&I!==d.publicUncompressed?!1:!!r.fromBytes(x)}catch{return!1}}function S(x=n(f)){return ao(x,a)}let B={isValidSecretKey:w,isValidPublicKey:p,randomSecretKey:S,isValidPrivateKey:w,randomPrivateKey:S,normPrivateKeyToScalar:x=>He(i,x),precompute(x=8,b=r.BASE){return b.precompute(x,!1)}};function v(x,b=!0){return r.BASE.multiply(He(i,x)).toBytes(b)}function T(x){if(typeof x=="bigint")return!1;if(x instanceof r)return!0;if(i.allowedLengths||d.secret===d.public)return;let b=H("key",x).length;return b===d.public||b===d.publicUncompressed}function R(x,b,I=!0){if(T(x)===!0)throw new Error("first arg must be private key");if(T(b)===!1)throw new Error("second arg must be public key");let L=He(i,x);return r.fromHex(b).multiply(L).toBytes(I)}let _=e.bits2int||function(x){if(x.length>8192)throw new Error("input is too large");let b=Ke(x),I=x.length*8-c;return I>0?b>>BigInt(I):b},U=e.bits2int_modN||function(x){return i.create(_(x))},k=ne(c);function D(x){return re("num < 2^"+c,x,Zt,k),i.toBytes(x)}function y(x,b,I=m){if(["recovered","canonical"].some(bt=>bt in I))throw new Error("sign() legacy options not supported");let{lowS:L,prehash:K,extraEntropy:N}=I;L==null&&(L=!0),x=H("msgHash",x),$i(I),K&&(x=H("prehashed msgHash",t(x)));let O=U(x),G=He(i,b),V=[D(G),D(O)];if(N!=null&&N!==!1){let bt=N===!0?n(d.secret):N;V.push(H("extraEntropy",bt))}let yt=mt(...V),q=O;function tt(bt){let Yt=_(bt);if(!i.isValidNot0(Yt))return;let ie=i.inv(Yt),Ze=r.BASE.multiply(Yt).toAffine(),ae=i.create(Ze.x);if(ae===Zt)return;let je=i.create(ie*i.create(q+ae*G));if(je===Zt)return;let hs=(Ze.x===ae?0:2)|Number(Ze.y&Ve),ds=je;return L&&l(je)&&(ds=u(je),hs^=1),new g(ae,ds,hs)}return{seed:yt,k2sig:tt}}let m={lowS:e.lowS,prehash:!1},E={lowS:e.lowS,prehash:!1};function A(x,b,I=m){let{seed:L,k2sig:K}=y(x,b,I);return si(t.outputLen,i.BYTES,o)(L,K)}r.BASE.precompute(8);function P(x,b,I,L=E){let K=x;b=H("msgHash",b),I=H("publicKey",I),$i(L);let{lowS:N,prehash:O,format:G}=L;if("strict"in L)throw new Error("options.strict was renamed to lowS");let V,yt;if(G===void 0){let q=typeof K=="string"||he(K),tt=!q&&K!==null&&typeof K=="object"&&typeof K.r=="bigint"&&typeof K.s=="bigint";if(!q&&!tt)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(tt)V=new g(K.r,K.s);else if(q){try{V=g.fromDER(K)}catch(bt){if(!(bt instanceof Gt.Err))throw bt}if(!V)try{V=g.fromCompact(K)}catch{return!1}}}else if(G==="compact"||G==="der"){if(typeof K!="string"&&!he(K))throw new Error('"der" / "compact" format expects Uint8Array signature');V=g.fromBytes(H("sig",K),G)}else if(G==="js"){if(!(K instanceof g))throw new Error('"js" format expects Signature instance');V=K}else throw new Error('format must be "compact", "der" or "js"');if(!V)return!1;try{if(yt=r.fromHex(I),N&&V.hasHighS())return!1;O&&(b=t(b));let{r:q,s:tt}=V,bt=U(b),Yt=i.inv(tt),ie=i.create(bt*Yt),Ze=i.create(q*Yt),ae=r.BASE.multiplyUnsafe(ie).add(yt.multiplyUnsafe(Ze));return ae.is0()?!1:i.create(ae.x)===q}catch{return!1}}function C(x){let b=B.randomSecretKey(x);return{secretKey:b,publicKey:v(b)}}return Object.freeze({keygen:C,getPublicKey:v,sign:A,verify:P,getSharedSecret:R,utils:B,Point:r,Signature:g,info:{type:"weierstrass",lengths:d,publicKeyHasPrefix:!0}})}function pf(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=r.allowedPrivateKeyLengths?Array.from(new Set(r.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=gt(t.n,{BITS:r.nBitLength,allowedLengths:n,modOnDecode:r.wrapPrivateKey}),s={Fp:e,Fn:o,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:s}}function mf(r){let{CURVE:t,curveOpts:e}=pf(r),n={hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,hash:r.hash,ecdsaOpts:n}}function yf(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function Qi(r){let{CURVE:t,curveOpts:e,hash:n,ecdsaOpts:o}=mf(r),s=hf(t,e),i=df(s,n,o);return yf(r,i)}function ta(r,t){let e=n=>Qi({...r,hash:n});return{...e(t),create:e}}var Jo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},bf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ea=BigInt(2);function gf(r){let t=Jo.p,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,d=f*f*r%t,l=Z(d,e,t)*d%t,u=Z(l,e,t)*d%t,h=Z(u,ea,t)*f%t,g=Z(h,o,t)*h%t,w=Z(g,s,t)*g%t,p=Z(w,a,t)*w%t,S=Z(p,c,t)*p%t,B=Z(S,a,t)*w%t,v=Z(B,e,t)*d%t,T=Z(v,i,t)*g%t,R=Z(T,n,t)*f%t,_=Z(R,ea,t);if(!Wo.eql(Wo.sqr(_),r))throw new Error("Cannot find square root");return _}var Wo=gt(Jo.p,void 0,void 0,{sqrt:gf}),Fe=ta({...Jo,Fp:Wo,lowS:!0,endo:bf},Hr);function ra(r,t,e,n){let o=fe.digest(e instanceof Uint8Array?e:e.subarray());if(Yr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Fe.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new fr(String(s))});try{return n?.signal?.throwIfAborted(),Fe.verify(t,o.digest,r)}catch(s){throw new fr(String(s))}}var an=class{type="secp256k1";raw;_key;constructor(t){this._key=oa(t),this.raw=na(this._key)}toMultihash(){return At.digest(Kt(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return ra(this._key,e,t,n)}};function Qo(r){return new an(r)}function na(r){return Fe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function oa(r){try{return Fe.ProjectivePoint.fromHex(r),r}catch(t){throw new Ae(String(t))}}function ts(r,t){let{Type:e,Data:n}=Dt.decode(r),o=n??new Uint8Array;switch(e){case Q.RSA:return Zo(o,t);case Q.Ed25519:return wo(o);case Q.secp256k1:return Qo(o);case Q.ECDSA:return Xn(o);default:throw new ce}}function sa(r){let{Type:t,Data:e}=Dt.decode(r.digest),n=e??new Uint8Array;switch(t){case Q.Ed25519:return wo(n);case Q.secp256k1:return Qo(n);case Q.ECDSA:return Xn(n);default:throw new ce}}function Kt(r){return Dt.encode({Type:Q[r.type],Data:r.raw})}var ia=Symbol.for("nodejs.util.inspect.custom"),wf=114,mr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[En]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return st.createV1(wf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return dt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return dt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ia](){return`PeerId(${this.toString()})`}},yr=class extends mr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},br=class extends mr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},gr=class extends mr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},xf=2336,cn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(F(this.url))}[ia](){return`PeerId(${this.url})`}[En]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return st.createV1(xf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function es(r){if(r.type==="Ed25519")return new br({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new gr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new yr({multihash:r.toCID().multihash,publicKey:r});throw new ce}function aa(r){return es(r.publicKey)}function wr(r){if(Sf(r))return new yr({multihash:r});if(Ef(r))try{let t=sa(r);if(t.type==="Ed25519")return new br({multihash:r,publicKey:t});if(t.type==="secp256k1")return new gr({multihash:r,publicKey:t})}catch{let e=z(r.digest);return new cn(new URL(e))}throw new Pr("Supplied PeerID Multihash is invalid")}function Ef(r){return r.code===At.code}function Sf(r){return r.code===fe.code}function Se(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function un(r){let t=$t(Y.decode(`z${r}`));return wr(t)}var xr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return Se(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return Se(this.map.values(),t=>t.key)}values(){return Se(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Er=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Se(this.set.entries(),t=>{let e=un(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=un(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Se(this.set.values(),t=>un(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 jt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var fn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},ze=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new fn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new fn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let 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 rs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ln(r={}){return vf(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 vf(r,t){t=t??{};let e=t.onEnd,n=new ze,o,s,i,a=jt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,S)=>{s=B=>{s=null,n.push(B);try{p(r(n))}catch(v){S(v)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=jt()})}},f=p=>s!=null?s(p):(n.push(p),o),d=p=>(n=new ze,s!=null?s({error:p}):(n.push({error:p}),o)),l=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:p})},u=p=>i?o:(i=!0,p!=null?d(p):f({done:!0})),h=()=>(n=new ze,u(),{done:!0}),g=p=>(u(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:g,push:l,end:u,get readableLength(){return n.size},onEmpty:async p=>{let S=p?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let B,v;S!=null&&(B=new Promise((T,R)=>{v=()=>{R(new rs)},S.addEventListener("abort",v)}));try{await Promise.race([a.promise,B])}finally{v!=null&&S!=null&&S?.removeEventListener("abort",v)}}},e==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(p){return w.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return w.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(p){return w.end(p),e!=null&&(e(p),e=void 0),o},get readableLength(){return w.readableLength},onEmpty:p=>w.onEmpty(p)},o}var hn=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 ca(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new hn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new hn(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 ns=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=jt(),this.haveNext=jt()}[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=jt(),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=jt(),await ca(this.readNext.promise,e?.signal,e)}};function ua(){return new ns}function Af(r){return r[Symbol.asyncIterator]!=null}async function If(r,t,e){try{await Promise.all(r.map(async n=>{for await(let o of n)await t.push(o,{signal:e}),e.throwIfAborted()})),await t.end(void 0,{signal:e})}catch(n){await t.end(n,{signal:e}).catch(()=>{})}}async function*Bf(r){let t=new AbortController,e=ua();If(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*_f(r){for(let t of r)yield*t}function Lf(...r){let t=[];for(let e of r)Af(e)||t.push(e);return t.length===r.length?_f(t):Bf(r)}var fa=Lf;function Sr(r,...t){if(r==null)throw new Error("Empty pipeline");if(os(r)){let n=r;r=()=>n.source}else if(ha(r)||la(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&os(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++)os(e[n])&&(e[n]=Df(e[n]));return Tf(...e)}var Tf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},la=r=>r?.[Symbol.asyncIterator]!=null,ha=r=>r?.[Symbol.iterator]!=null,os=r=>r==null?!1:r.sink!=null&&r.source!=null,Df=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=ln({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(la(s))o=async function*(){yield*s,n.end()};else if(ha(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return fa(n,o())}return r.source};var is=Na(pa(),1);var Ar=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},as=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},ma=r=>globalThis.DOMException===void 0?new as(r):new DOMException(r),ya=r=>{let t=r.reason===void 0?ma("This operation was aborted."):r.reason;return t instanceof Error?t:ma(t)};function cs(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,f=new Promise((d,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:h}=t;h.aborted&&l(ya(h)),a=()=>{l(ya(h))},h.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(d,l);return}let u=new Ar;i=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(h){l(h)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?d():o instanceof Error?l(o):(u.message=o??`Promise timed out after ${e} milliseconds`,l(u))},e),(async()=>{try{d(await r)}catch(h){l(h)}})()}).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 us(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 Ir=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=us(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var Br=class extends is.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#w=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ir,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#x(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},e)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#x&&this.#E){let e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#I(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#w++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=cs(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#I(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof Ar&&!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 ba(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 ga(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function wa(r,t){let e=ba(r).return?.();ga(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var pn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ge=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},mn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},_r=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function yn(r){return r[Symbol.asyncIterator]!=null}function xa(r,t){if(r.byteLength>t)throw new Ge("Message length too long")}var gn=r=>{let t=Bt(r),e=it(t);return Di(r,e),gn.bytes=t,e};gn.bytes=0;function wn(r,t){t=t??{};let e=t.lengthEncoder??gn,n=t?.maxDataLength??4194304;function*o(s){xa(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return yn(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}wn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??gn,n=t?.maxDataLength??4194304;return xa(r,n),new et(e(r.byteLength),r)};var ve;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ve||(ve={}));var fs=r=>{let t=Pi(r);return fs.bytes=Bt(t),t};fs.bytes=0;function Lr(r,t){let e=new et,n=ve.LENGTH,o=-1,s=t?.lengthDecoder??fs,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===ve.LENGTH)try{if(o=s(e),o<0)throw new pn("Invalid message length");if(o>a)throw new Ge("Message length too long");let f=s.bytes;e.consume(f),t?.onLength!=null&&t.onLength(o),n=ve.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>i)throw new mn("Message length length too long");break}throw f}if(n===ve.DATA){if(e.byteLength<o)break;let f=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(f),yield f,n=ve.LENGTH}}}return yn(r)?async function*(){for await(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new _r("Unexpected end of input")}():function*(){for(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw new _r("Unexpected end of input")}()}Lr.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 Lr(n,{...t??{},onLength:s=>{e=s}})};var xn=class extends Ie{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=e.id,this.protocol=e.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let e=this.id.toString();throw new Error("No writable connection to "+e)}this.outboundStream.push(t instanceof Uint8Array?new et(t):t)}attachInboundStream(t,e){let n=()=>{wa(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=Sr(this._rawInboundStream,o=>Lr(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=ln({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),Sr(this.outboundStream,n=>wn(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),e==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function Ea(){return BigInt(`0x${z(rn(8),"base16")}`)}var Sa=(r,t)=>{let e=F(t.toString(16).padStart(16,"0"),"base16"),n=Kt(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},va=r=>fe.encode(r);var Aa=function(r){return Array.isArray(r)?r:[r]},Nf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=wr($t(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return es(ts(e)).equals(t)}return!1},Ia=async r=>{if(r.from==null)throw new J("RPC message was missing from");if(!await Nf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=wr($t(r.from)),e=r.key??t.publicKey;if(e==null)throw new J("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:kf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?ts(e):e}},Tr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:Uf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Kt(r.key):void 0}:{data:r.data,topic:r.topic},Uf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},kf=r=>BigInt(`0x${z(r,"base16")}`);var Ba=F("libp2p-pubsub:");async function _a(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:aa(r)},o=ue([Ba,e(Tr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function La(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=ue([Ba,t({...Tr(r),signature:void 0,key:void 0}).subarray()]);return Of(r).verify(e,r.signature)}function Of(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 ls=class extends Ie{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,e){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:a=10,maxInboundStreams:c=1,maxOutboundStreams:f=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=Aa(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new xr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new Br({concurrency:a}),this.maxInboundStreams=c,this.maxOutboundStreams=f,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let e={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.multicodecs.map(async e=>{await t.unhandle(e)})),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:e,connection:n}=t,o=n.remotePeer;if(e.protocol==null){e.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,e.protocol),i=s.attachInboundStream(e);this.processMessages(o,i,s).catch(a=>{this.log(a)})}_onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await e.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new xn(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 Sr(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),a=[];for(let c of i.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,e,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.id,subscriptions:o.map(({topic:i,subscribe:a})=>({topic:`${i??""}`,subscribe:!!a}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let a=await Ia(i);await this.processMessage(t,a)}catch(a){this.log.error(a)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new Er,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 J('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new J("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new J("Need key when signature policy is StrictSign but it was missing");return Sa(t.key,t.sequenceNumber);case"StrictNoSign":return va(t.data);default:throw new J("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(Tr)})}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 J('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new J("StrictNoSigning: signature should not be present");if(e.key!=null)throw new J("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new J("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new J("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new J("StrictSigning: Signing required and no sequenceNumber was present");if(!await La(e,this.encodeMessage.bind(this)))throw new J("StrictSigning: Invalid message signature");break;default:throw new J("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===Ye.Reject||s===Ye.Ignore)throw new J("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return _a(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new J("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Cr("not started yet");if(t==null)throw new j("Topic is required");let e=this.topics.get(t.toString());return e==null?[]:Array.from(e.values())}async publish(t,e){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:e??new Uint8Array(0),sequenceNumber:Ea()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let e=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,e),e){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};return Ua(Mf);})();
2
+ "use strict";var Libp2PPubsub=(()=>{var Ka=Object.create;var Tr=Object.defineProperty;var Ra=Object.getOwnPropertyDescriptor;var Na=Object.getOwnPropertyNames;var Ua=Object.getPrototypeOf,ka=Object.prototype.hasOwnProperty;var Oa=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yt=(e,t)=>{for(var r in t)Tr(e,r,{get:t[r],enumerable:!0})},ws=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Na(t))!ka.call(e,o)&&o!==r&&Tr(e,o,{get:()=>t[o],enumerable:!(n=Ra(t,o))||n.enumerable});return e};var Ma=(e,t,r)=>(r=e!=null?Ka(Ua(e)):{},ws(t||!e||!e.__esModule?Tr(r,"default",{value:e,enumerable:!0}):r,e)),qa=e=>ws(Tr({},"__esModule",{value:!0}),e);var ga=Oa((xm,fs)=>{"use strict";var Nf=Object.prototype.hasOwnProperty,pt="~";function Er(){}Object.create&&(Er.prototype=Object.create(null),new Er().__proto__||(pt=!1));function Uf(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function ba(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new Uf(r,n||e,o),i=pt?pt+t:t;return e._events[i]?e._events[i].fn?e._events[i]=[e._events[i],s]:e._events[i].push(s):(e._events[i]=s,e._eventsCount++),e}function dn(e,t){--e._eventsCount===0?e._events=new Er:delete e._events[t]}function lt(){this._events=new Er,this._eventsCount=0}lt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)Nf.call(r,n)&&t.push(pt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};lt.prototype.listeners=function(t){var r=pt?pt+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};lt.prototype.listenerCount=function(t){var r=pt?pt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};lt.prototype.emit=function(t,r,n,o,s,i){var c=pt?pt+t:t;if(!this._events[c])return!1;var a=this._events[c],f=arguments.length,p,l;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),f){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,r),!0;case 3:return a.fn.call(a.context,r,n),!0;case 4:return a.fn.call(a.context,r,n,o),!0;case 5:return a.fn.call(a.context,r,n,o,s),!0;case 6:return a.fn.call(a.context,r,n,o,s,i),!0}for(l=1,p=new Array(f-1);l<f;l++)p[l-1]=arguments[l];a.fn.apply(a.context,p)}else{var u=a.length,h;for(l=0;l<u;l++)switch(a[l].once&&this.removeListener(t,a[l].fn,void 0,!0),f){case 1:a[l].fn.call(a[l].context);break;case 2:a[l].fn.call(a[l].context,r);break;case 3:a[l].fn.call(a[l].context,r,n);break;case 4:a[l].fn.call(a[l].context,r,n,o);break;default:if(!p)for(h=1,p=new Array(f-1);h<f;h++)p[h-1]=arguments[h];a[l].fn.apply(a[l].context,p)}}return!0};lt.prototype.on=function(t,r,n){return ba(this,t,r,n,!1)};lt.prototype.once=function(t,r,n){return ba(this,t,r,n,!0)};lt.prototype.removeListener=function(t,r,n,o){var s=pt?pt+t:t;if(!this._events[s])return this;if(!r)return dn(this,s),this;var i=this._events[s];if(i.fn)i.fn===r&&(!o||i.once)&&(!n||i.context===n)&&dn(this,s);else{for(var c=0,a=[],f=i.length;c<f;c++)(i[c].fn!==r||o&&!i[c].once||n&&i[c].context!==n)&&a.push(i[c]);a.length?this._events[s]=a.length===1?a[0]:a:dn(this,s)}return this};lt.prototype.removeAllListeners=function(t){var r;return t?(r=pt?pt+t:t,this._events[r]&&dn(this,r)):(this._events=new Er,this._eventsCount=0),this};lt.prototype.off=lt.prototype.removeListener;lt.prototype.addListener=lt.prototype.on;lt.prefixed=pt;lt.EventEmitter=lt;typeof fs<"u"&&(fs.exports=lt)});var Ff={};yt(Ff,{PubSubBaseProtocol:()=>ys});var En=Symbol.for("@libp2p/peer-id");var Ge;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(Ge||(Ge={}));var Zf=Symbol.for("@libp2p/pubsub");var Z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Se=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Cr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Q=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Pr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ue=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ve=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var In={};yt(In,{base58btc:()=>j,base58flickr:()=>ja});var $f=new Uint8Array(0);function xs(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Dt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Es(e){return new TextEncoder().encode(e)}function Ss(e){return new TextDecoder().decode(e)}function Ha(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),f=Math.log(c)/Math.log(256),p=Math.log(256)/Math.log(c);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var E=0,S=0,b=0,A=d.length;b!==A&&d[b]===0;)b++,E++;for(var w=(A-b)*p+1>>>0,L=new Uint8Array(w);b!==A;){for(var D=d[b],O=0,k=w-1;(D!==0||O<S)&&k!==-1;k--,O++)D+=256*L[k]>>>0,L[k]=D%c>>>0,D=D/c>>>0;if(D!==0)throw new Error("Non-zero carry");S=O,b++}for(var R=w-S;R!==w&&L[R]===0;)R++;for(var x=a.repeat(E);R<w;++R)x+=e.charAt(L[R]);return x}function u(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var E=0;if(d[E]!==" "){for(var S=0,b=0;d[E]===a;)S++,E++;for(var A=(d.length-E)*f+1>>>0,w=new Uint8Array(A);d[E];){var L=r[d.charCodeAt(E)];if(L===255)return;for(var D=0,O=A-1;(L!==0||D<b)&&O!==-1;O--,D++)L+=c*w[O]>>>0,w[O]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");b=D,E++}if(d[E]!==" "){for(var k=A-b;k!==A&&w[k]===0;)k++;for(var R=new Uint8Array(S+(A-k)),x=S;k!==A;)R[x++]=w[k++];return R}}}function h(d){var E=u(d);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:u,decode:h}}var Va=Ha,Fa=Va,As=Fa;var Sn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},vn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Bs(this,t)}},An=class{decoders;constructor(t){this.decoders=t}or(t){return Bs(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Bs(e,t){return new An({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Bn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sn(t,r,n),this.decoder=new vn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ae({name:e,prefix:t,encode:r,decode:n}){return new Bn(e,t,r,n)}function $t({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=As(r,e);return Ae({prefix:t,name:e,encode:n,decode:s=>Dt(o(s))})}function za(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let f=0;f<o;++f){let p=t[e[f]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|p,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ga(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Za(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function W({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Za(n);return Ae({prefix:t,name:e,encode(s){return Ga(s,n,r)},decode(s){return za(s,o,r,e)}})}var j=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ja=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _n={};yt(_n,{base32:()=>Be,base32hex:()=>Wa,base32hexpad:()=>Qa,base32hexpadupper:()=>tc,base32hexupper:()=>Ja,base32pad:()=>Xa,base32padupper:()=>$a,base32upper:()=>Ya,base32z:()=>ec});var Be=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ya=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xa=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),$a=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wa=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ja=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Qa=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tc=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ec=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ln={};yt(Ln,{base36:()=>Ze,base36upper:()=>rc});var Ze=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rc=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var nc=Ls,Is=128,oc=127,sc=~oc,ic=Math.pow(2,31);function Ls(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ic;)t[r++]=e&255|Is,e/=128;for(;e&sc;)t[r++]=e&255|Is,e>>>=7;return t[r]=e|0,Ls.bytes=r-n+1,t}var ac=Tn,cc=128,_s=127;function Tn(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw Tn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&_s)<<o:(i&_s)*Math.pow(2,o),o+=7}while(i>=cc);return Tn.bytes=s-n,r}var uc=Math.pow(2,7),fc=Math.pow(2,14),lc=Math.pow(2,21),hc=Math.pow(2,28),dc=Math.pow(2,35),pc=Math.pow(2,42),mc=Math.pow(2,49),yc=Math.pow(2,56),bc=Math.pow(2,63),gc=function(e){return e<uc?1:e<fc?2:e<lc?3:e<hc?4:e<dc?5:e<pc?6:e<mc?7:e<yc?8:e<bc?9:10},wc={encode:nc,decode:ac,encodingLength:gc},xc=wc,je=xc;function Ye(e,t=0){return[je.decode(e,t),je.decode.bytes]}function Ie(e,t,r=0){return je.encode(e,t,r),t}function _e(e){return je.encodingLength(e)}function Bt(e,t){let r=t.byteLength,n=_e(e),o=n+_e(r),s=new Uint8Array(o+r);return Ie(e,s,0),Ie(r,s,n),s.set(t,o),new Le(e,r,t,s)}function Wt(e){let t=Dt(e),[r,n]=Ye(t),[o,s]=Ye(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Le(r,o,i,t)}function Ts(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&xs(e.bytes,r.bytes)}}var Le=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Cs(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Sc(r,Cn(e),t??j.encoder);default:return vc(r,Cn(e),t??Be.encoder)}}var Ps=new WeakMap;function Cn(e){let t=Ps.get(e);if(t==null){let r=new Map;return Ps.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Xe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ac)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Bt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Ts(t.multihash,n.multihash)}toString(t){return Cs(this,t)}toJSON(){return{"/":Cs(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Ds(n,o,s.bytes))}else if(r[Bc]===!0){let{version:n,multihash:o,code:s}=r,i=Wt(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Xe)throw new Error(`Version 0 CID must use dag-pb (code: ${Xe}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ds(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Xe,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Dt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Le(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,u]=Ye(t.subarray(r));return r+=u,l},o=n(),s=Xe;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),f=r+a,p=f-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:p,size:f}}static parse(t,r){let[n,o]=Ec(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Cn(s).set(n,t),s}};function Ec(e,t){switch(e[0]){case"Q":{let r=t??j;return[j.prefix,r.decode(`${j.prefix}${e}`)]}case j.prefix:{let r=t??j;return[j.prefix,r.decode(e)]}case Be.prefix:{let r=t??Be;return[Be.prefix,r.decode(e)]}case Ze.prefix:{let r=t??Ze;return[Ze.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Sc(e,t,r){let{prefix:n}=r;if(n!==j.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function vc(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Xe=112,Ac=18;function Ds(e,t,r){let n=_e(e),o=n+_e(t),s=new Uint8Array(o+r.byteLength);return Ie(e,s,0),Ie(t,s,n),s.set(r,o),s}var Bc=Symbol.for("@ipld/js-cid/CID");var Pn={};yt(Pn,{identity:()=>It});var Ks=0,Ic="identity",Rs=Dt;function _c(e){return Bt(Ks,Rs(e))}var It={code:Ks,name:Ic,encode:Rs,digest:_c};function bt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Kt(e=0){return new Uint8Array(e)}function ct(e=0){return new Uint8Array(e)}function fe(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ct(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Us=Symbol.for("@achingbrain/uint8arraylist");function Ns(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Kr(e){return!!e?.[Us]}var rt=class e{bufs;length;[Us]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Kr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Kr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Ns(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ns(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Kr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return fe(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:fe(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let f=t>=c&&t<a,p=r>c&&r<=a;if(f&&p){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(p){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Kr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,a=this.byteLength-n.byteLength,f=n.byteLength-1,p;for(let l=r;l<=a;l+=p){p=0;for(let u=f;u>=0;u--){let h=this.get(l+u);if(n[u]!==h){p=Math.max(1,u-c[h]);break}}if(p===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!bt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Dn={};yt(Dn,{base10:()=>Lc});var Lc=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var Kn={};yt(Kn,{base16:()=>Tc,base16upper:()=>Cc});var Tc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Cc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Rn={};yt(Rn,{base2:()=>Pc});var Pc=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Nn={};yt(Nn,{base256emoji:()=>Uc});var ks=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Dc=ks.reduce((e,t,r)=>(e[r]=t,e),[]),Kc=ks.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Rc(e){return e.reduce((t,r)=>(t+=Dc[r],t),"")}function Nc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Kc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Uc=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:Rc,decode:Nc});var Un={};yt(Un,{base64:()=>kc,base64pad:()=>Oc,base64url:()=>Mc,base64urlpad:()=>qc});var kc=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Oc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Mc=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),qc=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var kn={};yt(kn,{base8:()=>Hc});var Hc=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var On={};yt(On,{identity:()=>Vc});var Vc=Ae({prefix:"\0",name:"identity",encode:e=>Ss(e),decode:e=>Es(e)});var Kl=new TextEncoder,Rl=new TextDecoder;var Hn={};yt(Hn,{sha256:()=>le,sha512:()=>Gc});function qn({name:e,code:t,encode:r}){return new Mn(e,t,r)}var Mn=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?Bt(this.code,r):r.then(n=>Bt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ms(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var le=qn({name:"sha2-256",code:18,encode:Ms("SHA-256")}),Gc=qn({name:"sha2-512",code:19,encode:Ms("SHA-512")});var Vn={...On,...Rn,...kn,...Dn,...Kn,..._n,...Ln,...In,...Un,...Nn},Zl={...Hn,...Pn};function Hs(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var qs=Hs("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Fn=Hs("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ct(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Zc={utf8:qs,"utf-8":qs,hex:Vn.base16,latin1:Fn,ascii:Fn,binary:Fn,...Vn},Rr=Zc;function F(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var jc=parseInt("11111",2),zn=parseInt("10000000",2),Yc=parseInt("01111111",2),Vs={0:$e,1:$e,2:Xc,3:Jc,4:Qc,5:Wc,6:$c,16:$e,22:$e,48:$e};function Rt(e,t={offset:0}){let r=e[t.offset]&jc;if(t.offset++,Vs[r]!=null)return Vs[r](e,t);throw new Error("No decoder for tag "+r)}function We(e,t){let r=0;if((e[t.offset]&zn)===zn){let n=e[t.offset]&Yc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function $e(e,t){We(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Rt(e,t);if(n===null)break;r.push(n)}return r}function Xc(e,t){let r=We(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function $c(e,t){let r=We(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,a.push(f&127),f<128){a.reverse();let p=0;for(let l=0;l<a.length;l++)p+=a[l]<<l*7;c+=`.${p}`,a=[]}}return c}function Wc(e,t){return t.offset++,null}function Jc(e,t){let r=We(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Qc(e,t){let r=We(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function tu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new rt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Gn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=tu(e.byteLength);return new rt(Uint8Array.from([t.byteLength|zn]),t)}function gt(e){let t=new rt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new rt(Uint8Array.from([2]),Gn(t),t)}function Nr(e){let t=Uint8Array.from([0]),r=new rt(t,e);return new rt(Uint8Array.from([3]),Gn(r),r)}function Qt(e,t=48){let r=new rt;for(let n of e)r.append(n);return new rt(Uint8Array.from([t]),Gn(r),r)}async function Fs(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var eu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ru=Uint8Array.from([6,5,43,129,4,0,34]),nu=Uint8Array.from([6,5,43,129,4,0,35]),ou={ext:!0,kty:"EC",crv:"P-256"},su={ext:!0,kty:"EC",crv:"P-384"},iu={ext:!0,kty:"EC",crv:"P-521"},Zn=32,jn=48,Yn=66;function Xn(e){let t=Rt(e);return zs(t)}function zs(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Zn*2+1)return n=z(t.subarray(r,r+Zn),"base64url"),o=z(t.subarray(r+Zn),"base64url"),new Te({...ou,key_ops:["verify"],x:n,y:o});if(t.byteLength===jn*2+1)return n=z(t.subarray(r,r+jn),"base64url"),o=z(t.subarray(r+jn),"base64url"),new Te({...su,key_ops:["verify"],x:n,y:o});if(t.byteLength===Yn*2+1)return n=z(t.subarray(r,r+Yn),"base64url"),o=z(t.subarray(r+Yn),"base64url"),new Te({...iu,key_ops:["verify"],x:n,y:o});throw new Z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Gs(e){return Qt([gt(Uint8Array.from([1])),Qt([au(e.crv)],160),Qt([Nr(new rt(Uint8Array.from([4]),F(e.x??"","base64url"),F(e.y??"","base64url")))],161)]).subarray()}function au(e){if(e==="P-256")return eu;if(e==="P-384")return ru;if(e==="P-521")return nu;throw new Z(`Invalid curve ${e}`)}var Te=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Gs(this.jwk)),this._raw}toMultihash(){return It.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}async verify(t,r,n){return Fs(this.jwk,r,t,n)}};var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function kt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Je(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function wt(e,...t){if(!kt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Ur(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Je(e.outputLen),Je(e.blockLen)}function Pe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function js(e,t){wt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Ot(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function kr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function _t(e,t){return e<<32-t|e>>>t}var Ys=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",cu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function vt(e){if(wt(e),Ys)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=cu[e[r]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function Zs(e){if(e>=Ut._0&&e<=Ut._9)return e-Ut._0;if(e>=Ut.A&&e<=Ut.F)return e-(Ut.A-10);if(e>=Ut.a&&e<=Ut.f)return e-(Ut.a-10)}function de(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ys)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Zs(e.charCodeAt(s)),c=Zs(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function $n(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Qe(e){return typeof e=="string"&&(e=$n(e)),wt(e),e}function ht(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];wt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Ce=class{};function Wn(e){let t=n=>e().update(Qe(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function te(e=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(e));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function uu(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,f=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+f,c,n)}function Xs(e,t,r){return e&t^~e&r}function $s(e,t,r){return e&t^e&r^t&r}var tr=class extends Ce{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=kr(this.buffer)}update(t){Pe(this),t=Qe(t),wt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=kr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Pe(this),js(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ot(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;uu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=kr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,p=this.get();if(f>p.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)c.setUint32(4*l,p[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Or=BigInt(4294967295),Ws=BigInt(32);function fu(e,t=!1){return t?{h:Number(e&Or),l:Number(e>>Ws&Or)}:{h:Number(e>>Ws&Or)|0,l:Number(e&Or)|0}}function Js(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=fu(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Jn=(e,t,r)=>e>>>r,Qn=(e,t,r)=>e<<32-r|t>>>r,pe=(e,t,r)=>e>>>r|t<<32-r,me=(e,t,r)=>e<<32-r|t>>>r,er=(e,t,r)=>e<<64-r|t>>>r-32,rr=(e,t,r)=>e>>>r-32|t<<64-r;function Ct(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Qs=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ti=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ei=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ri=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ni=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),oi=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var hu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ee=new Uint32Array(64),Mr=class extends tr{constructor(t=32){super(64,t,8,!1),this.A=Mt[0]|0,this.B=Mt[1]|0,this.C=Mt[2]|0,this.D=Mt[3]|0,this.E=Mt[4]|0,this.F=Mt[5]|0,this.G=Mt[6]|0,this.H=Mt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)ee[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let u=ee[l-15],h=ee[l-2],d=_t(u,7)^_t(u,18)^u>>>3,E=_t(h,17)^_t(h,19)^h>>>10;ee[l]=E+ee[l-7]+d+ee[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:f,H:p}=this;for(let l=0;l<64;l++){let u=_t(c,6)^_t(c,11)^_t(c,25),h=p+u+Xs(c,a,f)+hu[l]+ee[l]|0,E=(_t(n,2)^_t(n,13)^_t(n,22))+$s(n,o,s)|0;p=f,f=a,a=c,c=i+h|0,i=s,s=o,o=n,n=h+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,p=p+this.H|0,this.set(n,o,s,i,c,a,f,p)}roundClean(){Ot(ee)}destroy(){this.set(0,0,0,0,0,0,0,0),Ot(this.buffer)}};var si=Js(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),du=si[0],pu=si[1],re=new Uint32Array(80),ne=new Uint32Array(80),to=class extends tr{constructor(t=64){super(128,t,16,!1),this.Ah=st[0]|0,this.Al=st[1]|0,this.Bh=st[2]|0,this.Bl=st[3]|0,this.Ch=st[4]|0,this.Cl=st[5]|0,this.Dh=st[6]|0,this.Dl=st[7]|0,this.Eh=st[8]|0,this.El=st[9]|0,this.Fh=st[10]|0,this.Fl=st[11]|0,this.Gh=st[12]|0,this.Gl=st[13]|0,this.Hh=st[14]|0,this.Hl=st[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:f,El:p,Fh:l,Fl:u,Gh:h,Gl:d,Hh:E,Hl:S}=this;return[t,r,n,o,s,i,c,a,f,p,l,u,h,d,E,S]}set(t,r,n,o,s,i,c,a,f,p,l,u,h,d,E,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=f|0,this.El=p|0,this.Fh=l|0,this.Fl=u|0,this.Gh=h|0,this.Gl=d|0,this.Hh=E|0,this.Hl=S|0}process(t,r){for(let w=0;w<16;w++,r+=4)re[w]=t.getUint32(r),ne[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let L=re[w-15]|0,D=ne[w-15]|0,O=pe(L,D,1)^pe(L,D,8)^Jn(L,D,7),k=me(L,D,1)^me(L,D,8)^Qn(L,D,7),R=re[w-2]|0,x=ne[w-2]|0,T=pe(R,x,19)^er(R,x,61)^Jn(R,x,6),N=me(R,x,19)^rr(R,x,61)^Qn(R,x,6),C=ei(k,N,ne[w-7],ne[w-16]),g=ri(C,O,T,re[w-7],re[w-16]);re[w]=g|0,ne[w]=C|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:f,Dl:p,Eh:l,El:u,Fh:h,Fl:d,Gh:E,Gl:S,Hh:b,Hl:A}=this;for(let w=0;w<80;w++){let L=pe(l,u,14)^pe(l,u,18)^er(l,u,41),D=me(l,u,14)^me(l,u,18)^rr(l,u,41),O=l&h^~l&E,k=u&d^~u&S,R=ni(A,D,k,pu[w],ne[w]),x=oi(R,b,L,O,du[w],re[w]),T=R|0,N=pe(n,o,28)^er(n,o,34)^er(n,o,39),C=me(n,o,28)^rr(n,o,34)^rr(n,o,39),g=n&s^n&c^s&c,m=o&i^o&a^i&a;b=E|0,A=S|0,E=h|0,S=d|0,h=l|0,d=u|0,{h:l,l:u}=Ct(f|0,p|0,x|0,T|0),f=c|0,p=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let y=Qs(T,C,m);n=ti(y,x,N,g),o=y|0}({h:n,l:o}=Ct(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ct(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Ct(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l:p}=Ct(this.Dh|0,this.Dl|0,f|0,p|0),{h:l,l:u}=Ct(this.Eh|0,this.El|0,l|0,u|0),{h,l:d}=Ct(this.Fh|0,this.Fl|0,h|0,d|0),{h:E,l:S}=Ct(this.Gh|0,this.Gl|0,E|0,S|0),{h:b,l:A}=Ct(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,c,a,f,p,l,u,h,d,E,S,b,A)}roundClean(){Ot(re,ne)}destroy(){Ot(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var qr=Wn(()=>new Mr);var ii=Wn(()=>new to);var no=BigInt(0),ro=BigInt(1);function qt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function xt(e,t,r=""){let n=kt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function nr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function ai(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?no:BigInt("0x"+e)}function De(e){return ai(vt(e))}function Ht(e){return wt(e),ai(vt(Uint8Array.from(e).reverse()))}function Hr(e,t){return de(e.toString(16).padStart(t*2,"0"))}function oo(e,t){return Hr(e,t).reverse()}function H(e,t,r){let n;if(typeof t=="string")try{n=de(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(kt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function ci(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function so(e){return Uint8Array.from(e)}var eo=e=>typeof e=="bigint"&&no<=e;function ui(e,t,r){return eo(e)&&eo(t)&&eo(r)&&t<=e&&e<r}function or(e,t,r,n){if(!ui(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Vr(e){let t;for(t=0;e>no;e>>=ro,t+=1);return t}var oe=e=>(ro<<BigInt(e))-ro;function fi(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},f=(...h)=>r(i,s,...h),p=(h=n(0))=>{i=f(o(0),h),s=f(),h.length!==0&&(i=f(o(1),h),s=f())},l=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,d=[];for(;h<t;){s=f();let E=s.slice();d.push(E),h+=s.length}return ht(...d)};return(h,d)=>{a(),p(h);let E;for(;!(E=d(l()));)p();return a(),E}}function se(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var io=()=>{throw new Error("not implemented")};function Ke(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var dt=BigInt(0),nt=BigInt(1),ye=BigInt(2),di=BigInt(3),pi=BigInt(4),mi=BigInt(5),mu=BigInt(7),yi=BigInt(8),yu=BigInt(9),bi=BigInt(16);function J(e,t){let r=e%t;return r>=dt?r:t+r}function G(e,t,r){let n=e;for(;t-- >dt;)n*=n,n%=r;return n}function li(e,t){if(e===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,o=dt,s=nt,i=nt,c=dt;for(;r!==dt;){let f=n/r,p=n%r,l=o-i*f,u=s-c*f;n=r,r=p,o=i,s=c,i=l,c=u}if(n!==nt)throw new Error("invert: does not exist");return J(o,t)}function ao(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function gi(e,t){let r=(e.ORDER+nt)/pi,n=e.pow(t,r);return ao(e,n,t),n}function bu(e,t){let r=(e.ORDER-mi)/yi,n=e.mul(t,ye),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,ye),o),c=e.mul(s,e.sub(i,e.ONE));return ao(e,c,t),c}function gu(e){let t=Et(e),r=wi(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+mu)/bi;return(c,a)=>{let f=c.pow(a,i),p=c.mul(f,n),l=c.mul(f,o),u=c.mul(f,s),h=c.eql(c.sqr(p),a),d=c.eql(c.sqr(l),a);f=c.cmov(f,p,h),p=c.cmov(u,l,d);let E=c.eql(c.sqr(p),a),S=c.cmov(f,p,E);return ao(c,S,a),S}}function wi(e){if(e<di)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%ye===dt;)t/=ye,r++;let n=ye,o=Et(e);for(;hi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return gi;let s=o.pow(n,t),i=(t+nt)/ye;return function(a,f){if(a.is0(f))return f;if(hi(a,f)!==1)throw new Error("Cannot find square root");let p=r,l=a.mul(a.ONE,s),u=a.pow(f,t),h=a.pow(f,i);for(;!a.eql(u,a.ONE);){if(a.is0(u))return a.ZERO;let d=1,E=a.sqr(u);for(;!a.eql(E,a.ONE);)if(d++,E=a.sqr(E),d===p)throw new Error("Cannot find square root");let S=nt<<BigInt(p-d-1),b=a.pow(l,S);p=d,l=a.sqr(b),u=a.mul(u,l),h=a.mul(h,b)}return h}}function wu(e){return e%pi===di?gi:e%yi===mi?bu:e%bi===yu?gu(e):wi(e)}var Vt=(e,t)=>(J(e,t)&nt)===nt,xu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function co(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=xu.reduce((n,o)=>(n[o]="function",n),t);return se(e,r),e}function Eu(e,t,r){if(r<dt)throw new Error("invalid exponent, negatives unsupported");if(r===dt)return e.ONE;if(r===nt)return t;let n=e.ONE,o=t;for(;r>dt;)r&nt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=nt;return n}function sr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function hi(e,t){let r=(e.ORDER-nt)/ye,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Fr(e,t){t!==void 0&&Je(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Et(e,t,r=!1,n={}){if(e<=dt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(r=u.isLE),typeof u.modFromBytes=="boolean"&&(i=u.modFromBytes),c=u.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:f}=Fr(e,o);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let p,l=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:f,MASK:oe(a),ZERO:dt,ONE:nt,allowedLengths:c,create:u=>J(u,e),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return dt<=u&&u<e},is0:u=>u===dt,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&nt)===nt,neg:u=>J(-u,e),eql:(u,h)=>u===h,sqr:u=>J(u*u,e),add:(u,h)=>J(u+h,e),sub:(u,h)=>J(u-h,e),mul:(u,h)=>J(u*h,e),pow:(u,h)=>Eu(l,u,h),div:(u,h)=>J(u*li(h,e),e),sqrN:u=>u*u,addN:(u,h)=>u+h,subN:(u,h)=>u-h,mulN:(u,h)=>u*h,inv:u=>li(u,e),sqrt:s||(u=>(p||(p=wu(e)),p(l,u))),toBytes:u=>r?oo(u,f):Hr(u,f),fromBytes:(u,h=!0)=>{if(c){if(!c.includes(u.length)||u.length>f)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+u.length);let E=new Uint8Array(f);E.set(u,r?0:E.length-u.length),u=E}if(u.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+u.length);let d=r?Ht(u):De(u);if(i&&(d=J(d,e)),!h&&!l.isValid(d))throw new Error("invalid field element: outside of range 0..ORDER");return d},invertBatch:u=>sr(l,u),cmov:(u,h,d)=>d?h:u});return Object.freeze(l)}function xi(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function uo(e){let t=xi(e);return t+Math.ceil(t/2)}function fo(e,t,r=!1){let n=e.length,o=xi(t),s=uo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ht(e):De(e),c=J(i,t-nt)+nt;return r?oo(c,o):Hr(c,o)}var Re=BigInt(0),be=BigInt(1);function ir(e,t){let r=t.negate();return e?r:t}function Ft(e,t){let r=sr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Ai(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function lo(e,t){Ai(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=oe(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ei(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=be);let f=t*n,p=f+Math.abs(c)-1,l=c===0,u=c<0,h=t%2!==0;return{nextN:a,offset:p,isZero:l,isNeg:u,isNegF:h,offsetF:f}}function Su(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function vu(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var ho=new WeakMap,Bi=new WeakMap;function po(e){return Bi.get(e)||1}function Si(e){if(e!==Re)throw new Error("invalid wNAF")}var Ne=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Re;)r&be&&(n=n.add(o)),o=o.double(),r>>=be;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=lo(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let f=1;f<o;f++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=lo(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:f,isZero:p,isNeg:l,isNegF:u,offsetF:h}=Ei(n,c,i);n=a,p?s=s.add(ir(u,r[h])):o=o.add(ir(l,r[f]))}return Si(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=lo(t,this.bits);for(let i=0;i<s.windows&&n!==Re;i++){let{nextN:c,offset:a,isZero:f,isNeg:p}=Ei(n,i,s);if(n=c,!f){let l=r[a];o=o.add(p?l.negate():l)}}return Si(n),o}getPrecomputes(t,r,n){let o=ho.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ho.set(r,o))),o}cached(t,r,n){let o=po(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=po(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Ai(r,this.bits),Bi.set(t,r),ho.delete(t)}hasCache(t){return po(t)!==1}};function Ii(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Re||n>Re;)r&be&&(s=s.add(o)),n&be&&(i=i.add(o)),o=o.double(),r>>=be,n>>=be;return{p1:s,p2:i}}function Ue(e,t,r,n){Su(r,e),vu(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Vr(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let f=oe(a),p=new Array(Number(f)+1).fill(i),l=Math.floor((t.BITS-1)/a)*a,u=i;for(let h=l;h>=0;h-=a){p.fill(i);for(let E=0;E<s;E++){let S=n[E],b=Number(S>>BigInt(h)&f);p[b]=p[b].add(r[E])}let d=i;for(let E=p.length-1,S=i;E>0;E--)S=S.add(p[E]),d=d.add(S);if(u=u.add(d),h!==0)for(let E=0;E<a;E++)u=u.double()}return u}function vi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return co(t),t}else return Et(e,{isLE:r})}function zr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let f=t[a];if(!(typeof f=="bigint"&&f>Re))throw new Error(`CURVE.${a} must be positive bigint`)}let o=vi(t.p,r.Fp,n),s=vi(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var ie=BigInt(0),ot=BigInt(1),mo=BigInt(2),Au=BigInt(8);function Bu(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function Iu(e,t={}){let r=zr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;se(t,{},{uvRatio:"function"});let c=mo<<BigInt(o.BYTES*8)-ot,a=S=>n.create(S),f=t.uvRatio||((S,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,b))}}catch{return{isValid:!1,value:ie}}});if(!Bu(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function p(S,b,A=!1){let w=A?ot:ie;return or("coordinate "+S,b,w,c),b}function l(S){if(!(S instanceof d))throw new Error("ExtendedPoint expected")}let u=Ke((S,b)=>{let{X:A,Y:w,Z:L}=S,D=S.is0();b==null&&(b=D?Au:n.inv(L));let O=a(A*b),k=a(w*b),R=n.mul(L,b);if(D)return{x:ie,y:ot};if(R!==ot)throw new Error("invZ was invalid");return{x:O,y:k}}),h=Ke(S=>{let{a:b,d:A}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:w,Y:L,Z:D,T:O}=S,k=a(w*w),R=a(L*L),x=a(D*D),T=a(x*x),N=a(k*b),C=a(x*a(N+R)),g=a(T+a(A*a(k*R)));if(C!==g)throw new Error("bad point: equation left != right (1)");let m=a(w*L),y=a(D*O);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(b,A,w,L){this.X=p("x",b),this.Y=p("y",A),this.Z=p("z",w,!0),this.T=p("t",L),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof d)throw new Error("extended point not allowed");let{x:A,y:w}=b||{};return p("x",A),p("y",w),new d(A,w,ot,a(A*w))}static fromBytes(b,A=!1){let w=n.BYTES,{a:L,d:D}=s;b=so(xt(b,w,"point")),qt(A,"zip215");let O=so(b),k=b[w-1];O[w-1]=k&-129;let R=Ht(O),x=A?c:n.ORDER;or("point.y",R,ie,x);let T=a(R*R),N=a(T-ot),C=a(D*T-L),{isValid:g,value:m}=f(N,C);if(!g)throw new Error("bad point: invalid y coordinate");let y=(m&ot)===ot,v=(k&128)!==0;if(!A&&m===ie&&v)throw new Error("bad point: x=0 and x_0=1");return v!==y&&(m=a(-m)),d.fromAffine({x:m,y:R})}static fromHex(b,A=!1){return d.fromBytes(H("point",b),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,A=!0){return E.createCache(this,b),A||this.multiply(mo),this}assertValidity(){h(this)}equals(b){l(b);let{X:A,Y:w,Z:L}=this,{X:D,Y:O,Z:k}=b,R=a(A*k),x=a(D*L),T=a(w*k),N=a(O*L);return R===x&&T===N}is0(){return this.equals(d.ZERO)}negate(){return new d(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:b}=s,{X:A,Y:w,Z:L}=this,D=a(A*A),O=a(w*w),k=a(mo*a(L*L)),R=a(b*D),x=A+w,T=a(a(x*x)-D-O),N=R+O,C=N-k,g=R-O,m=a(T*C),y=a(N*g),v=a(T*g),B=a(C*N);return new d(m,y,B,v)}add(b){l(b);let{a:A,d:w}=s,{X:L,Y:D,Z:O,T:k}=this,{X:R,Y:x,Z:T,T:N}=b,C=a(L*R),g=a(D*x),m=a(k*w*N),y=a(O*T),v=a((L+D)*(R+x)-C-g),B=y-m,P=y+m,I=a(g-A*C),_=a(v*B),K=a(P*I),U=a(v*I),Y=a(B*P);return new d(_,K,Y,U)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=E.cached(this,b,L=>Ft(d,L));return Ft(d,[A,w])[0]}multiplyUnsafe(b,A=d.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===ie?d.ZERO:this.is0()||b===ot?this:E.unsafe(this,b,w=>Ft(d,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(b){return u(this,b)}clearCofactor(){return i===ot?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=b&ot?128:0,w}toHex(){return vt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(b){return Ft(d,b)}static msm(b,A){return Ue(d,o,b,A)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}d.BASE=new d(s.Gx,s.Gy,ot,a(s.Gx*s.Gy)),d.ZERO=new d(ie,ot,ot,ie),d.Fp=n,d.Fn=o;let E=new Ne(d,o.BITS);return d.BASE.precompute(8),d}var Gr=class{constructor(t){this.ep=t}static fromBytes(t){io()}static fromHex(t){io()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return vt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function _u(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');se(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||te,a=r.adjustScalarBytes||(x=>x),f=r.domain||((x,T,N)=>{if(qt(N,"phflag"),T.length||N)throw new Error("Contexts/pre-hash are not supported");return x});function p(x){return i.create(Ht(x))}function l(x){let T=w.secretKey;x=H("private key",x,T);let N=H("hashed private key",t(x),2*T),C=a(N.slice(0,T)),g=N.slice(T,2*T),m=p(C);return{head:C,prefix:g,scalar:m}}function u(x){let{head:T,prefix:N,scalar:C}=l(x),g=o.multiply(C),m=g.toBytes();return{head:T,prefix:N,scalar:C,point:g,pointBytes:m}}function h(x){return u(x).pointBytes}function d(x=Uint8Array.of(),...T){let N=ht(...T);return p(t(f(N,H("context",x),!!n)))}function E(x,T,N={}){x=H("message",x),n&&(x=n(x));let{prefix:C,scalar:g,pointBytes:m}=u(T),y=d(N.context,C,x),v=o.multiply(y).toBytes(),B=d(N.context,v,m,x),P=i.create(y+B*g);if(!i.isValid(P))throw new Error("sign failed: invalid s");let I=ht(v,i.toBytes(P));return xt(I,w.signature,"result")}let S={zip215:!0};function b(x,T,N,C=S){let{context:g,zip215:m}=C,y=w.signature;x=H("signature",x,y),T=H("message",T),N=H("publicKey",N,w.publicKey),m!==void 0&&qt(m,"zip215"),n&&(T=n(T));let v=y/2,B=x.subarray(0,v),P=Ht(x.subarray(v,y)),I,_,K;try{I=e.fromBytes(N,m),_=e.fromBytes(B,m),K=o.multiplyUnsafe(P)}catch{return!1}if(!m&&I.isSmallOrder())return!1;let U=d(g,_.toBytes(),I.toBytes(),T);return _.add(I.multiplyUnsafe(U)).subtract(K).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function L(x=c(w.seed)){return xt(x,w.seed,"seed")}function D(x){let T=R.randomSecretKey(x);return{secretKey:T,publicKey:h(T)}}function O(x){return kt(x)&&x.length===i.BYTES}function k(x,T){try{return!!e.fromBytes(x,T)}catch{return!1}}let R={getExtendedPublicKey:u,randomSecretKey:L,isValidSecretKey:O,isValidPublicKey:k,toMontgomery(x){let{y:T}=e.fromBytes(x),N=w.publicKey,C=N===32;if(!C&&N!==57)throw new Error("only defined for 25519 and 448");let g=C?s.div(ot+T,ot-T):s.div(T-ot,T+ot);return s.toBytes(g)},toMontgomeryPriv(x){let T=w.secretKey;xt(x,T);let N=t(x.subarray(0,T));return a(N).subarray(0,T)},randomPrivateKey:L,precompute(x=8,T=e.BASE){return T.precompute(x,!1)}};return Object.freeze({keygen:D,getPublicKey:h,sign:E,verify:b,utils:R,Point:e,lengths:w})}function Lu(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=Et(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function Tu(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function _i(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=Lu(e),s=Iu(t,r),i=_u(s,n,o);return Tu(e,i)}var Cu=BigInt(0),zt=BigInt(1),Li=BigInt(2),td=BigInt(3),Pu=BigInt(5),Du=BigInt(8),ke=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ar={p:ke,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Du,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Ku(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ke,c=e*e%s*e%s,a=G(c,Li,s)*c%s,f=G(a,zt,s)*e%s,p=G(f,Pu,s)*f%s,l=G(p,t,s)*p%s,u=G(l,r,s)*l%s,h=G(u,n,s)*u%s,d=G(h,o,s)*h%s,E=G(d,o,s)*h%s,S=G(E,t,s)*p%s;return{pow_p_5_8:G(S,Li,s)*e%s,b2:c}}function Ru(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var yo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function wo(e,t){let r=ke,n=J(t*t*t,r),o=J(n*n*t,r),s=Ku(e*o).pow_p_5_8,i=J(e*n*s,r),c=J(t*i*i,r),a=i,f=J(i*yo,r),p=c===e,l=c===J(-e,r),u=c===J(-e*yo,r);return p&&(i=a),(l||u)&&(i=f),Vt(i,r)&&(i=J(-i,r)),{isValid:p||l,value:i}}var ae=Et(ar.p,{isLE:!0}),Nu=Et(ar.n,{isLE:!0}),Uu={...ar,Fp:ae,hash:ii,adjustScalarBytes:Ru,uvRatio:wo},Gt=_i(Uu);var bo=yo,ku=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Ou=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Mu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),qu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ti=e=>wo(zt,e),Hu=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),go=e=>Gt.Point.Fp.create(Ht(e)&Hu);function Ci(e){let{d:t}=ar,r=ke,n=b=>ae.create(b),o=n(bo*e*e),s=n((o+zt)*Mu),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:f}=wo(s,c),p=n(f*e);Vt(p,r)||(p=n(-p)),a||(f=p),a||(i=o);let l=n(i*(o-zt)*qu-c),u=f*f,h=n((f+f)*c),d=n(l*ku),E=n(zt-u),S=n(zt+u);return new Gt.Point(n(h*S),n(E*d),n(d*S),n(h*E))}function Vu(e){wt(e,64);let t=go(e.subarray(0,32)),r=Ci(t),n=go(e.subarray(32,64)),o=Ci(n);return new Zt(r.add(o))}var Zt=class e extends Gr{constructor(t){super(t)}static fromAffine(t){return new e(Gt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Vu(H("ristrettoHash",t,64))}static fromBytes(t){wt(t,32);let{a:r,d:n}=ar,o=ke,s=L=>ae.create(L),i=go(t);if(!ci(ae.toBytes(i),t)||Vt(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(zt+r*c),f=s(zt-r*c),p=s(a*a),l=s(f*f),u=s(r*n*p-l),{isValid:h,value:d}=Ti(s(u*l)),E=s(d*f),S=s(d*E*u),b=s((i+i)*E);Vt(b,o)&&(b=s(-b));let A=s(a*S),w=s(b*A);if(!h||Vt(w,o)||A===Cu)throw new Error("invalid ristretto255 encoding 2");return new e(new Gt.Point(b,A,zt,w))}static fromHex(t){return e.fromBytes(H("ristrettoHex",t,32))}static msm(t,r){return Ue(e,Gt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=ke,i=S=>ae.create(S),c=i(i(n+r)*i(n-r)),a=i(t*r),f=i(a*a),{value:p}=Ti(i(c*f)),l=i(p*c),u=i(p*a),h=i(l*u*o),d;if(Vt(o*h,s)){let S=i(r*bo),b=i(t*bo);t=S,r=b,d=i(l*Ou)}else d=u;Vt(t*h,s)&&(r=i(-r));let E=i((n-r)*d);return Vt(E,s)&&(E=i(-E)),ae.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=f=>ae.create(f),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};Zt.BASE=new Zt(Gt.Point.BASE);Zt.ZERO=new Zt(Gt.Point.ZERO);Zt.Fp=ae;Zt.Fn=Nu;var cr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Pi={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Zr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var At=Pi;var jr=32;var xo,Fu=(async()=>{try{return await At.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function zu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await At.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await At.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Gu(e,t,r){return Gt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Di(e,t,r){return xo==null&&(xo=await Fu),xo?zu(e,t,r):Gu(e,t,r)}function Yr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Xr=class{type="Ed25519";raw;constructor(t){this.raw=Eo(t,jr)}toMultihash(){return It.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Di(this.raw,r,t);return Yr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function So(e){return e=Eo(e,jr),new Xr(e)}function Eo(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Z(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var ju=Math.pow(2,7),Yu=Math.pow(2,14),Xu=Math.pow(2,21),vo=Math.pow(2,28),Ao=Math.pow(2,35),Bo=Math.pow(2,42),Io=Math.pow(2,49),q=128,ut=127;function Lt(e){if(e<ju)return 1;if(e<Yu)return 2;if(e<Xu)return 3;if(e<vo)return 4;if(e<Ao)return 5;if(e<Bo)return 6;if(e<Io)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function _o(e,t,r=0){switch(Lt(e)){case 8:t[r++]=e&255|q,e/=128;case 7:t[r++]=e&255|q,e/=128;case 6:t[r++]=e&255|q,e/=128;case 5:t[r++]=e&255|q,e/=128;case 4:t[r++]=e&255|q,e>>>=7;case 3:t[r++]=e&255|q,e>>>=7;case 2:t[r++]=e&255|q,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function $u(e,t,r=0){switch(Lt(e)){case 8:t.set(r++,e&255|q),e/=128;case 7:t.set(r++,e&255|q),e/=128;case 6:t.set(r++,e&255|q),e/=128;case 5:t.set(r++,e&255|q),e/=128;case 4:t.set(r++,e&255|q),e>>>=7;case 3:t.set(r++,e&255|q),e>>>=7;case 2:t.set(r++,e&255|q),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Lo(e,t){let r=e[t],n=0;if(n+=r&ut,r<q||(r=e[t+1],n+=(r&ut)<<7,r<q)||(r=e[t+2],n+=(r&ut)<<14,r<q)||(r=e[t+3],n+=(r&ut)<<21,r<q)||(r=e[t+4],n+=(r&ut)*vo,r<q)||(r=e[t+5],n+=(r&ut)*Ao,r<q)||(r=e[t+6],n+=(r&ut)*Bo,r<q)||(r=e[t+7],n+=(r&ut)*Io,r<q))return n;throw new RangeError("Could not decode varint")}function Wu(e,t){let r=e.get(t),n=0;if(n+=r&ut,r<q||(r=e.get(t+1),n+=(r&ut)<<7,r<q)||(r=e.get(t+2),n+=(r&ut)<<14,r<q)||(r=e.get(t+3),n+=(r&ut)<<21,r<q)||(r=e.get(t+4),n+=(r&ut)*vo,r<q)||(r=e.get(t+5),n+=(r&ut)*Ao,r<q)||(r=e.get(t+6),n+=(r&ut)*Bo,r<q)||(r=e.get(t+7),n+=(r&ut)*Io,r<q))return n;throw new RangeError("Could not decode varint")}function Ri(e,t,r=0){return t==null&&(t=ct(Lt(e))),t instanceof Uint8Array?_o(e,t,r):$u(e,t,r)}function Ni(e,t=0){return e instanceof Uint8Array?Lo(e,t):Wu(e,t)}var To=new Float32Array([-0]),ce=new Uint8Array(To.buffer);function ki(e,t,r){To[0]=e,t[r]=ce[0],t[r+1]=ce[1],t[r+2]=ce[2],t[r+3]=ce[3]}function Oi(e,t){return ce[0]=e[t],ce[1]=e[t+1],ce[2]=e[t+2],ce[3]=e[t+3],To[0]}var Co=new Float64Array([-0]),ft=new Uint8Array(Co.buffer);function Mi(e,t,r){Co[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function qi(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],Co[0]}var Ju=BigInt(Number.MAX_SAFE_INTEGER),Qu=BigInt(Number.MIN_SAFE_INTEGER),St=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ge;if(t<Ju&&t>Qu)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Hi&&(o=0n,++n>Hi&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ge}},ge=new St(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var Hi=4294967296n;function Vi(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Fi(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Po(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Tt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function $r(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Do=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Tt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Tt(this,4);return $r(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return $r(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=Oi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=qi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Tt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Fi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new St(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Tt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Tt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Tt(this,8);let t=$r(this.buf,this.pos+=4),r=$r(this.buf,this.pos+=4);return new St(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Lo(this.buf,this.pos);return this.pos+=Lt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ko(e){return new Do(e instanceof Uint8Array?e:e.subarray())}function Wr(e,t,r){let n=Ko(e);return t.decode(n,void 0,r)}function Ro(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ct(i);o+i>t&&(n=ct(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var we=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function No(){}var ko=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},tf=Ro();function ef(e){return globalThis.Buffer!=null?ct(e):tf(e)}var fr=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(No,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new we(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Oo((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Jr,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=St.fromBigInt(t);return this._push(Jr,r.length(),r)}uint64Number(t){return this._push(_o,Lt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=St.fromBigInt(t).zzEncode();return this._push(Jr,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push(Jr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Uo,1,t?1:0)}fixed32(t){return this._push(ur,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(ur,4,r.lo)._push(ur,4,r.hi)}fixed64Number(t){let r=St.fromNumber(t);return this._push(ur,4,r.lo)._push(ur,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ki,4,t)}double(t){return this._push(Mi,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Uo,1,0):this.uint32(r)._push(nf,r,t)}string(t){let r=Vi(t);return r!==0?this.uint32(r)._push(Po,r,t):this._push(Uo,1,0)}fork(){return this.states=new ko(this),this.head=this.tail=new we(No,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new we(No,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=ef(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Uo(e,t,r){t[r]=e&255}function rf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Oo=class extends we{next;constructor(t,r){super(rf,t,r),this.next=void 0}};function Jr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function ur(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function nf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(fr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(of,t,e),this},fr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(sf,t,e),this});function of(e,t,r){t.set(e,r)}function sf(e,t,r){e.length<40?Po(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(F(e),r)}function Mo(){return new fr}function Qr(e,t){let r=Mo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Oe;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Oe||(Oe={}));function tn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function qo(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return tn("enum",Oe.VARINT,r,n)}function en(e,t){return tn("message",Oe.LENGTH_DELIMITED,e,t)}var tt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(tt||(tt={}));var Ho;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ho||(Ho={}));(function(e){e.codec=()=>qo(Ho)})(tt||(tt={}));var Pt;(function(e){let t;e.codec=()=>(t==null&&(t=en((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),tt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Qr(r,e.codec()),e.decode=(r,n)=>Wr(r,e.codec(),n)})(Pt||(Pt={}));var Vo;(function(e){let t;e.codec=()=>(t==null&&(t=en((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),tt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Qr(r,e.codec()),e.decode=(r,n)=>Wr(r,e.codec(),n)})(Vo||(Vo={}));function rn(e){if(isNaN(e)||e<=0)throw new Z("random bytes length must be a Number bigger than 0");return te(e)}var hr={};yt(hr,{MAX_RSA_KEY_SIZE:()=>Fo,generateRSAKeyPair:()=>Xi,jwkToJWKKeyPair:()=>$i,jwkToPkcs1:()=>ff,jwkToPkix:()=>jo,jwkToRSAPrivateKey:()=>Wo,pkcs1MessageToJwk:()=>Go,pkcs1MessageToRSAPrivateKey:()=>Yo,pkcs1ToJwk:()=>uf,pkcs1ToRSAPrivateKey:()=>Yi,pkixMessageToJwk:()=>Zo,pkixMessageToRSAPublicKey:()=>$o,pkixToJwk:()=>lf,pkixToRSAPublicKey:()=>Xo});var nn=qr;var Me=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=hr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){return ji(this.jwk,r,t,n)}},lr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=hr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}sign(t,r){return Zi(this.jwk,t,r)}};var Fo=8192,zo=18,af=1062,cf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function uf(e){let t=Rt(e);return Go(t)}function Go(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function ff(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new Z("JWK was missing components");return Qt([gt(Uint8Array.from([0])),gt(F(e.n,"base64url")),gt(F(e.e,"base64url")),gt(F(e.d,"base64url")),gt(F(e.p,"base64url")),gt(F(e.q,"base64url")),gt(F(e.dp,"base64url")),gt(F(e.dq,"base64url")),gt(F(e.qi,"base64url"))]).subarray()}function lf(e){let t=Rt(e,{offset:0});return Zo(t)}function Zo(e){let t=Rt(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function jo(e){if(e.n==null||e.e==null)throw new Z("JWK was missing components");return Qt([cf,Nr(Qt([gt(F(e.n,"base64url")),gt(F(e.e,"base64url"))]))]).subarray()}function Yi(e){let t=Rt(e);return Yo(t)}function Yo(e){let t=Go(e);return Wo(t)}function Xo(e,t){if(e.byteLength>=af)throw new Se("Key size is too large");let r=Rt(e,{offset:0});return $o(r,e,t)}function $o(e,t,r){let n=Zo(e);if(r==null){let o=nn(Pt.encode({Type:tt.RSA,Data:t}));r=Bt(zo,o)}return new Me(n,r)}function Wo(e){if(Ji(e)>Fo)throw new Z("Key size is too large");let t=$i(e),r=nn(Pt.encode({Type:tt.RSA,Data:jo(t.publicKey)})),n=Bt(zo,r);return new lr(t.privateKey,new Me(t.publicKey,n))}async function Xi(e){if(e>Fo)throw new Z("Key size is too large");let t=await Wi(e),r=nn(Pt.encode({Type:tt.RSA,Data:jo(t.publicKey)})),n=Bt(zo,r);return new lr(t.privateKey,new Me(t.publicKey,n))}function $i(e){if(e==null)throw new Z("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Wi(e,t){let r=await At.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await hf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Zi(e,t,r){let n=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function ji(e,t,r,n){let o=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function hf(e,t){if(e.privateKey==null||e.publicKey==null)throw new Z("Private and public key are required");let r=await Promise.all([At.get().subtle.exportKey("jwk",e.privateKey),At.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Ji(e){if(e.kty!=="RSA")throw new Z("invalid key type");if(e.n==null)throw new Z("invalid key modulus");return F(e.n,"base64url").length*8}var on=class extends Ce{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Ur(t);let n=Qe(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Ot(s)}update(t){return Pe(this),this.iHash.update(t),this}digestInto(t){Pe(this),wt(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Jo=(e,t,r)=>new on(e,t).update(r).digest();Jo.create=(e,t)=>new on(e,t);var Qi=(e,t)=>(e+(e>=0?t:-t)/ta)/t;function df(e,t,r){let[[n,o],[s,i]]=t,c=Qi(i*e,r),a=Qi(-o*e,r),f=e-c*n-a*s,p=-c*o-a*i,l=f<Yt,u=p<Yt;l&&(f=-f),u&&(p=-p);let h=oe(Math.ceil(Vr(r)/2))+He;if(f<Yt||f>=h||p<Yt||p>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:u,k2:p}}function ts(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Qo(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return qt(r.lowS,"lowS"),qt(r.prehash,"prehash"),r.format!==void 0&&ts(r.format),r}var es=class extends Error{constructor(t=""){super(t)}},jt={Err:es,_tlv:{encode:(e,t)=>{let{Err:r}=jt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=nr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?nr(o.length/2|128):"";return nr(e)+s+o+t},decode(e,t){let{Err:r}=jt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+a);if(f.length!==a)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let p of f)i=i<<8|p;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=jt;if(e<Yt)throw new t("integer: negative integers are not allowed");let r=nr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=jt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return De(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=jt,o=H("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:f,l:p}=n.decode(2,a);if(p.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=jt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Yt=BigInt(0),He=BigInt(1),ta=BigInt(2),sn=BigInt(3),pf=BigInt(4);function qe(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=H("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function mf(e,t={}){let r=zr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;se(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=ra(n,o);function p(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(C,g,m){let{x:y,y:v}=g.toAffine(),B=n.toBytes(y);if(qt(m,"isCompressed"),m){p();let P=!n.isOdd(v);return ht(ea(P),B)}else return ht(Uint8Array.of(4),B,n.toBytes(v))}function u(C){xt(C,void 0,"Point");let{publicKey:g,publicKeyUncompressed:m}=f,y=C.length,v=C[0],B=C.subarray(1);if(y===g&&(v===2||v===3)){let P=n.fromBytes(B);if(!n.isValid(P))throw new Error("bad point: is not on curve, wrong x");let I=E(P),_;try{_=n.sqrt(I)}catch(Y){let V=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}p();let K=n.isOdd(_);return(v&1)===1!==K&&(_=n.neg(_)),{x:P,y:_}}else if(y===m&&v===4){let P=n.BYTES,I=n.fromBytes(B.subarray(0,P)),_=n.fromBytes(B.subarray(P,P*2));if(!S(I,_))throw new Error("bad point: is not on curve");return{x:I,y:_}}else throw new Error(`bad point: got length ${y}, expected compressed=${g} or uncompressed=${m}`)}let h=t.toBytes||l,d=t.fromBytes||u;function E(C){let g=n.sqr(C),m=n.mul(g,C);return n.add(n.add(m,n.mul(C,s.a)),s.b)}function S(C,g){let m=n.sqr(g),y=E(C);return n.eql(m,y)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,sn),pf),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,A)))throw new Error("bad curve params: a or b");function w(C,g,m=!1){if(!n.isValid(g)||m&&n.is0(g))throw new Error(`bad point coordinate ${C}`);return g}function L(C){if(!(C instanceof x))throw new Error("ProjectivePoint expected")}function D(C){if(!a||!a.basises)throw new Error("no endo");return df(C,a.basises,o.ORDER)}let O=Ke((C,g)=>{let{X:m,Y:y,Z:v}=C;if(n.eql(v,n.ONE))return{x:m,y};let B=C.is0();g==null&&(g=B?n.ONE:n.inv(v));let P=n.mul(m,g),I=n.mul(y,g),_=n.mul(v,g);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:P,y:I}}),k=Ke(C=>{if(C.is0()){if(t.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:m}=C.toAffine();if(!n.isValid(g)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!S(g,m))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(C,g,m,y,v){return m=new x(n.mul(m.X,C),m.Y,m.Z),g=ir(y,g),m=ir(v,m),g.add(m)}class x{constructor(g,m,y){this.X=w("x",g),this.Y=w("y",m,!0),this.Z=w("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:m,y}=g||{};if(!g||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(g instanceof x)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?x.ZERO:new x(m,y,n.ONE)}static fromBytes(g){let m=x.fromAffine(d(xt(g,void 0,"point")));return m.assertValidity(),m}static fromHex(g){return x.fromBytes(H("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,m=!0){return N.createCache(this,g),m||this.multiply(sn),this}assertValidity(){k(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){L(g);let{X:m,Y:y,Z:v}=this,{X:B,Y:P,Z:I}=g,_=n.eql(n.mul(m,I),n.mul(B,v)),K=n.eql(n.mul(y,I),n.mul(P,v));return _&&K}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:m}=s,y=n.mul(m,sn),{X:v,Y:B,Z:P}=this,I=n.ZERO,_=n.ZERO,K=n.ZERO,U=n.mul(v,v),Y=n.mul(B,B),V=n.mul(P,P),M=n.mul(v,B);return M=n.add(M,M),K=n.mul(v,P),K=n.add(K,K),I=n.mul(g,K),_=n.mul(y,V),_=n.add(I,_),I=n.sub(Y,_),_=n.add(Y,_),_=n.mul(I,_),I=n.mul(M,I),K=n.mul(y,K),V=n.mul(g,V),M=n.sub(U,V),M=n.mul(g,M),M=n.add(M,K),K=n.add(U,U),U=n.add(K,U),U=n.add(U,V),U=n.mul(U,M),_=n.add(_,U),V=n.mul(B,P),V=n.add(V,V),U=n.mul(V,M),I=n.sub(I,U),K=n.mul(V,Y),K=n.add(K,K),K=n.add(K,K),new x(I,_,K)}add(g){L(g);let{X:m,Y:y,Z:v}=this,{X:B,Y:P,Z:I}=g,_=n.ZERO,K=n.ZERO,U=n.ZERO,Y=s.a,V=n.mul(s.b,sn),M=n.mul(m,B),X=n.mul(y,P),et=n.mul(v,I),mt=n.add(m,y),$=n.add(B,P);mt=n.mul(mt,$),$=n.add(M,X),mt=n.sub(mt,$),$=n.add(m,v);let it=n.add(B,I);return $=n.mul($,it),it=n.add(M,et),$=n.sub($,it),it=n.add(y,v),_=n.add(P,I),it=n.mul(it,_),_=n.add(X,et),it=n.sub(it,_),U=n.mul(Y,$),_=n.mul(V,et),U=n.add(_,U),_=n.sub(X,U),U=n.add(X,U),K=n.mul(_,U),X=n.add(M,M),X=n.add(X,M),et=n.mul(Y,et),$=n.mul(V,$),X=n.add(X,et),et=n.sub(M,et),et=n.mul(Y,et),$=n.add($,et),M=n.mul(X,$),K=n.add(K,M),M=n.mul(it,$),_=n.mul(mt,_),_=n.sub(_,M),M=n.mul(mt,X),U=n.mul(it,U),U=n.add(U,M),new x(_,K,U)}subtract(g){return this.add(g.negate())}is0(){return this.equals(x.ZERO)}multiply(g){let{endo:m}=t;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let y,v,B=P=>N.cached(this,P,I=>Ft(x,I));if(m){let{k1neg:P,k1:I,k2neg:_,k2:K}=D(g),{p:U,f:Y}=B(I),{p:V,f:M}=B(K);v=Y.add(M),y=R(m.beta,U,V,P,_)}else{let{p:P,f:I}=B(g);y=P,v=I}return Ft(x,[y,v])[0]}multiplyUnsafe(g){let{endo:m}=t,y=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===Yt||y.is0())return x.ZERO;if(g===He)return y;if(N.hasCache(this))return this.multiply(g);if(m){let{k1neg:v,k1:B,k2neg:P,k2:I}=D(g),{p1:_,p2:K}=Ii(x,y,B,I);return R(m.beta,_,K,v,P)}else return N.unsafe(y,g)}multiplyAndAddUnsafe(g,m,y){let v=this.multiplyUnsafe(m).add(g.multiplyUnsafe(y));return v.is0()?void 0:v}toAffine(g){return O(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return i===He?!0:g?g(x,this):N.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===He?this:g?g(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return qt(g,"isCompressed"),this.assertValidity(),h(x,this,g)}toHex(g=!0){return vt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return Ft(x,g)}static msm(g,m){return Ue(x,o,g,m)}static fromPrivateKey(g){return x.BASE.multiply(qe(o,g))}}x.BASE=new x(s.Gx,s.Gy,n.ONE),x.ZERO=new x(n.ZERO,n.ONE,n.ZERO),x.Fp=n,x.Fn=o;let T=o.BITS,N=new Ne(x,t.endo?Math.ceil(T/2):T);return x.BASE.precompute(8),x}function ea(e){return Uint8Array.of(e?2:3)}function ra(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function yf(e,t={}){let{Fn:r}=e,n=t.randomBytes||te,o=Object.assign(ra(e.Fp,r),{seed:uo(r.ORDER)});function s(h){try{return!!qe(r,h)}catch{return!1}}function i(h,d){let{publicKey:E,publicKeyUncompressed:S}=o;try{let b=h.length;return d===!0&&b!==E||d===!1&&b!==S?!1:!!e.fromBytes(h)}catch{return!1}}function c(h=n(o.seed)){return fo(xt(h,o.seed,"seed"),r.ORDER)}function a(h,d=!0){return e.BASE.multiply(qe(r,h)).toBytes(d)}function f(h){let d=c(h);return{secretKey:d,publicKey:a(d)}}function p(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let{secretKey:d,publicKey:E,publicKeyUncompressed:S}=o;if(r.allowedLengths||d===E)return;let b=H("key",h).length;return b===E||b===S}function l(h,d,E=!0){if(p(h)===!0)throw new Error("first arg must be private key");if(p(d)===!1)throw new Error("second arg must be public key");let S=qe(r,h);return e.fromHex(d).multiply(S).toBytes(E)}return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:f,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:h=>qe(r,h),precompute(h=8,d=e.BASE){return d.precompute(h,!1)}},lengths:o})}function bf(e,t,r={}){Ur(t),se(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||te,o=r.hmac||((m,...y)=>Jo(t,m,ht(...y))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:f,getPublicKey:p,getSharedSecret:l,utils:u,lengths:h}=yf(e,r),d={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function S(m){let y=c>>He;return m>y}function b(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function A(m,y){ts(y);let v=h.signature,B=y==="compact"?v:y==="recovered"?v+1:void 0;return xt(m,B,`${y} signature`)}class w{constructor(y,v,B){this.r=b("r",y),this.s=b("s",v),B!=null&&(this.recovery=B),Object.freeze(this)}static fromBytes(y,v=E){A(y,v);let B;if(v==="der"){let{r:K,s:U}=jt.toSig(xt(y));return new w(K,U)}v==="recovered"&&(B=y[0],v="compact",y=y.subarray(1));let P=i.BYTES,I=y.subarray(0,P),_=y.subarray(P,P*2);return new w(i.fromBytes(I),i.fromBytes(_),B)}static fromHex(y,v){return this.fromBytes(de(y),v)}addRecoveryBit(y){return new w(this.r,this.s,y)}recoverPublicKey(y){let v=s.ORDER,{r:B,s:P,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(c*ta<v&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");let K=I===2||I===3?B+c:B;if(!s.isValid(K))throw new Error("recovery id 2 or 3 invalid");let U=s.toBytes(K),Y=e.fromBytes(ht(ea((I&1)===0),U)),V=i.inv(K),M=D(H("msgHash",y)),X=i.create(-M*V),et=i.create(P*V),mt=e.BASE.multiplyUnsafe(X).add(Y.multiplyUnsafe(et));if(mt.is0())throw new Error("point at infinify");return mt.assertValidity(),mt}hasHighS(){return S(this.s)}toBytes(y=E){if(ts(y),y==="der")return de(jt.hexFromSig(this));let v=i.toBytes(this.r),B=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ht(Uint8Array.of(this.recovery),v,B)}return ht(v,B)}toHex(y){return vt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return w.fromBytes(H("sig",y),"compact")}static fromDER(y){return w.fromBytes(H("sig",y),"der")}normalizeS(){return this.hasHighS()?new w(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return vt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return vt(this.toBytes("compact"))}}let L=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let v=De(y),B=y.length*8-a;return B>0?v>>BigInt(B):v},D=r.bits2int_modN||function(y){return i.create(L(y))},O=oe(a);function k(m){return or("num < 2^"+a,m,Yt,O),i.toBytes(m)}function R(m,y){return xt(m,void 0,"message"),y?xt(t(m),void 0,"prehashed message"):m}function x(m,y,v){if(["recovered","canonical"].some(X=>X in v))throw new Error("sign() legacy options not supported");let{lowS:B,prehash:P,extraEntropy:I}=Qo(v,d);m=R(m,P);let _=D(m),K=qe(i,y),U=[k(K),k(_)];if(I!=null&&I!==!1){let X=I===!0?n(h.secretKey):I;U.push(H("extraEntropy",X))}let Y=ht(...U),V=_;function M(X){let et=L(X);if(!i.isValidNot0(et))return;let mt=i.inv(et),$=e.BASE.multiply(et).toAffine(),it=i.create($.x);if(it===Yt)return;let Lr=i.create(mt*i.create(V+it*K));if(Lr===Yt)return;let bs=($.x===it?0:2)|Number($.y&He),gs=Lr;return B&&S(Lr)&&(gs=i.neg(Lr),bs^=1),new w(it,gs,bs)}return{seed:Y,k2sig:M}}function T(m,y,v={}){m=H("message",m);let{seed:B,k2sig:P}=x(m,y,v);return fi(t.outputLen,i.BYTES,o)(B,P)}function N(m){let y,v=typeof m=="string"||kt(m),B=!v&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!v&&!B)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(B)y=new w(m.r,m.s);else if(v){try{y=w.fromBytes(H("sig",m),"der")}catch(P){if(!(P instanceof jt.Err))throw P}if(!y)try{y=w.fromBytes(H("sig",m),"compact")}catch{return!1}}return y||!1}function C(m,y,v,B={}){let{lowS:P,prehash:I,format:_}=Qo(B,d);if(v=H("publicKey",v),y=R(H("message",y),I),"strict"in B)throw new Error("options.strict was renamed to lowS");let K=_===void 0?N(m):w.fromBytes(H("sig",m),_);if(K===!1)return!1;try{let U=e.fromBytes(v);if(P&&K.hasHighS())return!1;let{r:Y,s:V}=K,M=D(y),X=i.inv(V),et=i.create(M*X),mt=i.create(Y*X),$=e.BASE.multiplyUnsafe(et).add(U.multiplyUnsafe(mt));return $.is0()?!1:i.create($.x)===Y}catch{return!1}}function g(m,y,v={}){let{prehash:B}=Qo(v,d);return y=R(y,B),w.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:f,getPublicKey:p,getSharedSecret:l,utils:u,lengths:h,Point:e,sign:T,verify:C,recoverPublicKey:g,Signature:w,hash:t})}function gf(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=Et(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function wf(e){let{CURVE:t,curveOpts:r}=gf(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function xf(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Fr(r.Fn.ORDER,r.Fn.BITS))})}function na(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=wf(e),s=mf(t,r),i=bf(s,n,o);return xf(e,i)}function oa(e,t){let r=n=>na({...e,hash:n});return{...r(t),create:r}}var ns={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ef={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var sa=BigInt(2);function Sf(e){let t=ns.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),f=e*e*e%t,p=f*f*e%t,l=G(p,r,t)*p%t,u=G(l,r,t)*p%t,h=G(u,sa,t)*f%t,d=G(h,o,t)*h%t,E=G(d,s,t)*d%t,S=G(E,c,t)*E%t,b=G(S,a,t)*S%t,A=G(b,c,t)*E%t,w=G(A,r,t)*p%t,L=G(w,i,t)*d%t,D=G(L,n,t)*f%t,O=G(D,sa,t);if(!rs.eql(rs.sqr(O),e))throw new Error("Cannot find square root");return O}var rs=Et(ns.p,{sqrt:Sf}),Ve=oa({...ns,Fp:rs,lowS:!0,endo:Ef},qr);function ia(e,t,r,n){let o=le.digest(r instanceof Uint8Array?r:r.subarray());if(Yr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ve.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new cr(String(s))});try{return n?.signal?.throwIfAborted(),Ve.verify(t,o.digest,e)}catch(s){throw new cr(String(s))}}var an=class{type="secp256k1";raw;_key;constructor(t){this._key=ca(t),this.raw=aa(this._key)}toMultihash(){return It.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){return ia(this._key,r,t,n)}};function os(e){return new an(e)}function aa(e){return Ve.ProjectivePoint.fromHex(e).toRawBytes(!0)}function ca(e){try{return Ve.ProjectivePoint.fromHex(e),e}catch(t){throw new Se(String(t))}}function ss(e,t){let{Type:r,Data:n}=Pt.decode(e),o=n??new Uint8Array;switch(r){case tt.RSA:return Xo(o,t);case tt.Ed25519:return So(o);case tt.secp256k1:return os(o);case tt.ECDSA:return Xn(o);default:throw new ue}}function ua(e){let{Type:t,Data:r}=Pt.decode(e.digest),n=r??new Uint8Array;switch(t){case tt.Ed25519:return So(n);case tt.secp256k1:return os(n);case tt.ECDSA:return Xn(n);default:throw new ue}}function Nt(e){return Pt.encode({Type:tt[e.type],Data:e.raw})}var fa=Symbol.for("nodejs.util.inspect.custom"),vf=114,dr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[En]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(vf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[fa](){return`PeerId(${this.toString()})`}},pr=class extends dr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},mr=class extends dr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},yr=class extends dr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Af=2336,cn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=It.digest(F(this.url))}[fa](){return`PeerId(${this.url})`}[En]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Af,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function is(e){if(e.type==="Ed25519")return new mr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new yr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new pr({multihash:e.toCID().multihash,publicKey:e});throw new ue}function la(e){return is(e.publicKey)}function br(e){if(If(e))return new pr({multihash:e});if(Bf(e))try{let t=ua(e);if(t.type==="Ed25519")return new mr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new yr({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new cn(new URL(r))}throw new Cr("Supplied PeerID Multihash is invalid")}function Bf(e){return e.code===It.code}function If(e){return e.code===le.code}function xe(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function un(e){let t=Wt(j.decode(`z${e}`));return br(t)}var gr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return xe(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return xe(this.map.values(),t=>t.key)}values(){return xe(this.map.values(),t=>t.value)}get size(){return this.map.size}};var wr=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return xe(this.set.entries(),t=>{let r=un(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=un(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return xe(this.set.values(),t=>un(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function Xt(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var fn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Fe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new fn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new fn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var as=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ln(e={}){return _f(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function _f(e,t){t=t??{};let r=t.onEnd,n=new Fe,o,s,i,c=Xt(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((S,b)=>{s=A=>{s=null,n.push(A);try{S(e(n))}catch(w){b(w)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Xt()})}},f=S=>s!=null?s(S):(n.push(S),o),p=S=>(n=new Fe,s!=null?s({error:S}):(n.push({error:S}),o)),l=S=>{if(i)return o;if(t?.objectMode!==!0&&S?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:S})},u=S=>i?o:(i=!0,S!=null?p(S):f({done:!0})),h=()=>(n=new Fe,u(),{done:!0}),d=S=>(u(S),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:h,throw:d,push:l,end:u,get readableLength(){return n.size},onEmpty:async S=>{let b=S?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let A,w;b!=null&&(A=new Promise((L,D)=>{w=()=>{D(new as)},b.addEventListener("abort",w)}));try{await Promise.race([c.promise,A])}finally{w!=null&&b!=null&&b?.removeEventListener("abort",w)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(S){return E.throw(S),r!=null&&(r(S),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(S){return E.end(S),r!=null&&(r(S),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:S=>E.onEmpty(S)},o}var hn=class extends Error{type;code;constructor(t,r,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function ha(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new hn(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new hn(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([e,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var cs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Xt(),this.haveNext=Xt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Xt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,r){await this._push(t,r)}async end(t,r){t!=null?await this.throw(t):await this._push(void 0,r)}async _push(t,r){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Xt(),await ha(this.readNext.promise,r?.signal,r)}};function da(){return new cs}function Lf(e){return e[Symbol.asyncIterator]!=null}async function Tf(e,t,r){try{await Promise.all(e.map(async n=>{for await(let o of n)await t.push(o,{signal:r}),r.throwIfAborted()})),await t.end(void 0,{signal:r})}catch(n){await t.end(n,{signal:r}).catch(()=>{})}}async function*Cf(e){let t=new AbortController,r=da();Tf(e,r,t.signal).catch(()=>{});try{yield*r}finally{t.abort()}}function*Pf(e){for(let t of e)yield*t}function Df(...e){let t=[];for(let r of e)Lf(r)||t.push(r);return t.length===e.length?Pf(t):Cf(e)}var pa=Df;function xr(e,...t){if(e==null)throw new Error("Empty pipeline");if(us(e)){let n=e;e=()=>n.source}else if(ya(e)||ma(e)){let n=e;e=()=>n}let r=[e,...t];if(r.length>1&&us(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)us(r[n])&&(r[n]=Rf(r[n]));return Kf(...r)}var Kf=(...e)=>{let t;for(;e.length>0;)t=e.shift()(t);return t},ma=e=>e?.[Symbol.asyncIterator]!=null,ya=e=>e?.[Symbol.iterator]!=null,us=e=>e==null?!1:e.sink!=null&&e.source!=null,Rf=e=>t=>{let r=e.sink(t);if(r?.then!=null){let n=ln({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=e.source;if(ma(s))o=async function*(){yield*s,n.end()};else if(ya(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return pa(n,o())}return e.source};var ls=Ma(ga(),1);var Sr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},hs=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},wa=e=>globalThis.DOMException===void 0?new hs(e):new DOMException(e),xa=e=>{let t=e.reason===void 0?wa("This operation was aborted."):e.reason;return t instanceof Error?t:wa(t)};function ds(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,f=new Promise((p,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:h}=t;h.aborted&&l(xa(h)),c=()=>{l(xa(h))},h.addEventListener("abort",c,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(p,l);return}let u=new Sr;i=s.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(h){l(h)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?p():o instanceof Error?l(o):(u.message=o??`Promise timed out after ${r} milliseconds`,l(u))},r),(async()=>{try{p(await e)}catch(h){l(h)}})()}).finally(()=>{f.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}function ps(e,t,r){let n=0,o=e.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;r(e[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var vr=class{#t=[];enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,id:r.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=r.priority){this.#t.push(n);return}let o=ps(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,r){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#t.length}};var Ar=class extends ls.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#w=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:vr,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#x(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let r=this.#p-t;if(r<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},r)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#x&&this.#E){let r=this.#e.dequeue();return r?(this.emit("active"),r(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#B(t){return new Promise((r,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,r){this.#e.setPriority(t,r)}async add(t,r={}){return r.id??=(this.#w++).toString(),r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{r.signal?.throwIfAborted();let s=t({signal:r.signal});r.timeout&&(s=ds(Promise.resolve(s),{milliseconds:r.timeout})),r.signal&&(s=Promise.race([s,this.#B(r.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof Sr&&!r.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},r),this.emit("add"),this.#f()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function Ea(e){if(e!=null){if(typeof e[Symbol.iterator]=="function")return e[Symbol.iterator]();if(typeof e[Symbol.asyncIterator]=="function")return e[Symbol.asyncIterator]();if(typeof e.next=="function")return e}throw new Error("argument is not an iterator or iterable")}function Sa(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}function va(e,t){let r=Ea(e).return?.();Sa(r)&&r.catch(n=>{t.error("could not cause iterator to return",n)})}var pn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ze=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},mn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Br=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function yn(e){return e[Symbol.asyncIterator]!=null}function Aa(e,t){if(e.byteLength>t)throw new ze("Message length too long")}var gn=e=>{let t=Lt(e),r=ct(t);return Ri(e,r),gn.bytes=t,r};gn.bytes=0;function wn(e,t){t=t??{};let r=t.lengthEncoder??gn,n=t?.maxDataLength??4194304;function*o(s){Aa(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return yn(e)?async function*(){for await(let s of e)yield*o(s)}():function*(){for(let s of e)yield*o(s)}()}wn.single=(e,t)=>{t=t??{};let r=t.lengthEncoder??gn,n=t?.maxDataLength??4194304;return Aa(e,n),new rt(r(e.byteLength),e)};var Ee;(function(e){e[e.LENGTH=0]="LENGTH",e[e.DATA=1]="DATA"})(Ee||(Ee={}));var ms=e=>{let t=Ni(e);return ms.bytes=Lt(t),t};ms.bytes=0;function Ir(e,t){let r=new rt,n=Ee.LENGTH,o=-1,s=t?.lengthDecoder??ms,i=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;r.byteLength>0;){if(n===Ee.LENGTH)try{if(o=s(r),o<0)throw new pn("Invalid message length");if(o>c)throw new ze("Message length too long");let f=s.bytes;r.consume(f),t?.onLength!=null&&t.onLength(o),n=Ee.DATA}catch(f){if(f instanceof RangeError){if(r.byteLength>i)throw new mn("Message length length too long");break}throw f}if(n===Ee.DATA){if(r.byteLength<o)break;let f=r.sublist(0,o);r.consume(o),t?.onData!=null&&t.onData(f),yield f,n=Ee.LENGTH}}}return yn(e)?async function*(){for await(let f of e)r.append(f),yield*a();if(r.byteLength>0)throw new Br("Unexpected end of input")}():function*(){for(let f of e)r.append(f),yield*a();if(r.byteLength>0)throw new Br("Unexpected end of input")}()}Ir.fromReader=(e,t)=>{let r=1,n=async function*(){for(;;)try{let{done:s,value:i}=await e.next(r);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{r=1}}();return Ir(n,{...t??{},onLength:s=>{r=s}})};var xn=class extends ve{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,r){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=r.id,this.protocol=r.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let r=this.id.toString();throw new Error("No writable connection to "+r)}this.outboundStream.push(t instanceof Uint8Array?new rt(t):t)}attachInboundStream(t,r){let n=()=>{va(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=xr(this._rawInboundStream,o=>Ir(o,r)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let r=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=ln({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),xr(this.outboundStream,n=>wn(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),r==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function Ba(){return BigInt(`0x${z(rn(8),"base16")}`)}var Ia=(e,t)=>{let r=F(t.toString(16).padStart(16,"0"),"base16"),n=Nt(e),o=new Uint8Array(n.byteLength+r.length);return o.set(n,0),o.set(r,n.byteLength),o},_a=e=>le.encode(e);var La=function(e){return Array.isArray(e)?e:[e]},Mf=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=br(Wt(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return is(ss(r)).equals(t)}return!1},Ta=async e=>{if(e.from==null)throw new Q("RPC message was missing from");if(!await Mf(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=br(Wt(e.from)),r=e.key??t.publicKey;if(r==null)throw new Q("RPC message was missing public key");return{type:"signed",from:t,topic:e.topic??"",sequenceNumber:Hf(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?ss(r):r}},_r=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:qf(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Nt(e.key):void 0}:{data:e.data,topic:e.topic},qf=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},Hf=e=>BigInt(`0x${z(e,"base16")}`);var Ca=F("libp2p-pubsub:");async function Pa(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:la(e)},o=fe([Ca,r(_r(n)).subarray()]);return n.signature=await e.sign(o),n.key=e.publicKey,n}async function Da(e,t){if(e.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(e.signature==null)throw new Error("Message must contain a signature to be verified");if(e.from==null)throw new Error("Message must contain a from property to be verified");let r=fe([Ca,t({..._r(e),signature:void 0,key:void 0}).subarray()]);return Vf(e).verify(r,e.signature)}function Vf(e){if(e.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(e.from==null)throw new Error("Could not get the public key from the originator id");if(e.key!=null)return e.key;if(e.from.publicKey!=null)return e.from.publicKey;throw new Error("Could not get the public key from the originator id")}var ys=class extends ve{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,r){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:c=10,maxInboundStreams:a=1,maxOutboundStreams:f=1}=r;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=La(n),this.enabled=r.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new gr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new Ar({concurrency:c}),this.maxInboundStreams=a,this.maxOutboundStreams=f,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let r={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,r))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(r=>{t.unregister(r)}),await Promise.all(this.multicodecs.map(async r=>{await t.unhandle(r)})),this.log("stopping");for(let r of this.peers.values())r.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:r,connection:n}=t,o=n.remotePeer;if(r.protocol==null){r.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,r.protocol),i=s.attachInboundStream(r);this.processMessages(o,i,s).catch(c=>{this.log(c)})}_onPeerConnected(t,r){if(this.log("connected %p",t),r.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await r.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,r){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,r){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new xn(this.components,{id:t,protocol:r});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let r=this.peers.get(t);if(r!=null){r.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return r}}async processMessages(t,r,n){try{await xr(r,async o=>{for await(let s of o){let i=this.decodeRpc(s),c=[];for(let a of i.messages??[]){if(a.from==null||a.data==null||a.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}c.push({from:a.from,data:a.data,topic:a.topic,sequenceNumber:a.sequenceNumber??void 0,signature:a.signature??void 0,key:a.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(a=>({subscribe:!!a.subscribe,topic:a.topic??""})),messages:c}).catch(a=>{this.log(a)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,r,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:r.id,subscriptions:o.map(({topic:i,subscribe:c})=>({topic:`${i??""}`,subscribe:!!c}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let c=await Ta(i);await this.processMessage(t,c)}catch(c){this.log.error(c)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,r){let n=r.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new wr,this.topics.set(n,o)),r.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,r){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,r)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(r.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:r})),await this.publishMessage(t,r)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new Q("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new Q("Need key when signature policy is StrictSign but it was missing");return Ia(t.key,t.sequenceNumber);case"StrictNoSign":return _a(t.data);default:throw new Q("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,r){let{messages:n,subscriptions:o,subscribe:s}=r;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(_r)})}sendRpc(t,r){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(r))}async validate(t,r){switch(this.globalSignaturePolicy){case"StrictNoSign":if(r.type!=="unsigned")throw new Q('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new Q("StrictNoSigning: signature should not be present");if(r.key!=null)throw new Q("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new Q("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new Q("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new Q("StrictSigning: Signing required and no sequenceNumber was present");if(!await Da(r,this.encodeMessage.bind(this)))throw new Q("StrictSigning: Invalid message signature");break;default:throw new Q("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(r.topic);if(o!=null){let s=await o(t,r);if(s===Ge.Reject||s===Ge.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Pa(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new Q("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Pr("not started yet");if(t==null)throw new Z("Topic is required");let r=this.topics.get(t.toString());return r==null?[]:Array.from(r.values())}async publish(t,r){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:r??new Uint8Array(0),sequenceNumber:Ba()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let r of this.peers.keys())this.send(r,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let r=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,r),r){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};return qa(Ff);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: